You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
workspaceContains:*.txt starts a search through the workspace #110510
bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code InsiderssearchSearch widget and operation issuesverifiedVerification succeeded
After 84fc970, any local extension with workspaceContains will trigger a search on the remote to activate it. Since the expandPatterns flag is set for workspaceContains searches, this triggers a search like **/devcontainer.json which will be expensive. This will only happen for extensions like Remote-Containers which will be activated locally when in a remote window.
I guess we want either
To do a normal file lookup, but on the remote workspace instead of the local. No idea if this is possible
To do a search, but without the expandPatterns flag
The current effect of this is that workspaceContains:hello.txt will only look for a hello.txt in the root, but workspaceContains:*.txt will search **/*.txt
Alexandru Dima (@alexdima) the code in workspaceContains.ts is called from two places, extHostExtensionService.ts and abstractExtensionService.ts, in what cases are those two used? And is it possible to have the local EH check the fileService on the remote EH while handling this pattern so we can process it without triggering a search?
It makes sense for Remote-Containers to trigger a lookup, e.g., when connected to Remote-WSL we support having a devcontainer.json that can then also be used to reopen the WSL folder in a container.
Yeah it doesn't, but when a search is triggered through this path then wildcards are added. If possible it would be simplest and fastest to do a lookup for the exact path on the remote, which is what workspaceContains normally does. If we can't do that, like if the local EH doesn't have something like a file service that will end up resolving paths on the remote, then I can change the search to run without the wildcards.
This is all rather complex. I will try to write what I know on the topic:
checkActivateWorkspaceContainsExtension is called in the extension host process from extHostExtensionService.ts on extension host startup. This is the most simple case in a way: opening a folder or a workspace and all extensions are checked if they use workspaceContains and if they need to be activated.
checkActivateWorkspaceContainsExtension is also called from the renderer process from abstractExtensionService.ts when an extension is installed or updated. The idea is that if you install an extension that uses workspaceContains, you'd want it to activate if the workspace contains whatever the extension looks for.
84fc970 is IMHO perfectly valid. In the remote case, the local extension host cannot access directly the remote filesystem, so it will forcefully issue a search (which AFAIK goes to the renderer process, and then goes to the remote extension host).
roblourens What I don't understand is what do you mean with the following:
The current effect of this is that workspaceContains:hello.txt will only look for a hello.txt in the root, but workspaceContains:.txt will search **/.txt
but when a search is triggered through this path then wildcards are added
Who is prepending the extra **/ to the search patterns. Is this something recent or has this always been the case? Is it possible to run the search without an extra **/ prepended to the patterns?
To further clarify, a workspaceContains:*.txt means that the extension wants to be activated if there is at least one .txt file in the root of the folder. A workspaceContains:**/*.txt means that the extension wants to be activated if there is at least one .txt file anywhere in the workspace.
That makes sense, I didn't know that extensions are activated in the workspace when they are installed, thanks.
In the remote case, the local extension host cannot access directly the remote filesystem, so it will forcefully issue a search (which AFAIK goes to the renderer process, and then goes to the remote extension host).
That's right, I think it would be less load during startup to do a stat through some file service that makes the same trip rather than spawning rg, but if we don't have something like that already, it's fine. This particular situation is not really common.
Bad news is, I realized that what I explained does not make sense, I looked into it and see that it seems that I changed it to handle workspaceContains:*.txt as **/*.txt last year, while fixing a different issue, I set expandPatterns: true just so that the pattern would be split on commas, but this also adds the **.
It's possible that some extension now depends on this now but it's bad enough that I should fix it. I can check popular extensions, reach out to them, whatever, but yeah obviously *.txt should not search the whole workspace.
There are many extensions using the second pattern, but I'm sure they would notice if it wasn't working in a local window, so I'm only concerned about the first pattern.
I think a lot of usages of workspaceContains:**/ are questionable in general. Will mention the perf impact and 5s limit in the release notes while we are on the topic.
Here's the issue: This event is supposed to start a search in the user's workspace with the given glob pattern. A pattern like *.txt should activate the extension whenever the root of the workspace has a file matching *.txt, but it should not search the entire workspace. A pattern like **/*.txt should recursively search the entire workspace. We discovered that VS Code is incorrectly applying the ** pattern to every workspaceContains pattern that includes a *.
If your extension depended on this behavior, you can easily get the old behavior back by prepending **/ to your workspaceContains pattern. However, you should think carefully about whether this is even necessary for your extension. It's usually sufficient to activate your extension only once the user actually opens a file of the type you are interested in (see the onLanguage activation event: https://code.visualstudio.com/api/references/activation-events). Using workspaceContains:**/... will start a search across the user's full workspace which may use a lot of CPU. And, if this search takes longer than 5s, the search will be canceled and your extension will be activated anyway. So please think carefully before using this pattern.
bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code InsiderssearchSearch widget and operation issuesverifiedVerification succeeded
Activity
roblourens commentedon Nov 12, 2020
Alexandru Dima (@alexdima) the code in workspaceContains.ts is called from two places, extHostExtensionService.ts and abstractExtensionService.ts, in what cases are those two used? And is it possible to have the local EH check the fileService on the remote EH while handling this pattern so we can process it without triggering a search?
chrmarti commentedon Nov 13, 2020
Not sure I fully understand, Remote-Containers doesn't use wildcards:
It makes sense for Remote-Containers to trigger a lookup, e.g., when connected to Remote-WSL we support having a devcontainer.json that can then also be used to reopen the WSL folder in a container.
roblourens commentedon Nov 13, 2020
Yeah it doesn't, but when a search is triggered through this path then wildcards are added. If possible it would be simplest and fastest to do a lookup for the exact path on the remote, which is what workspaceContains normally does. If we can't do that, like if the local EH doesn't have something like a file service that will end up resolving paths on the remote, then I can change the search to run without the wildcards.
alexdima commentedon Nov 18, 2020
This is all rather complex. I will try to write what I know on the topic:
checkActivateWorkspaceContainsExtensionis called in the extension host process fromextHostExtensionService.tson extension host startup. This is the most simple case in a way: opening a folder or a workspace and all extensions are checked if they useworkspaceContainsand if they need to be activated.checkActivateWorkspaceContainsExtensionis also called from the renderer process fromabstractExtensionService.tswhen an extension is installed or updated. The idea is that if you install an extension that usesworkspaceContains, you'd want it to activate if the workspace contains whatever the extension looks for.84fc970 is IMHO perfectly valid. In the remote case, the local extension host cannot access directly the remote filesystem, so it will forcefully issue a search (which AFAIK goes to the renderer process, and then goes to the remote extension host).
roblourens What I don't understand is what do you mean with the following:
Who is prepending the extra
**/to the search patterns. Is this something recent or has this always been the case? Is it possible to run the search without an extra**/prepended to the patterns?To further clarify, a
workspaceContains:*.txtmeans that the extension wants to be activated if there is at least one.txtfile in the root of the folder. AworkspaceContains:**/*.txtmeans that the extension wants to be activated if there is at least one.txtfile anywhere in the workspace.roblourens commentedon Nov 19, 2020
That makes sense, I didn't know that extensions are activated in the workspace when they are installed, thanks.
That's right, I think it would be less load during startup to do a
statthrough some file service that makes the same trip rather than spawning rg, but if we don't have something like that already, it's fine. This particular situation is not really common.Bad news is, I realized that what I explained does not make sense, I looked into it and see that it seems that I changed it to handle
workspaceContains:*.txtas**/*.txtlast year, while fixing a different issue, I setexpandPatterns: truejust so that the pattern would be split on commas, but this also adds the**.#68969
then #69862
It's possible that some extension now depends on this now but it's bad enough that I should fix it. I can check popular extensions, reach out to them, whatever, but yeah obviously
*.txtshould not search the whole workspace.[-]Unnecessary searches triggered in remote[/-][+]workspaceContains:*.txt starts a search through the workspace[/+]roblourens commentedon Dec 14, 2020
Local window:
*.txtincorrectly handled as**/*.txtUI extension in remote window:
anythingincorrectly handled as**/anythingThere are many extensions using the second pattern, but I'm sure they would notice if it wasn't working in a local window, so I'm only concerned about the first pattern.
In the top 1000 extensions, only 3 are affected
**/patterns anyway https://github.com/OmniSharp/omnisharp-vscode/blame/master/package.jsontds-vscodebut their usage has not changed in years https://github.com/totvs/tds-vscode/blame/master/package.jsonIkuyadeu.r, will file an issue https://github.com/Ikuyadeu/vscode-R/blob/master/package.jsonIn the few thousand beyond that, there are a few more that I have to look into. I've prepared the change, will push it soon.
Two use
*/and probably intended**/scalameta.metalshttps://github.com/scalameta/metals-vscode/blob/master/package.jsonI think a lot of usages of
workspaceContains:**/are questionable in general. Will mention the perf impact and 5s limit in the release notes while we are on the topic.roblourens commentedon Jan 30, 2021
A summary here to link from the release notes:
Here's the issue: This event is supposed to start a search in the user's workspace with the given glob pattern. A pattern like
*.txtshould activate the extension whenever the root of the workspace has a file matching*.txt, but it should not search the entire workspace. A pattern like**/*.txtshould recursively search the entire workspace. We discovered that VS Code is incorrectly applying the**pattern to every workspaceContains pattern that includes a*.If your extension depended on this behavior, you can easily get the old behavior back by prepending
**/to your workspaceContains pattern. However, you should think carefully about whether this is even necessary for your extension. It's usually sufficient to activate your extension only once the user actually opens a file of the type you are interested in (see theonLanguageactivation event: https://code.visualstudio.com/api/references/activation-events). UsingworkspaceContains:**/...will start a search across the user's full workspace which may use a lot of CPU. And, if this search takes longer than 5s, the search will be canceled and your extension will be activated anyway. So please think carefully before using this pattern.