Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #8669: .gitignore entries shouldn't be excluded from workspaceContains events #8671

Closed
wants to merge 1 commit into from

Conversation

vnfedotov
Copy link
Contributor

What it does

Fixes #8669: workspaceContains activation event doesn't fire if matched file found in .gitignore, it's expected behavior of ripgrep.

This PR changes arguments for fileSearchService when looking for files matched by workspaceContains pattern, adding useGitIgnore=false, in result ripgrep will run with '-uu' flag and include .gitignore entries in search results.

Impact is limited to workspaceContains activation event behavior.

How to test

  1. Create plugin with following activation events:
"activationEvents": [
        "workspaceContains:**/compile_commands.json"
]
  1. Create following folder structure:
my-parent-repo/
   .gitignore
   modules/
       my-module/   <- workspace root
          src/
          build/
             compile_commands.json
  1. Add following entries to .gitignore:
    **/build/*
  2. Load plugin, point workspace root to: my-parent-repo/modules/my-module/
  3. Plugin should activate

Review checklist

Reminder for reviewers

Signed-off-by: Vladimir Fedotov [email protected]

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vnfedotov thank you for your investigation into the issue and your subsequent pull-request contribution 👍 Please be sure to complete the Eclipse Contributor Agreement (ECA) so we can accept your changes.

@vince-fugnitto vince-fugnitto added the vscode issues related to VSCode compatibility label Oct 27, 2020
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vnfedotov were you able to confirm the behavior in vscode, I do not believe they search in ignored files when determining the activation event for workspaceContains. I verified with a custom extension which displays a message when compile_commands.json is present in the workspace.

During my tests in vscode, I noticed that the compile_commands.json added under node_modules (which is gitignored) does not trigger the activation event, while if it outside gitnignored files it does. This is the behavior I expect since I do not believe gitignored files should trigger extensions eagerly.

@vnfedotov
Copy link
Contributor Author

vnfedotov commented Oct 28, 2020

@vince-fugnitto I did. I've tested with vscode-clangd extension (https://github.com/clangd/vscode-clangd) modified to have following activationEvents:

"activationEvents": [
        "workspaceContains:**/compile_commands.json",
        "onCommand:clangd.activate",
        "onCommand:clangd.install",
        "onCommand:clangd.update"
    ],

In fact, underlying workspace.findFiles() behaves differently in vscode, which initially made me think in has something to do with #6460 -- in vscode it finds gitignored files, in theia it doesn't (because useGitIgnore is true by default).

P.S. It's probably easier to test with vscode-clangd. If you're seeing prompt to install clangd, it means it's activated.

@vince-fugnitto
Copy link
Member

vince-fugnitto commented Oct 28, 2020

@vnfedotov when testing, did you add a compile_commands.json file under a gitignored folder and no where else (ex: under node_modules)? For this case, vscode did not activate the extension and it is the behavior I expect but is broken by these changes.

To test, I created a minimal extension with the following activation event:

"activationEvents": [
    "workspaceContains:**/compile_commands.json"
],

Upon activation it will display an information message to end-users (for test purposes). The two use case are:

Use-Case Observed VS Code Behavior
compile_commands.json exists in a non-gitignored folder (ex: root of workspace) Extension activates
compile_commands.json exists in a gitignored folder (ex: node_modules) Extension does not activate

For test purposes, you can use the sources of the extension itself: https://github.com/vince-fugnitto/workspace-contains-test

  1. add a compile_commands.json at the root of the repo, reload the application, and notice the message.
  2. move the compile_commands.json under node_modules, reload the application and the message does not appear.

@vince-fugnitto
Copy link
Member

@vnfedotov I believe the fix would not be to ignore all gitignored files, but rather parent ones which seem to be your initial bug:

--no-ignore-parent
Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories.

@vnfedotov
Copy link
Contributor Author

@vince-fugnitto These are ripgrep args that I've extracted from vscode:

--files --hidden --case-sensitive -g '!**/.git' -g '!**/.svn' -g '!**/.hg' -g '!**/CVS' -g '!**/.DS_Store' -g '!**/node_modules' -g '!**/bower_components' -g '!**/*.code-search' --no-ignore-parent --follow --no-config --no-ignore-global

You can probably guess why workspaceContains doesn't fire when compile_commands.json is placed in node_modules.
I would suggest following test case, using your extension:

  1. git clone https://github.com/vnfedotov/workspace-contains-test-repo
  2. cd workspace-contains-test-repo && mkdir build && touch build/compile_commands.json
  3. open vscode on workspace-contains-test-repo -> message appears
  4. verify that compile_commands.json is gitignored (greyed out in project explorer)
  5. mv build/compile_commands.json node_modules/
  6. reopen workspace -> message doesn't appear

@vince-fugnitto
Copy link
Member

You can probably guess why workspaceContains doesn't fire when compile_commands.json is placed in node_modules.
I would suggest following test case, using your extension:

@vnfedotov I understand that vscode does not activate the extension when it is under node_modules, what I'm trying to illustrate is how this pull-request breaks that behavior. With your changes, if my compile_commands.json is placed under node_modules (which is gitignored) the extension is incorrectly activated. While it may resolve your initial bug, it introduces a breaking behavior which should instead be fixed alternatively than simply ignoring all gitignored folders.

@vnfedotov
Copy link
Contributor Author

@vince-fugnitto The point I was trying to make is that node_modules is ignored not because it's in .gitignore, but because vscode explicitly excludes it from search results, along with .git/, CVS/ and others.

@vince-fugnitto
Copy link
Member

@vince-fugnitto The point I was trying to make is that node_modules is ignored not because it's in .gitignore, but because vscode explicitly excludes it from search results, along with .git/, CVS/ and others.

@vnfedotov I placed a compile_commands.json under another gitignored folder (ex: vince) for test purposes, the extension is not activated in vscode while it is with this pull-request.

@vnfedotov
Copy link
Contributor Author

@vince-fugnitto I'm not sure what to tell you, because I'm observing exactly opposite behaviour

@vince-fugnitto
Copy link
Member

@vince-fugnitto I'm not sure what to tell you, because I'm observing exactly opposite behaviour

In your example build is not properly gitignored (it is also not decorated as ignored), try:

build

You'll see that the activation event does not occur, while this pull-request does.

@vnfedotov
Copy link
Contributor Author

@vince-fugnitto Ah, I see. It does work if file is gitignored, but doesn't if folder is also gitignored.
I'm not sure what to do with this. File search implementation in theia substantially differs from vscode. We can put bandage on it, adding no-ignore-parent as you suggested, but it won't fix underlying issues.

Tbh, I don't really get the logic behind vscode implementation, it leaves out use cases that are useful. In fact, we need some way to trigger plugin activation, if compilation database (compile_commands.json) exists in the workspace, and its common to put it in .gitignore as a build artifact.

@vince-fugnitto
Copy link
Member

I believe the pull-request can be closed, from the last feedback (#8671 (comment)) the changes will incorrectly activate the extension which differs from behavior compared to vscode. If we continue we should find a way which does not break this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workspaceContains activation event doesn't fire if matched with .gitignore outside of the workspace
2 participants