How to disable or enable GitHub Copilot suggestions for certain files or directories?

Content verified by Anycode AI
August 26, 2024
Learn how to easily enable or disable GitHub Copilot suggestions for specific files or directories, ensuring personalized code assistance based on your project needs.

How to Disable or Enable GitHub Copilot Suggestions for Certain Files or Directories

 

Step 1: Open the Settings

Fire up Visual Studio Code (VS Code) and head to the settings by clicking on the gear icon in the lower left corner. Then, select "Settings."

 

Step 2: Access JSON Settings

In the top right corner of the settings tab, you'll spot an icon that looks like a page, labeled "Open Settings (JSON)." Click on that to open the settings in JSON format.

 

Step 3: Modify the Configuration

Add or tweak the following lines based on what you need.

To turn off GitHub Copilot for certain files or directories, use:

"copilot.advanced.ignore": [
  "**/directory/**",
  "**/*.fileExtension",
  "**/specificFileName.*"
]

 

To enable suggestions specifically for certain files or directories when they're disabled globally (by default or another setting), use:

"copilot.advanced.enable": [
  "**/specificEnabledDirectory/**",
  "**/*.specificEnabledExtension",
  "**/specificEnabledFileName.*"
]

Swap out the placeholders like directory, fileExtension, specificFileName with the actual relative paths or filenames you want to target.

 

Step 4: Save the Settings

After making the necessary changes in the JSON configuration, save the file. Your new settings will kick in immediately. GitHub Copilot will now enable or disable suggestions according to the specified patterns.

 

Step 5: Verify the Configuration

Open the files or directories you've specified in your settings. You should see that GitHub Copilot's suggestions are either enabled or disabled as per your configuration.

 

Step 6: Restart VS Code (if needed)

If the changes don't take effect right away, try restarting Visual Studio Code. This will make sure all new settings are properly loaded.

 

Optional: Use Workspace-Specific Settings

If you want these settings to apply only to a particular workspace, you can add the same configuration in the workspace settings.json file. This is usually found under .vscode/settings.json in the root of your project directory.

 

Step 7: Enjoy Customized Copilot Suggestions

With these settings in place, you'll now have more control over where GitHub Copilot provides suggestions, making your coding experience more streamlined and efficient. Happy coding!

Improve your CAST Scores by 20% with Anycode Security AI

Have any questions?
Alex (a person who's writing this 😄) and Anubis are happy to connect for a 10-minute Zoom call to demonstrate Anycode Security in action. (We're also developing an IDE Extension that works with GitHub Co-Pilot, and extremely excited to show you the Beta)
Get Beta Access
Anubis Watal
CTO at Anycode
Alex Hudym
CEO at Anycode