forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.ts
More file actions
46 lines (41 loc) · 2.08 KB
/
provider.ts
File metadata and controls
46 lines (41 loc) · 2.08 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
import * as _ from 'lodash';
import * as vscode from 'vscode';
import { Commands } from '../common/constants';
import { fsExistsAsync } from '../common/utils';
import { captureTelemetry } from '../telemetry';
import { WORKSPACE_SYMBOLS_GO_TO } from '../telemetry/constants';
import { Generator } from './generator';
import { parseTags } from './parser';
export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
public constructor(private tagGenerators: Generator[], private outputChannel: vscode.OutputChannel) {
}
@captureTelemetry(WORKSPACE_SYMBOLS_GO_TO)
public async provideWorkspaceSymbols(query: string, token: vscode.CancellationToken): Promise<vscode.SymbolInformation[]> {
if (this.tagGenerators.length === 0) {
return [];
}
const generatorsWithTagFiles = await Promise.all(this.tagGenerators.map(generator => fsExistsAsync(generator.tagFilePath)));
if (generatorsWithTagFiles.filter(exists => exists).length !== this.tagGenerators.length) {
await vscode.commands.executeCommand(Commands.Build_Workspace_Symbols, true, token);
}
const generators = await Promise.all(this.tagGenerators.map(async generator => {
const tagFileExists = await fsExistsAsync(generator.tagFilePath);
return tagFileExists ? generator : undefined;
}));
const promises = generators
.filter(generator => generator !== undefined && generator.enabled)
.map(async generator => {
// load tags
const items = await parseTags(generator.workspaceFolder.fsPath, generator.tagFilePath, query, token);
if (!Array.isArray(items)) {
return [];
}
return items.map(item => new vscode.SymbolInformation(
item.symbolName, item.symbolKind, '',
new vscode.Location(vscode.Uri.file(item.fileName), item.position)
));
});
const symbols = await Promise.all(promises);
return _.flatten(symbols);
}
}