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
59 lines (53 loc) · 2.39 KB
/
provider.ts
File metadata and controls
59 lines (53 loc) · 2.39 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
'use strict';
// tslint:disable-next-line:no-var-requires no-require-imports
const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
import {
CancellationToken, Location, SymbolInformation,
Uri, WorkspaceSymbolProvider as IWorspaceSymbolProvider
} from 'vscode';
import { ICommandManager } from '../common/application/types';
import { Commands } from '../common/constants';
import { IFileSystem } from '../common/platform/types';
import { captureTelemetry } from '../telemetry';
import { EventName } from '../telemetry/constants';
import { Generator } from './generator';
import { parseTags } from './parser';
export class WorkspaceSymbolProvider implements IWorspaceSymbolProvider {
public constructor(
private fs: IFileSystem,
private commands: ICommandManager,
private tagGenerators: Generator[]
) {
}
@captureTelemetry(EventName.WORKSPACE_SYMBOLS_GO_TO)
public async provideWorkspaceSymbols(query: string, token: CancellationToken): Promise<SymbolInformation[]> {
if (this.tagGenerators.length === 0) {
return [];
}
const generatorsWithTagFiles = await Promise.all(this.tagGenerators.map(generator => this.fs.fileExists(generator.tagFilePath)));
if (generatorsWithTagFiles.filter(exists => exists).length !== this.tagGenerators.length) {
await this.commands.executeCommand(Commands.Build_Workspace_Symbols, true, token);
}
const generators: Generator[] = [];
await Promise.all(this.tagGenerators.map(async generator => {
if (await this.fs.fileExists(generator.tagFilePath)) {
generators.push(generator);
}
}));
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 SymbolInformation(
item.symbolName, item.symbolKind, '',
new Location(Uri.file(item.fileName), item.position)
));
});
const symbols = await Promise.all(promises);
return flatten(symbols);
}
}