diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index e94daeed5cc..f3285c58a23 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -842,6 +842,20 @@ "description": "%configuration.tsserver.watchOptions.synchronousWatchDirectory%" } } + }, + "typescript.workspaceSymbols.scope": { + "type": "string", + "enum": [ + "allOpenProjects", + "currentProject" + ], + "enumDescriptions": [ + "%typescript.workspaceSymbols.scope.allOpenProjects%", + "%typescript.workspaceSymbols.scope.currentProject%" + ], + "default": "allOpenProjects", + "markdownDescription": "%typescript.workspaceSymbols.scope%", + "scope": "window" } } }, diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index 70bbf57df25..6f4241434ef 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -102,6 +102,9 @@ "configuration.tsserver.watchOptions.synchronousWatchDirectory": "Disable deferred watching on directories. Deferred watching is useful when lots of file changes might occur at once (e.g. a change in node_modules from running npm install), but you might want to disable it with this flag for some less-common setups.", "typescript.preferences.renameShorthandProperties.deprecationMessage": "The setting 'typescript.preferences.renameShorthandProperties' has been deprecated in favor of 'typescript.preferences.useAliasesForRenames'", "typescript.preferences.useAliasesForRenames": "Enable/disable introducing aliases for object shorthand properties during renames. Requires using TypeScript 3.4 or newer in the workspace.", + "typescript.workspaceSymbols.scope": "Controls which files are searched by [go to symbol in workspace](https://code.visualstudio.com/docs/editor/editingevolved#_open-symbol-by-name).", + "typescript.workspaceSymbols.scope.allOpenProjects": "Search all open JavaScript or TypeScript projects for symbols. Requires using TypeScript 3.9 or newer in the workspace.", + "typescript.workspaceSymbols.scope.currentProject": "Only search for symbols in the current JavaScript or TypeScript project.", "codeActions.refactor.extract.constant.title": "Extract constant", "codeActions.refactor.extract.constant.description": "Extract expression to constant.", "codeActions.refactor.extract.function.title": "Extract function", diff --git a/extensions/typescript-language-features/src/features/workspaceSymbols.ts b/extensions/typescript-language-features/src/features/workspaceSymbols.ts index e23c21eeb37..e4caa5b5977 100644 --- a/extensions/typescript-language-features/src/features/workspaceSymbols.ts +++ b/extensions/typescript-language-features/src/features/workspaceSymbols.ts @@ -5,11 +5,12 @@ import * as vscode from 'vscode'; import type * as Proto from '../protocol'; +import * as PConst from '../protocol.const'; import { ITypeScriptServiceClient } from '../typescriptService'; +import API from '../utils/api'; import * as fileSchemes from '../utils/fileSchemes'; import { doesResourceLookLikeAJavaScriptFile, doesResourceLookLikeATypeScriptFile } from '../utils/languageDescription'; import * as typeConverters from '../utils/typeConverters'; -import * as PConst from '../protocol.const'; function getSymbolKind(item: Proto.NavtoItem): vscode.SymbolKind { switch (item.kind) { @@ -29,27 +30,33 @@ function getSymbolKind(item: Proto.NavtoItem): vscode.SymbolKind { } class TypeScriptWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider { + public constructor( private readonly client: ITypeScriptServiceClient, - private readonly modeIds: readonly string[] + private readonly modeIds: readonly string[], ) { } public async provideWorkspaceSymbols( search: string, token: vscode.CancellationToken ): Promise { - const document = this.getDocument(); - if (!document) { - return []; - } + let file: string | undefined; + if (this.searchAllOpenProjects) { + file = undefined; + } else { + const document = this.getDocument(); + if (!document) { + return []; + } - const filepath = await this.toOpenedFiledPath(document); - if (!filepath) { - return []; + file = await this.toOpenedFiledPath(document); + if (!file) { + return []; + } } const args: Proto.NavtoRequestArgs = { - file: filepath, + file: file!, // TS 3.9+ supports using undefined to search all open projects searchValue: search, maxResultCount: 256, }; @@ -64,6 +71,10 @@ class TypeScriptWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvide .map(item => this.toSymbolInformation(item)); } + private get searchAllOpenProjects() { + return this.client.apiVersion.gte(API.v390) + && vscode.workspace.getConfiguration('typescript').get('workspaceSymbols.scope', 'allOpenProjects') === 'allOpenProjects'; + } private async toOpenedFiledPath(document: vscode.TextDocument) { if (document.uri.scheme === fileSchemes.git) {