Workspace Search
Relevant source files
The following files were used as context for generating this wiki page:
- extensions/search-result/package.json
- extensions/markdown-language-features/package.json
- extensions/markdown-language-features/package.nls.json
- extensions/typescript-language-features/package.nls.json
- extensions/npm/package.json
- extensions/github/package.json
- extensions/restructuredtext/syntaxes/rst.tmLanguage.json
Workspace Search in Visual Studio Code is not a single monolithic system but a collection of distributed capabilities provided by various extensions and language features. These features work together to enable users to find files, text, symbols, and references across their entire workspace. The system is designed to be extensible, allowing different language services and tools to contribute their own search logic and commands.
This document outlines the various components and configurations that constitute the workspace search experience, as defined by the extension contribution points and settings. It covers the dedicated search result language, language-specific search commands like finding references, and configuration options that allow users to customize and scope search behavior.
Search Architecture Overview
The overall search functionality is an aggregation of features from multiple extensions. Each extension contributes commands, configurations, and language-aware logic that plugs into the core search experience.
This diagram illustrates how different extensions contribute to the central concept of Workspace Search.
Search Result Language
VS Code defines a specific language for displaying search results, identified as search-result. This language is associated with files having the .code-search extension.
Sources: extensions/search-result/package.json:30-35
| Property | Value | Description |
|---|---|---|
id | search-result | The unique identifier for the language. |
extensions | .code-search | The file extension associated with this language. |
aliases | Search Result | An alternative friendly name. |
grammar | ./syntaxes/searchResult.tmLanguage.json | The path to the TextMate grammar for syntax highlighting. |
Sources: extensions/search-result/package.json:30-44
By default, the editor is configured to hide line numbers for this language to provide a cleaner presentation of search results.
"configurationDefaults": {
"[search-result]": {
"editor.lineNumbers": "off"
}
}
Sources: extensions/search-result/package.json:24-28
Language-Specific Search Capabilities
Different language extensions enhance the workspace search with context-aware commands and features.
Markdown Search
The markdown-language-features extension provides several commands and configurations for searching and navigating within and between Markdown files.
| Command | Description |
|---|---|
markdown.findAllFileReferences | Finds all references to the current file within the workspace. |
markdown.editor.insertLinkFromWorkspace | A command to search for and insert a link to a file in the workspace. |
markdown.suggest.paths.includeWorkspaceHeaderCompletions | Enables suggestions for headers in other Markdown files in the workspace, effectively searching for linkable content. |
Sources: extensions/markdown-language-features/package.json:115-117, 123-125, extensions/markdown-language-features/package.nls.json:30-32
Link validation features also perform background searches to verify the existence of linked files and headers.
markdown.validate.fileLinks.enabled: Validates links to other files by checking if the target file exists.markdown.validate.fragmentLinks.enabled: Validates fragment links to headers within the current file.
Sources: extensions/markdown-language-features/package.json:329-337, extensions/markdown-language-features/package.nls.json:50-52
TypeScript and JavaScript Search
The built-in TypeScript and JavaScript extension provides powerful symbol search capabilities.
- Go to Symbol in Workspace: This feature is controlled by the
typescript.workspaceSymbols.scopesetting, which defines whether the search includes all open projects or only the current one. - Find File References: The
typescript.findAllFileReferencescommand allows finding all references to a file.
Sources: extensions/typescript-language-features/package.nls.json:194-197, 200
reStructuredText Search
The restructuredtext extension contributes syntax highlighting for various search-related directives and roles. This allows the editor to correctly parse and display references, which is a form of workspace-aware navigation.
- Roles:
:ref:is identified as a tag for creating references. - Directives: The syntax recognizes domain-specific directives like
.. cpp:function::or.. py:module::which are used for creating searchable documentation anchors.
"ref": {
"begin": "(:ref:)`",
"end": "`|^\\s*$",
"name": "entity.name.tag",
"beginCaptures": {
"1": {
"name": "keyword.control"
}
},
"patterns": [
{
"match": "<.*?>",
"name": "markup.underline.link"
}
]
}
Sources: extensions/restructuredtext/syntaxes/rst.tmLanguage.json:96-113
Search Configuration
Users can fine-tune workspace search behavior through various settings.
| Setting | Extension | Description |
|---|---|---|
npm.exclude | npm | A glob pattern to exclude directories from package.json script detection, effectively narrowing the search space for NPM tasks. |
markdown.validate.ignoredLinks | markdown-language-features | A list of glob patterns for links that should be ignored during validation, preventing them from being searched. |
markdown.updateLinksOnFileMove.include | markdown-language-features | Glob patterns specifying which files should trigger automatic link updates when a file is moved, which involves searching for references. |
typescript.workspaceSymbols.scope | typescript-language-features | Controls whether "Go to Symbol in Workspace" searches all open projects or only the current one. |
Sources: extensions/npm/package.json:200-207, extensions/markdown-language-features/package.json:347-352, 368-379, extensions/typescript-language-features/package.nls.json:194-197
Conclusion
Workspace Search in VS Code is a powerful, decentralized feature set. Its functionality is primarily derived from contributions by various extensions, most notably language-specific ones like Markdown and TypeScript. By leveraging extension-provided commands, configurations, and a dedicated search-result language, VS Code offers a flexible and context-aware search experience that can be tailored to the needs of any project.