Visual Studio Code - 在搜索结果中包含上下文 [英] Visual Studio Code - Include context in search results

查看:30
本文介绍了Visual Studio Code - 在搜索结果中包含上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

filea.rb定义调试(str)文件b.js功能调试(str){

我想看看代码的用途,比如说,每个匹配项上下 3 行.

filea.rbdef somefuncaputs "some func a"结尾定义调试(str)把 str.inspect结尾定义一些函数

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

解决方案

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

<块引用>

预览:搜索编辑器

在这个里程碑中,我们已经开始展示结果在编辑器中搜索.这提供了更多的空间来查看搜索结果并允许用户维护多个搜索集合结果同时发生.在此版本中,您可以在搜索编辑器中:

  • 使用 Go to Definition-family 命令导航到结果,包括 Peek Definition 和 Open Definition to Side.

  • 重新运行搜索以更新结果列表

  • 查看围绕结果的上下文行

  • 将结果保存到磁盘以备后用,甚至在 SCM 中进行跟踪

我们将继续添加功能并提高可用性即将发布的版本.

注意:您可以通过启用设置来预览此功能search.enableSearchEditorPreview强文本.


v1.42 添加了更多功能,请参阅


顺便说一句,您可以直接打开搜索编辑器,而无需先在面板中使用命令 New Search Editor (search.action.openNewEditor) 进行搜索未绑定(并在 v1.48 中重命名).该命令将始终打开一个新的搜索编辑器.

如果您希望重新使用搜索编辑器(而不是打开一个新的),一个命令正在添加到 v1.48:>

Open Search Editor : search.action.openEditor//默认也未绑定


v1.43 发行说明

<块引用>

您可以使用搜索编辑器打开一个新的搜索编辑器:打开新搜索编辑器命令,或使用打开新的搜索编辑器"按钮在搜索视图的顶部.或者,您可以复制您的来自搜索视图的现有结果搜索到搜索编辑器使用在编辑器中打开"链接添加到结果树的顶部,或搜索编辑器:在编辑器中打开 Reuslts 命令.

注意您可以试用实验性搜索编辑器:应用更改将您在搜索编辑器中所做的编辑同步回的扩展源文件:

------------------------------- 见下面的

显示上下文行在搜索编辑器的使用之间似乎不是持久的.但是 Alt+L 充当 toggle 来显示/隐藏上下文.为上下文行数选择的值是持久的.

但是,在 v1.44 和 Insiders' Build 中有两个新命令,用于增加/减少每个搜索结果周围的上下文行数:

<代码>{键":alt+-",命令":减少搜索编辑器上下文线",何时":inSearchEditor"},{键":alt+=",命令":增加搜索编辑器上下文线",何时":inSearchEditor"}

默认情况下它们是未绑定的 - 这些只是示例键绑定.上下文行输入框不需要可见就可以工作.所以 Alt+L 启用上下文行或这些新命令来更改数字.


在 v1.46 中,有一个新设置可以使显示的上下文行数量保持不变:

 "search.searchEditor.defaultNumberOfContextLines": 4,//现在默认为 1

search.searchEditor.reusePriorSearchConfiguration - 创建新的搜索编辑器时重用上一个活动搜索编辑器的配置

(defaultNumberOfContextLines 似乎优先于 reusePriorSearchConfiguration)

参见 v1.46 版本注意:搜索编辑器改进

Is there a way to show context for search results in Visual Studio Code?

By default, if I search "debug" for example I might get 2 lines of code returned.

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

I want to see what the code is for, say, 3 lines above and below each match.

filea.rb
  def somefunca
    puts "some func a"
  end

  def debug(str)
    puts str.inspect
  end

  def somefuncb

Is it possible to add context like this to the search results?

解决方案

v1.41 is adding a preview of a feature which will display search results in an editor thus allowing for some context lines around the actual search result. See search.enableSearchEditorPreview

Preview: Search Editor

In this milestone, we've started work on showing the results of a search in an editor. This provides much more space to view search results and allows users to maintain multiple collections of search results 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 in the coming releases.

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


v1.42 is adding a bit more functionality, see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#search-editor. Like selecting the context width around the search result and running another search right in the search editor itself.


By the way, you can directly open a search editor without first doing a search in the panel with the command New Search Editor (search.action.openNewEditor) currently unbound (and renamed in v1.48). That command will always open a new Search Editor.

If instead, you wish to re-use a Search Editor (rather than opening a new one), a command is being added to v1.48:

Open Search Editor : search.action.openEditor // also unbound by default


v1.43 release notes https://code.visualstudio.com/updates/v1_43#_search-editors

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

You can open a new search editor with the Search Editor: Open New Search Editor command, or using the "Open New Search Editor" button at the top of the search viewlet. Alternatively, you can copy your existing results from a search viewlet search over to a search editor with 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 Changes extension to synchronize edits you make in a search editor back to source files:

------------------------------- see edit below:

Showing the context lines does not appear to be persistent between uses of the search editor. But Alt+L acts as a toggle to show/hide the context. The value chosen for the number of context lines is persistent.

However, in v1.44 and the Insiders' Build are two new commands fro increasing/decreasing the number of context lines surrounding each search result:

{
  "key": "alt+-",
  "command": "decreaseSearchEditorContextLines",
  "when": "inSearchEditor"
},
{
  "key": "alt+=",
  "command": "increaseSearchEditorContextLines",
  "when": "inSearchEditor"
}

They are unbound by default - these are just sample keybindings. The context lines input box does not need to be visible for these to work. So Alt+L to enable context lines or these new commands to change the number.


In v1.46 there is a new setting to make the amount of context lines shown persistent:

 "search.searchEditor.defaultNumberOfContextLines": 4,  // default is now 1

and

search.searchEditor.reusePriorSearchConfiguration - Reuse the last active search editor's configuration when creating a new search editor

(defaultNumberOfContextLines seems to take precedence over reusePriorSearchConfiguration)

See v1.46 release notes: Search Editor improvements

这篇关于Visual Studio Code - 在搜索结果中包含上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆