microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.34k stars 28.9k forks source link

"Go to Symbol in Workspace..." - searching for symbols using more than one word/substring #109548

Open hi2u opened 3 years ago

hi2u commented 3 years ago

Searching for symbols with multiple keywords/substrings via the feature: "Go to Symbol in Workspace..."

Main Request

When using "Go to Symbol in Workspace..." (ctrl-T by default) to find symbols anywhere in the current workspace, is there a way to search for symbols that contains two separate words/substrings?

e.g. Let's say I have a function called oneTwoThree() somewhere in my project, but I can't remember the exact name of it... I should be able to find it with any 2 word search query such as:

...and any other two (or more) substrings that are contained in the name. Yet none of these work, my oneTwoThree() function is never shown in the results (yet a lot of other irrelevant stuff is due to full filepath names that aren't even in the symbol name).

Is there any way to use this search feature with two (or more words) when they might not be joined or in a specific order? If not could this please be improved so that it works in the same way as "Go to File..." does, which does allow you to search using two+ substrings (is there any reason why these work so differently?)

I found a setting called: search.quickOpen.includeSymbols - which will also include symbols in the "Go to File..." results, yet it has the exact same issue - it seems to use completely different filtering methods for filenames vs symbols.

I'm finding that since switching to vscode, I've written a lot of duplicate functions that do the same thing due to not being able to find functions by name using more than one word/substring.

Side Question 1:

While looking into this, I came across setting: typescript.workspaceSymbols.scope which has two options:

...but I can't figure out what the definition of "project" means here. I've tried changing the setting and don't see any different behavior. It doesn't seem mean "workspace", nor exclude node_modules/* from the results. So what does it mean by "project"? This doesn't seem to be a regular term used in vscode.

Side Question 2:

Is there any way to exclude node_modules/* code from "Go to Symbol in Workspace..." results? ...but while still having vscode be aware of it in others contexts like typing and still being able to ctrl-click to navigate into it? It seems most of my results are stuff from node_modules/* - and there's no prioritization that displays my own code above all the node_modules/* results.

vscodebot[bot] commented 3 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

KamasamaK commented 3 years ago

You should make it more explicit that this request is for TypeScript/JavaScript to support this. As best I can tell, the WorkspaceSymbolProvider API would not prevent these from being implemented. Your title and main request make it seem like the issue is with "Go to Symbol in Workspace..." generally.

hi2u commented 3 years ago

@KamasamaK

Your title and main request make it seem like the issue is with "Go to Symbol in Workspace..." generally.

Yes, that's exactly what it is.

I guess maybe the side questions threw you. The side questions were just that... side questions. :)

And the 2nd side question really applies to any language that has package folders, e.g. /vendor/ in PHP etc, or actually any folder name at all that you might want to exclude.

The request here (everything before the side questions) is not specific to any language(s), it applies to all of them. I've tested in: TypeScript, PHP, Rust, C# & bash shell scripts - it works the same way in all.

KamasamaK commented 3 years ago

@hi2u I see the issue is with VS Code's filtering (highlighting and scoring), not the list of symbol results which was my initial understanding.

Regarding your 2nd side question, it may apply to other languages as well but it only makes sense to create an issue here for things that are bundled with VS Code. JS/TS is the only language you mentioned that implements a WorkspaceSymbolProvider in a bundled extension. That said, you can see #46718 for potential VS Code solutions. I still think it's ideal if the provider excludes the results instead of relying on VS Code to filter them out.

nguyencobap commented 3 years ago

Totally agree, please support this feature.

ssigwart commented 2 years ago

I implemented a fix for this in #151859. It looks like the code was looking for the first term in the symbol, then the rest of it in the file path. My fix retains that, but also allows both matches in the symbol itself.

Thk54 commented 5 months ago

I believe I too am running into this issue but from the extension development side. I am making the extension for a language that regularly names symbols with foo_bar construction. However, if I type #foo bar, provideWorkspaceSymbols will only receive "foo" as the query, which would be tolerable (if less than ideal) if the "bar" of #foo bar didn't cause foo_bar to get excluded from the list displayed on the VS Code side. #foo_bar and #foobar work fine, but with how the language works, searching #foo bar will tend to feel much more intuitive than #foo_bar or #foobar

ssigwart commented 5 months ago

I just rebased PR #151859. It's showing this now: image

I'm not entirely sure what that means. Maybe it means that once a certain number of non-Microsoft employees approve the PR, someone from Microsoft will look at it.

gjsjohnmurray commented 5 months ago

@ssigwart I think it means that it hasn't yet received the number of approvals (2) required from team members in order for a community-contributed PR to be mergeable.

ssigwart commented 5 months ago

Ah, thanks, @gjsjohnmurray, I've tried researching it before and never found anything. That makes more sense than what I was thinking.