-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathworkspaceSymbolProvider.ts
More file actions
71 lines (66 loc) · 2.99 KB
/
workspaceSymbolProvider.ts
File metadata and controls
71 lines (66 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { ResponseError } from 'vscode-languageclient';
import { DefaultClient, GetSymbolInfoRequest, LocalizeSymbolInformation, SymbolScope, WorkspaceSymbolParams } from '../client';
import { getLocalizedString, getLocalizedSymbolScope } from '../localization';
import { RequestCancelled, ServerCancelled } from '../protocolFilter';
import { makeVscodeLocation } from '../utils';
export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}
public async provideWorkspaceSymbols(query: string, token: vscode.CancellationToken): Promise<vscode.SymbolInformation[]> {
// if the query is empty, then return as quickly as possible
if (!query) {
return [];
}
const params: WorkspaceSymbolParams = {
query: query,
experimentEnabled: true
};
let symbols: LocalizeSymbolInformation[];
try {
symbols = await this.client.languageClient.sendRequest(GetSymbolInfoRequest, params, token);
} catch (e: any) {
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
throw new vscode.CancellationError();
}
throw e;
}
const resultSymbols: vscode.SymbolInformation[] = [];
if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}
// Convert to vscode.Command array
symbols.forEach((symbol) => {
let suffix: string = getLocalizedString(symbol.suffix);
let name: string = symbol.name;
if (suffix.length) {
if (symbol.scope === SymbolScope.Private) {
suffix = getLocalizedSymbolScope("private", suffix);
} else if (symbol.scope === SymbolScope.Protected) {
suffix = getLocalizedSymbolScope("protected", suffix);
}
name = name + ' (' + suffix + ')';
} else {
if (symbol.scope === SymbolScope.Private) {
name = name + " (private)";
} else if (symbol.scope === SymbolScope.Protected) {
name = name + " (protected)";
}
}
const vscodeSymbol: vscode.SymbolInformation = new vscode.SymbolInformation(
name,
symbol.kind,
symbol.containerName,
makeVscodeLocation(symbol.location)
);
resultSymbols.push(vscodeSymbol);
});
return resultSymbols;
}
}