Copilot Chat does not use relevant open files as context #84161
Replies: 3 comments
-
Here are a few things you can try:
Copilot uses the active document and the context of your workspace to generate responses. If you're asking a question about a specific piece of code, including that code in your question can be helpful. It's best to have that file open in your workspace and active in your editor. Providing the relative path to a specific file in your workspace might help GitHub Copilot understand the context of your question better. |
Beta Was this translation helpful? Give feedback.
-
The suggestions provided do work, I actually use them all the time to get copilot chat to be a bit more intuitive. Unfortunately it's not always viable to copy code from multiple interrelated files int a single chat prompt, and using @workspace on a very large repository can in some cases lead worse results. Even when I have the only 2, or 3 files required opened in the editor already; have named the files in the prompt; specified the class names and functions in them to use for context/reference. In this case the scan for workspace can still lead copilot to use different files unrelated to the question. Unfortunately @workspace I believe is supposed to give some priority to open files in the editor, but in practice the scan of the repository can lead it to ignoring the open files entirely. I have however been quite successful when copying blocks of code from the other files and placing it above and/or below the code in the current file being discussed. Then highlighting all the code before asking a question of course has a consistent line X - Y reference. This is quite similar to pasting code blocks in a prompt, which works quite well when there is a single code block to add to the open file, but not quite as good when 2 or 3+ code blocks need to be added to a prompt to be references for the open file, sometimes it seems to not include one, or more, of the blocks of code pasted in the prompt during the reply (even when using `code` or ```code```). This can be
So I'd call it the "very extreme approach" to solving the problem. Unfortunately in very large repositories it's sometimes the only solution I've been able to come up with. While it works almost perfectly to ensure the context is provided, I definitely would not suggest people use this approach unless all other approaches to getting the references correct have failed. What would be nice if there was also an @editor or @openfiles etc. which would be like a focused @workspace that ensures that each (every) file open in the editor would be used as a reference, while also skipping the scan of the entire repository trying determine them. When working with code that inherits from more than one class which are spread over more than 1 additional file this could be a game changer to getting exact references to work. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Bug
Body
Repro:
@workspace
to ask about it instead.@workspace
does not pick up the desired context, even though the class in question is in a file named after it.Seems like a bug and
@workspace
should be picking up this open file. Is there a way I can debug furtherBeta Was this translation helpful? Give feedback.
All reactions