提交 c94789c5 编写于 作者: M Matt Bierner

Add Filename to JS/TS Workspace Symbol Search

Fixes #22357

Adds file name to the workspace symbol results for JS and TS
上级 0f102b95
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Range, Location, CancellationToken } from 'vscode'; import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Range, Location, CancellationToken } from 'vscode';
import * as path from 'path';
import * as Proto from '../protocol'; import * as Proto from '../protocol';
import { ITypescriptServiceClient } from '../typescriptService'; import { ITypescriptServiceClient } from '../typescriptService';
...@@ -28,7 +30,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo ...@@ -28,7 +30,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
// general questions so we check the active editor. If this // general questions so we check the active editor. If this
// doesn't match we take the first TS document. // doesn't match we take the first TS document.
let uri: Uri | undefined = undefined; let uri: Uri | undefined = undefined;
let editor = window.activeTextEditor; const editor = window.activeTextEditor;
if (editor) { if (editor) {
let document = editor.document; let document = editor.document;
if (document && document.languageId === this.modeId) { if (document && document.languageId === this.modeId) {
...@@ -53,34 +55,39 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo ...@@ -53,34 +55,39 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
if (!filepath) { if (!filepath) {
return Promise.resolve<SymbolInformation[]>([]); return Promise.resolve<SymbolInformation[]>([]);
} }
let args: Proto.NavtoRequestArgs = { const args: Proto.NavtoRequestArgs = {
file: filepath, file: filepath,
searchValue: search searchValue: search
}; };
if (!args.file) {
return Promise.resolve<SymbolInformation[]>([]);
}
return this.client.execute('navto', args, token).then((response): SymbolInformation[] => { return this.client.execute('navto', args, token).then((response): SymbolInformation[] => {
let data = response.body; let data = response.body;
if (data) { if (data) {
let result: SymbolInformation[] = []; const result: SymbolInformation[] = [];
for (let item of data) { for (let item of data) {
if (!item.containerName && item.kind === 'alias') { if (!item.containerName && item.kind === 'alias') {
continue; continue;
} }
let range = new Range(item.start.line - 1, item.start.offset - 1, item.end.line - 1, item.end.offset - 1); const range = new Range(item.start.line - 1, item.start.offset - 1, item.end.line - 1, item.end.offset - 1);
let label = item.name; let label = item.name;
if (item.kind === 'method' || item.kind === 'function') { if (item.kind === 'method' || item.kind === 'function') {
label += '()'; label += '()';
} }
result.push(new SymbolInformation(label, _kindMapping[item.kind], item.containerName ? item.containerName : '', const containerNameParts: string[] = [];
new Location(this.client.asUrl(item.file), range))); if (item.containerName) {
containerNameParts.push(item.containerName);
}
const fileUri = this.client.asUrl(item.file);
const fileName = path.basename(fileUri.fsPath);
if (fileName) {
containerNameParts.push(fileName);
}
result.push(new SymbolInformation(label, _kindMapping[item.kind], containerNameParts.join(''),
new Location(fileUri, range)));
} }
return result; return result;
} else { } else {
return []; return [];
} }
}, (err) => { }, (err) => {
this.client.error(`'navto' request failed with error.`, err); this.client.error(`'navto' request failed with error.`, err);
return []; return [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册