mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Clean up provideDocumentSymbols
- Returned undefined instead of empty array - Only execute server call in try catch
This commit is contained in:
@@ -34,30 +34,30 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider
|
|||||||
private readonly client: ITypeScriptServiceClient
|
private readonly client: ITypeScriptServiceClient
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public async provideDocumentSymbols(resource: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[] | vscode.SymbolInformation[]> {
|
public async provideDocumentSymbols(resource: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[] | undefined> {
|
||||||
const filepath = this.client.toPath(resource.uri);
|
const file = this.client.toPath(resource.uri);
|
||||||
if (!filepath) {
|
if (!file) {
|
||||||
return [];
|
return undefined;
|
||||||
}
|
}
|
||||||
const args: Proto.FileRequestArgs = {
|
|
||||||
file: filepath
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
let tree: Proto.NavigationTree | undefined;
|
||||||
try {
|
try {
|
||||||
|
const args: Proto.FileRequestArgs = { file };
|
||||||
const response = await this.client.execute('navtree', args, token);
|
const response = await this.client.execute('navtree', args, token);
|
||||||
if (response.body) {
|
tree = response.body;
|
||||||
// The root represents the file. Ignore this when showing in the UI
|
} catch {
|
||||||
const tree = response.body;
|
return undefined;
|
||||||
if (tree.childItems) {
|
|
||||||
const result = new Array<vscode.DocumentSymbol>();
|
|
||||||
tree.childItems.forEach(item => TypeScriptDocumentSymbolProvider.convertNavTree(resource.uri, result, item));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
} catch (e) {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tree && tree.childItems) {
|
||||||
|
// The root represents the file. Ignore this when showing in the UI
|
||||||
|
const result: vscode.DocumentSymbol[] = [];
|
||||||
|
tree.childItems.forEach(item => TypeScriptDocumentSymbolProvider.convertNavTree(resource.uri, result, item));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static convertNavTree(resource: vscode.Uri, bucket: vscode.DocumentSymbol[], item: Proto.NavigationTree): boolean {
|
private static convertNavTree(resource: vscode.Uri, bucket: vscode.DocumentSymbol[], item: Proto.NavigationTree): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user