Enable JS/TS workspace symbol search for all projects
Fixes #11026 Adds a new `typescript.workspaceSymbols.scope` setting that enables searching all known projects when using TS 3.9+
This commit is contained in:
parent
9448f6e5ed
commit
a4597e1905
3 changed files with 38 additions and 10 deletions
|
@ -842,6 +842,20 @@
|
||||||
"description": "%configuration.tsserver.watchOptions.synchronousWatchDirectory%"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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.",
|
"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.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.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.title": "Extract constant",
|
||||||
"codeActions.refactor.extract.constant.description": "Extract expression to constant.",
|
"codeActions.refactor.extract.constant.description": "Extract expression to constant.",
|
||||||
"codeActions.refactor.extract.function.title": "Extract function",
|
"codeActions.refactor.extract.function.title": "Extract function",
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import type * as Proto from '../protocol';
|
import type * as Proto from '../protocol';
|
||||||
|
import * as PConst from '../protocol.const';
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||||
|
import API from '../utils/api';
|
||||||
import * as fileSchemes from '../utils/fileSchemes';
|
import * as fileSchemes from '../utils/fileSchemes';
|
||||||
import { doesResourceLookLikeAJavaScriptFile, doesResourceLookLikeATypeScriptFile } from '../utils/languageDescription';
|
import { doesResourceLookLikeAJavaScriptFile, doesResourceLookLikeATypeScriptFile } from '../utils/languageDescription';
|
||||||
import * as typeConverters from '../utils/typeConverters';
|
import * as typeConverters from '../utils/typeConverters';
|
||||||
import * as PConst from '../protocol.const';
|
|
||||||
|
|
||||||
function getSymbolKind(item: Proto.NavtoItem): vscode.SymbolKind {
|
function getSymbolKind(item: Proto.NavtoItem): vscode.SymbolKind {
|
||||||
switch (item.kind) {
|
switch (item.kind) {
|
||||||
|
@ -29,27 +30,33 @@ function getSymbolKind(item: Proto.NavtoItem): vscode.SymbolKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeScriptWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
|
class TypeScriptWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly client: ITypeScriptServiceClient,
|
private readonly client: ITypeScriptServiceClient,
|
||||||
private readonly modeIds: readonly string[]
|
private readonly modeIds: readonly string[],
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public async provideWorkspaceSymbols(
|
public async provideWorkspaceSymbols(
|
||||||
search: string,
|
search: string,
|
||||||
token: vscode.CancellationToken
|
token: vscode.CancellationToken
|
||||||
): Promise<vscode.SymbolInformation[]> {
|
): Promise<vscode.SymbolInformation[]> {
|
||||||
|
let file: string | undefined;
|
||||||
|
if (this.searchAllOpenProjects) {
|
||||||
|
file = undefined;
|
||||||
|
} else {
|
||||||
const document = this.getDocument();
|
const document = this.getDocument();
|
||||||
if (!document) {
|
if (!document) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const filepath = await this.toOpenedFiledPath(document);
|
file = await this.toOpenedFiledPath(document);
|
||||||
if (!filepath) {
|
if (!file) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const args: Proto.NavtoRequestArgs = {
|
const args: Proto.NavtoRequestArgs = {
|
||||||
file: filepath,
|
file: file!, // TS 3.9+ supports using undefined to search all open projects
|
||||||
searchValue: search,
|
searchValue: search,
|
||||||
maxResultCount: 256,
|
maxResultCount: 256,
|
||||||
};
|
};
|
||||||
|
@ -64,6 +71,10 @@ class TypeScriptWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvide
|
||||||
.map(item => this.toSymbolInformation(item));
|
.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) {
|
private async toOpenedFiledPath(document: vscode.TextDocument) {
|
||||||
if (document.uri.scheme === fileSchemes.git) {
|
if (document.uri.scheme === fileSchemes.git) {
|
||||||
|
|
Loading…
Reference in a new issue