mattickx / copilotignore-vscode

Disable copilot extension when certain files are open listed in a .copilotignore file
MIT License
14 stars 4 forks source link

Pattern not matching #1

Closed asheroto closed 9 months ago

asheroto commented 9 months ago

Hey there,

Steps to reproduce:

1.) Create a new directory 2.) Create home.html 3.) Create .copilotignore 4.) Type home.html inside .copilotignore and save 5.) Save workspace as Test.code-workspace 6.) Close VS Code 7.) Opened Test.code-workspace workspace 8.) Copilot is not disabled

Also tried **/home.html.

Maybe I'm missing something? I figured it requires a workspace and not just a directory opened, correct?

https://github.com/mattickx/copilotignore-vscode/assets/49938263/0fd35406-fbb2-4493-9847-bc1e114d350e

mattickx commented 9 months ago

Could you open the output window for 'Copilot Ignore' and send me the logs? Could you check if you are on version 0.1.1 of the extension?

image

asheroto commented 9 months ago

Thanks for debugging!

Looks like it's not recognizing any patterns for some reason.

image

2024-01-24 04:10:48.407 [info] CopilotIgnore: Skipped due to already same boolean value (Old: true - New: true)
2024-01-24 04:10:50.139 [info] CopilotIgnore: Trying to set new state: (true) for file: undefined
2024-01-24 04:10:50.139 [info] CopilotIgnore: Skipped due to already same boolean value (Old: true - New: true)
2024-01-24 04:10:50.147 [info] CopilotIgnore: Trying to set new state: (true) for file: undefined
2024-01-24 04:10:50.147 [info] CopilotIgnore: Skipped due to already same boolean value (Old: true - New: true)
2024-01-24 04:10:52.614 [info] Collected patterns: 0
2024-01-24 04:10:57.409 [info] Collected patterns: 0
2024-01-24 04:10:57.569 [info] Collected patterns: 0

https://github.com/mattickx/copilotignore-vscode/assets/49938263/2fc6617e-63b2-4cda-b768-02e90a5b2eaa

asheroto commented 9 months ago

In the previous post I had opened the Test directory, saved the workspace, then reopened the workspace.

I also tried opening the Test folder itself, same bug.

mattickx commented 9 months ago

@asheroto Could you retry with version 0.1.2 of the extension?

asheroto commented 9 months ago

Using 0.1.2 but unfortunately the same issue. Tried the same two patterns but both said pattern count is 0.

image

image

mattickx commented 9 months ago

Please put .copilotignore in root of the workspace as documented in README That seems to fix it for me.

asheroto commented 9 months ago

I'm pretty sure it is in the root. The way it appears can seem like I have the parent folder opened and am looking into Test, but I actually have the Test folder opened with .copilotignore in the root.

image

I tried opening with File -> Open Folder -> C:\Downloads\Test ...

image

and then tried File -> Save Workspace As -> Test.code-workspace then opened that.

image

That almost makes it look like I've opened C:\Downloads but I haven't, as I have other files and folders in there that do not appear.

Am I missing something?

mattickx commented 9 months ago

@asheroto Could you try:

Install latest version (>= 0.1.4) of the extension Please remove any github.copilot.enable entry in your workspace (file) settings Please remove any github.copilot.enable entry in your ./.vscode/settings.json in your project folder

This extension now overwrites your global github.copilot.enable settings. Meaning you would loose any self configured entries of github.copilot.enable. So you might want to make a backup from this setting if you configured something yourself.

Proof this works for me:

https://github.com/mattickx/copilotignore-vscode/assets/9006731/8cc9016a-93ec-46d3-830f-75b805194a88

You see the setting jumping from true to false, and copilot icon changing aswell.

asheroto commented 9 months ago

Gotcha. I removed them, and I do notice that the extension recreates them automatically when I load home.html. Also FYI I do not have any other copilot settings in the settings.json file. No workspace settings.

Updated, but unfortunately it still does not detect the patterns.

I'm wondering if this is because I'm using Windows and you're using Mac/Linux? Maybe there's some oddity related to VS Code itself and either paths or glob patterns.

Perhaps it would help if the extension wrote additional debug messages in console? In theory this could be enabled/disabled with a setting. Or if you want to send me a debug branch we could even do that.

That way we could see:

I'm wondering if it even sees the .copilotignore file at all. Because even if I delete the file, it shows the same messages with 0 patterns. Also I changed .copilotignore to *.html as in your video.

image

I bet it's something with Windows vs Mac/Linux. VS Code should handle it, but who knows maybe it's a new glitch.

mattickx commented 9 months ago

Thanks for pointing that out. Indeed there was an issue on Windows which I fixed in commit 3e4f9aa

I released v0.1.5 that includes this fix. Please update, restart and retry. Let me know if that fixes it for you as well.

asheroto commented 9 months ago

Eureka! IT WORKS! 😊

Awesome! Thanks so much. Not sure why the Copilot team hasn't added this in as native functionality, but so glad you did!

asheroto commented 9 months ago

I haven't analyzed the code. Does it actually prevent Copilot from loading for that file? Or does the file load and then it's turned off?

mattickx commented 9 months ago

Eureka! IT WORKS! 😊 Awesome! Thanks so much. Not sure why the Copilot team hasn't added this in as native functionality, but so glad you did!

I hope as well as this is just hacked together and not optimal imo, but it works for me. Glad it works out for you too.

I haven't analyzed the code. Does it actually prevent Copilot from loading for that file? Or does the file load and then it's turned off?

I had some logic for skipping invalid files, the way I did was not compatible with a Windows file system.

asheroto commented 9 months ago

not optimal imo

agreed.

I had some logic for skipping invalid files, the way I did was not compatible with a Windows file system.

Is the logic to skip files in Windows now? Just wanted to make sure Copilot doesn't load then turn off.

mattickx commented 9 months ago

Is the logic to skip files in Windows now?

The skipping of files is just to exclude files not in the workspace mostly.

Just wanted to make sure Copilot doesn't load then turn off.

I cannot guarantee that Copilot won't load first; I can only work with the tools available to me. The function trigger checks the open file against all collected patterns, and if it matches, I disable Copilot immediately through a configuration entry.

This is the only viable way I see to implement it without support inside the official Copilot extension. I looked around and found a Vim extension that approaches it in the same way.

Having an active directory/workspace open without any patterns will result in Copilot being (re)enabled.

asheroto commented 9 months ago

Gotcha. Okay cool, looks like this will work great!