VS Code finds problems in GitHub Copilot Chat code blocks. Why?

678 Views Asked by At

When using GitHub Copilot Chat within Visual Studio Code, I've encountered an issue where TypeScript attempts to type check "temporary files" generated by Copilot. These files, identifiable by their hash-based filenames (e.g., c4507d29-b816-4a1c-9f29-c06addfc1204), are not part of my repository. Yet, TypeScript checks produce a plethora of errors, disrupting my workflow. The error messages suggest TypeScript treats these temporary outputs as part of my project, even though they're out of context and irrelevant to my actual codebase.

enter image description here

My questions are twofold: am I overlooking a straightforward setting or configuration related to GitHub Copilot and TypeScript, or has anyone else encountered this issue, and if so, how was it resolved?

I have tried excluding these files in my tsconfig.json, however I feel like this should not even be happening in the first place. I would expect TypeScript to ignore any generated code unless it is in one of the actual files of the project I am currently working on.

2

There are 2 best solutions below

8
starball On

This was a bug. It's supposed to be fixed in the latest VS Code Insiders. The fix should be in 1.88.0 when that releases (you can try that in VS Code Insiders). See issue ticket Problems in chat codeblocks show as workspace problems #206644.

In the meantime, you can edit your search.exclude setting (if that doesn't work, try files.exclude) to exclude files matching the following pattern (based on the pattern given by TonyH in their answer post, but I think this will be more accurate): [a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]-[a-z0-9][a-z0-9][a-z0-9][a-z0-9]-[a-z0-9][a-z0-9][a-z0-9][a-z0-9]-[a-z0-9][a-z0-9][a-z0-9][a-z0-9]-[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9] (yes, it's verbose. I don't know if it works since I don't use GitHub Copilot, but if the idea works, then it's accurate and is less prone to exclude other things you might care about).

There's a related bug with chat stuff being included in references: Functions in Cached Chat files are being discovered as a reference in Visual Studio Code #1055.

1
TonyH On

My fix for this is simple:

Most checkers (ShellCheck was my issue) have a way to exclude files.

The Copilot temporary or virtual files all seem to have hex names like e481a39b-6037-4f11-8dd4-9d813bf1de08

Excluding this glob: [a-f0-9]* will unmatch, and all the errors will be gone!