英文:
vscode: symbol search, but only in my code
问题
如果我使用ctrl-t(符号搜索),我会得到所有的符号。这意味着我的符号和我使用的库的符号都会显示出来。
有没有办法将符号搜索限制在只显示我的代码中的符号(不包括库中的符号)?
我在Go中使用的是vscode。
在上面的截图中,我突出显示了来自我的代码的单行。
如果没有“只显示我的代码”的筛选器,那么如果vscode可以突出显示我的代码,那就太好了。
相关问题:https://github.com/golang/go/issues/37236
英文:
If I use ctrl-t (symbol search), I get all symbols. This means my symbols and symbols of libraries I use.
Is there a way to restrict symbol search to only the symbols which are in my code (excluding symbols from libraries).
I use vscode for Go.
In above screenshot I highlighted the single line which comes from my code.
If a filter for "only my code" is not possible, then it would be nice if my code would get higlighted by vscode.
Related issue: https://github.com/golang/go/issues/37236
答案1
得分: 5
你可以使用vscode-search-everywhere插件。
参考:
扩展设置
searchEverywhere.include: "**/*.{go,js,jsx,ts,tsx}"
含义:包括所有具有上述扩展名的文件
英文:
You can use vscode-search-everywhere
Refer
> Extension Settings
searchEverywhere.include: "**/*.{go,js,jsx,ts,tsx}"
meaning: include all files with the above extentions
答案2
得分: 1
相关问题:https://github.com/golang/go/issues/37236
该问题已经通过CL 490935和提交golang/tools
commit 8e9b185关闭:
- gopls/internal/lsp/source: 添加了“symbolScope”选项
添加了一个新的“symbolScope”选项,用于控制匹配是否仅限于工作区包。尽管旧行为可以通过设置“symbolScope”为“all”来启用,但这是新的默认行为。
实际上,CL 494217将此设置的默认值保持为“all”,并征求用户对默认值的反馈意见。
现在你有:
symbolScope
枚举类型
symbolScope
控制搜索工作区/符号请求的包。默认值为“workspace”,仅搜索工作区包。旧行为“all”会搜索所有加载的包,包括依赖项;这样做会更加耗费资源,并可能返回不需要的结果。
可选值为:
- “all”:匹配任何加载的包中的符号,包括依赖项。
- “workspace”:仅匹配工作区包中的符号。
这可能仍然包括vendoring,可能会引发问题。
注意:这不包括#37237(“x/tools/gopls
: 支持符号的高级查询语法”):
在VS Code允许控制工作区符号结果对话框之前,不会支持高级查询语法。因为现在任何类型的高级查询语法都会导致VS Code过滤掉所有结果,因为它在返回结果后会进行自己的排序和过滤。
你现在可以通过构建gopls@master来测试:
例如:
git clone https://go.googlesource.com/tools
cd tools/gopls && go install
Thomas Gütler,问题的提出者,确认:
现在ctrl+t
只显示我的代码:
存在一个回归问题(#60027:WorkspaceSymbol
返回奇怪的结果和顺序),将在gopls/v0.12.0中修复,感谢findleyr。
Paul Jolly补充道:
这个问题涉及到工作区之外的符号。这个更改对你有帮助吗?
不是很有帮助。因为我想要搜索符号的范围会发生变化。
- 有时我想要搜索等同于所有包空间的范围,
- 有时只在工作区中搜索,
- 有时只在当前文件所属模块的范围内搜索,
- 有时只在当前文件所属包的范围内搜索,
- 有时只在当前文件的范围内搜索。
因此,单一的静态配置选项并没有太大帮助。并不是说它对其他人没有帮助,我只是在与之前讨论过的问题建立联系。
英文:
> Related issue: https://github.com/golang/go/issues/37236
That issue just got closed with CL 490935 and commit golang/tools
commit 8e9b185:
> ## gopls/internal/lsp/source: add the "symbolScope" option
>
> Add a new "symbolScope
" option that controls whether matches are restricted to workspace packages only.
<del>This is the new default behavior</del>, though the old behavior can be enabled by setting "symbolScope": "all"
.
Actually, CL 494217 keeps the default of this
setting at "all
", and solicit feedback for which default our users
prefer.
You now have:
> ## symbolScope
enum
>
> symbolScope
controls which packages are searched for workspace/symbol
> requests.
>
> The default value, "workspace
", searches only workspace
> packages.
> The legacy behavior, "all
", causes all loaded packages to be
> searched, including dependencies; this is more expensive and may
> return unwanted results.
>
> Must be one of:
>
> * "all"
matches symbols in any loaded package, including dependencies.
> * "workspace"
matches symbols in workspace packages only.
This still might include vendoring, which can be an issue.
Note: this does not include #37237 ("x/tools/gopls
: support advanced query syntax for Symbol"):
> not until VS Code allows controlling the workspace symbol result dialog.
>
> As it is now, any sort of advanced query syntax would cause VS Code to filter out all results, because it does its own round of sorting and filtering after we return results.
>
> You can now test this out by building gopls@master:
>
> e.g.:
>
> bash
> git clone https://go.googlesource.com/tools
> cd tools/gopls && go install
>
Thomas Güttler, the OP, confirms:
> ctrl+t show now my code only:
>
>
There is a regression (#60027: WorkspaceSymbol
returns strange results in strange order), which will be fixed with gopls/v0.12.0, thanks to findleyr.
And Paul Jolly adds:
> > this issue is about symbols outside the workspace. Did this change help you?
>
> not really. Because the scope in which I want to search for symbols changes.
>
> - Sometimes I want to search across the equivalent of the all package space,
> - sometimes just in the workspace,
> - sometimes just in the scope of the module to which the current file belongs,
> - sometimes the scope of the package to which the current file belongs,
> - sometimes in the scope of just the current file.
>
> Having a single static config option doesn't much help therefore.
Not to say that it wouldn't help others, I'm just drawing a connection to a previously discussed issue.
答案3
得分: -1
在“要排除的文件”中输入库的路径。
英文:
Enter the path of the libraries, in files to exclude
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论