visual-studio-code - 将 VSCode 中的 "Go to Symbol in Workspace"范围限定为整个工作区

标签 visual-studio-code vscode-settings

我在 VSCode 中的一个 TypeScript 项目中工作,该项目包含多个模块。 “转到工作区中的符号”(CTRL+T) 命令似乎将其自身限定为工作区的本地子集,尽管它的名称如此(这意味着它的搜索应该是全局的)。

假设我在模块 A 中定义了 Foo(),它公开了一个被模块 B 使用的 foo.d.ts 文件,我有这个目录结构

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

我看到以下行为:

  1. 如果我正在编辑 A 中的文件并搜索 #Foo,它将带我到 Foo() 的实际定义。好。
  2. 但如果我在 B 中编辑一个文件并搜索 #Foo,它只会带我到 A 导出的 foo.d.ts - 我有手动导航到 A 以找到 Foo() 的实际定义。

我真的希望 #Foo 的意思是“显示我工作区中任何位置的符号 Foo 的所有实例。”有没有办法强制这种行为?

最佳答案

预览功能:vscode v1.45 应该改进跨 javascript 和 typescript 项目的符号搜索,而无需打开所有文件。参见 https://github.com/microsoft/vscode/issues/11026https://github.com/microsoft/vscode/issues/11026 (js/ts 工作区符号搜索仅在加载了 js/ts 文件时有效)。

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

  • 来自第一个链接。

#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

  • 来自第二个链接。

另请参阅 v1.45 发行说明: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".


要查看您拥有的 typescript 版本以及如何安装更新版本,请参阅 https://stackoverflow.com/a/39676463/836330 .和 https://stackoverflow.com/a/47087772/836330很好。


v1.46 发行说明: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"

关于visual-studio-code - 将 VSCode 中的 "Go to Symbol in Workspace"范围限定为整个工作区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47931087/

相关文章:

python - 如何在 Visual Studio Code 中跨 python 文件访问符号

python - vs 代码未启动,启动器配置问题?

css - Emmet 停止在 VS Code 中处理 CSS 文件

visual-studio-code - "Find All References"跨文件用于 VSCode 中的方法/函数是不可能的

gcc - 如何在 .cpp 文件的 VSCode 编辑器中显示警告?

c++ - 什么是正确的 macOS vscode intellisense C++ 包含标准库的路径?

docker - 一台服务器上的远程容器正常工作,另一台服务器上的远程容器不工作

linux - 命令面板中缺少 "Shell Command: Install"命令 - VS 代码 - ubuntu

visual-studio-code - 如何从 VSCode 中删除侧边栏搜索?

visual-studio-code - 仅在安装C#扩展时VSCode无法检测到安装