Peter Baer
Peter Baer

Reputation: 1292

Scoping "Go to Symbol in Workspace" in VSCode to the entire workspace

I'm working in a TypeScript project in VSCode that contains multiple modules. The "Go to Symbol in Workspace" (CTRL+T) command seems to scope itself to a local subset of the workspace, despite its name (which implies its search should be global).

Let's say I have Foo() defined in module A, which exposes a foo.d.ts file consumed by module B, and I have this directory structure

 root
 |
 +-- A (folder)
 |
 +-- B (folder)

I see the following behavior:

  1. If I am editing a file in A and search for #Foo, it will take me to the actual definition of Foo(). Good.
  2. But if I am editing a file in B and search for #Foo, it will only take me to the foo.d.ts exported by A - I have to manually navigate into A to find the actual definition of Foo().

I really want #Foo to mean "show me all instances of the symbol Foo anywhere in my workspace." Is there a way to force this behavior?

Upvotes: 3

Views: 4522

Answers (1)

Mark
Mark

Reputation: 182551

Preview feature: vscode v1.45 should improve on symbol searching across javascript and typescript projects without having all the files open. See https://github.com/microsoft/vscode/issues/11026 and https://github.com/microsoft/vscode/issues/11026 (js/ts workspace symbol search only works if you have loaded a js/ts file).

Added with a new setting: typescript.workspaceSymbols.scope. Valid values are:

allOpenProjects — (default) search all opened projects for symbols. Requires TS 3.9+

currentProject — Only search the current project

  • above from the first link.

#11026 Improved this. You no longer need to have a JS/TS file open for workspace symbol search to work and we can now search across all JS/TS projects you know about.

If you are using TS 3.9, all projects should be searched by default

On older TS versions, only the current project should be searched. If using TS 3.9, you can switch to only search the current project by setting: "typescript.workspaceSymbols.scope": "currentProject"

However we still require you to have opened a JS/TS file

  • above from the second link.

Also see the v1.45 release notes : https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#workspace-symbol-search-in-all-open-typescriptjavascript-projects

When using TypeScript 3.9+, VS Code's workspace symbol search now includes results from all opened JavaScript and TypeScript projects by default. We previously only searched the project of the currently active file.

This is controlled by the new "typescript.workspaceSymbols.scope" setting. To revert to the old behavior, just set: "typescript.workspaceSymbols.scope": "currentProject".


To see what version of typescript you have and how to install a newer version, see https://stackoverflow.com/a/39676463/836330. And https://stackoverflow.com/a/47087772/836330 is good.


v1.46 release notes: searching for symbols across projects in a workspace

JS/TS Go to Symbol in workspace includes all opened projects

By default, workspace symbol search for JavaScript and TypeScript now search all opened jsconfig and tsconfig projects. It previously only included search results from the project the focused file belonged to.

This behavior is controlled by the typescript.workspaceSymbols.scope setting and requires TS 3.9+. To revert the to previous behavior and only search the current project, just set "typescript.workspaceSymbols.scope": "currentProject"

Upvotes: 2

Related Questions