gpt4 book ai didi

visual-studio-code - Visual Studio Code - 在搜索结果中包含上下文

转载 作者:行者123 更新时间:2023-12-04 19:27:33 27 4
gpt4 key购买 nike

有没有办法在 Visual Studio Code 中显示搜索结果的上下文?

默认情况下,例如,如果我搜索“调试”,我可能会返回 2 行代码。

filea.rb
def debug(str)
fileb.js
function debug(str) {

我想看看代码是什么,比如说,每场比赛的上下 3 行。
filea.rb
def somefunca
puts "some func a"
end

def debug(str)
puts str.inspect
end

def somefuncb

是否可以在搜索结果中添加这样的上下文?

最佳答案

v1.41 添加了一项功能的预览,该功能将在编辑器中显示搜索结果,从而允许在实际搜索结果周围添加一些上下文行。见 search.enableSearchEditorPreview

Preview: Search Editor

In this milestone, we've started work on showing the results of asearch in an editor. This provides much more space to view searchresults and allows users to maintain multiple collections of searchresults simultaneously. With this release, in a search editor you can:

  • Navigate to results using Go to Definition-family commands, including Peek Definition and Open Definition to Side.

  • Rerun a search to update the list of results

  • View lines of context surrounding a result

  • Persist results to disk to be referenced later or even tracked in SCM

We will be continuing to add functionality and increase usability inthe coming releases.

Note: You can preview this feature by enabling the settingsearch.enableSearchEditorPreviewstrong text.


preview search in an editor demo

v1.42 正在添加更多功能,请参阅 https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#search-editor .就像选择搜索结果周围的上下文宽度并在搜索编辑器本身中运行另一个搜索一样。
search context demo

顺便说一句,您可以直接打开搜索编辑器,而无需先在面板中使用命令 New Search Editor进行搜索。 ( search.action.openNewEditor ) 当前未绑定(bind)(并在 v1.48 中重命名)。该命令将始终打开一个新的搜索编辑器。
相反,您希望 重复使用搜索编辑器 (而不是打开一个新的),一个命令是 添加到 v1.48 : Open Search Editor : search.action.openEditor//默认情况下也未绑定(bind)

v1.43 发行说明 https://code.visualstudio.com/updates/v1_43#_search-editors

In a search editor, results can be navigated to using "Go toDefinition" actions, such as kb(editor.action.revealDefinition) toopen the source location in the current editor group, orkb(editor.action.revealDefinitionAside) to open the location in an editor tothe side. Additionally, double clicking can optionally open the sourcelocation, configurable with thesearch.searchEditor.doubleClickBehaviour setting.


search editor image

You can open a new search editor with the Search Editor: Open NewSearch Editor command, or using the "Open New Search Editor" button atthe top of the search viewlet. Alternatively, you can copy yourexisting results from a search viewlet search over to a search editorwith the "Open in Editor" link added to the top of the results tree,or the Search Editor: Open Reuslts in Editor command.

Note You can try out the experimental Search Editor: Apply Changesextension to synchronize edits you make in a search editor back tosource files:


search and apply changes
------------------------------------------- 见下面的编辑:
在使用搜索编辑器之间显示上下文行似乎不是持久的。但是 Alt+L 充当 切换 显示/隐藏上下文。为上下文行数选择的值是持久的。
但是,在 v1.44 和 Insiders' Build 中,有两个新命令用于增加/减少围绕每个搜索结果的上下文行数:
{
"key": "alt+-",
"command": "decreaseSearchEditorContextLines",
"when": "inSearchEditor"
},
{
"key": "alt+=",
"command": "increaseSearchEditorContextLines",
"when": "inSearchEditor"
}
默认情况下它们是未绑定(bind)的 - 这些只是示例键绑定(bind)。上下文行输入框不需要可见就可以正常工作。所以 Alt+L 启用上下文行或这些新命令来更改数字。

在 v1.46 中有一个新设置可以使 持续显示的上下文行数 :
 "search.searchEditor.defaultNumberOfContextLines": 4,  // default is now 1
search.searchEditor.reusePriorSearchConfiguration - 创建新的搜索编辑器时重用上次事件的搜索编辑器的配置
( defaultNumberOfContextLines 似乎优先于 reusePriorSearchConfiguration )
v1.46 release notes: Search Editor improvements

关于visual-studio-code - Visual Studio Code - 在搜索结果中包含上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51599104/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com