How to use GitHub Copilot for multiple files?
Asked Answered
E

5

14

I am looking to explore GitHub Copilot. I don't have in-depth coding experience and I graduated just a few months ago. I was planning to build a small website to explore what GitHub copilot has to offer.

When I added comments for the copilot to generate code, it wasn't generating the required code. In the html file, I commented that I want to create text with glitch animations and a section containing the header, navigation icon and to play a video on loop. It wasn't able to generate code that I wanted. So, how do I use it for code that requires reference for other files too(.css or .js files). I'm still learning about front end since I've most experience in C, C++ and Core Java.

Examination answered 19/6, 2023 at 19:17 Comment(1)
one can write CSS and JS in HTML (see the <style> and <script> tags).Vina
D
0

you don't need to do anything, GitHub copilot automatically takes context from the css and js files when using html file.

Decalcify answered 10/7, 2023 at 17:2 Comment(0)
I
4

You can use the @workspace command to provide context to Copilot Chat. This will let you ask questions about the entire codebase. You can take a look at Workspace Context to read more about it.

The sources used for this context are:

  • All files in the workspace, except for files that are ignored by a .gitignore file
  • Directory structure with nested folder and file names
  • GitHub's code search index, if the workspace is a GitHub repository and indexed by code search
  • Symbols and definitions in the workspace
  • Currently selected text or visible text in the active editor

For inline suggestions (ghost text) Copilot looks at the current and open files in your editor to analyze the context and create appropriate suggestions. See Getting the most out of Copilot inline suggestions

I would also suggest to take a look at these sections which contain examples of how to use chat participants with slash commands and variables to select context:

Hope this helps you.

Imf answered 28/6, 2024 at 14:36 Comment(0)
L
1

Currently (jan 2024) copilot will reference only one file at a time. IF you want it to take your CSS and JS into consideration, you need to either paste it into the conversation, or include it all in one file.

Lietman answered 7/1, 2024 at 6:35 Comment(3)
? https://mcmap.net/q/438839/-can-github-copilot-look-at-the-context-of-a-project-with-multiple-files/11107541Vina
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Beating
you can use @workspace, but it will hardly do what you expect if the files are too big...Honorific
D
1

GitHub Copilot is designed to automatically observe the necessary context from all called or imported files across any programming language, so this shouldn't be a natural problem.

If you need to manually direct Copilot to consider specific files for its context understanding, you can utilize the syntax @workspace #file:'file name.xxx' #file:'second file.xxx' and continue in the same format for additional files you wish to include. This command tells Copilot to explicitly include these files in its context analysis. It's essential to note that for this functionality to work as expected, you should mention your current workspace and ensure that the files you're referencing are opened in VSCode.

Then no, Copilot has not removed the function to see multiple context files manually.

Damascene answered 6/4, 2024 at 1:0 Comment(0)
D
0

you don't need to do anything, GitHub copilot automatically takes context from the css and js files when using html file.

Decalcify answered 10/7, 2023 at 17:2 Comment(0)
B
0

On Vitual Studio Code: open Copilot chat located in the left panel. Before entering your prompt type @workspace. Copilot will now use the entire project as the context to answer your question.

Boatbill answered 15/5, 2024 at 20:13 Comment(1)
already mentioned in protoncracker's answer.Vina

© 2022 - 2025 — McMap. All rights reserved.