forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.ts
More file actions
39 lines (36 loc) · 1.65 KB
/
helper.ts
File metadata and controls
39 lines (36 loc) · 1.65 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable, named } from 'inversify';
import { CancellationToken, SymbolInformation, TextDocument, TextEditor, Uri } from 'vscode';
import { IDocumentManager } from '../../common/application/types';
import { traceError } from '../../common/logger';
import { IDocumentSymbolProvider } from '../../common/types';
import { ITestNavigatorHelper, SymbolSearch } from './types';
@injectable()
export class TestNavigatorHelper implements ITestNavigatorHelper {
constructor(
@inject(IDocumentManager) private readonly documentManager: IDocumentManager,
@inject(IDocumentSymbolProvider) @named('test') private readonly symbolProvider: IDocumentSymbolProvider,
) {}
public async openFile(file?: Uri): Promise<[TextDocument, TextEditor]> {
if (!file) {
throw new Error('Unable to navigate to an undefined test file');
}
const doc = await this.documentManager.openTextDocument(file);
const editor = await this.documentManager.showTextDocument(doc);
return [doc, editor];
}
public async findSymbol(
doc: TextDocument,
search: SymbolSearch,
token: CancellationToken,
): Promise<SymbolInformation | undefined> {
const symbols = (await this.symbolProvider.provideDocumentSymbols(doc, token)) as SymbolInformation[];
if (!Array.isArray(symbols) || symbols.length === 0) {
traceError('Symbol information not found', new Error('Symbol information not found'));
return;
}
return symbols.find(search);
}
}