Skip to content

Commit a3034a0

Browse files
committed
support python unittest framework #239
1 parent b0927e0 commit a3034a0

6 files changed

Lines changed: 119 additions & 3 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import {CodeLensProvider, TextDocument, CancellationToken, CodeLens, SymbolInformation} from 'vscode';
5+
import * as telemetryContracts from '../common/telemetryContracts';
6+
7+
export class TestResultsCodeLensProvider implements CodeLensProvider {
8+
constructor(private symbolProvider: vscode.DocumentSymbolProvider) {
9+
// The command has been defined in the package.json file
10+
// Now provide the implementation of the command with registerCommand
11+
// The commandId parameter must match the command field in package.json
12+
vscode.commands.registerCommand('extension.sayHello', () => {
13+
// The code you place here will be executed every time your command is executed
14+
15+
// Display a message box to the user
16+
vscode.window.showInformationMessage('Hello World!');
17+
vscode.commands.executeCommand('vscode.executeCodeLensProvider', vscode.window.activeTextEditor.document.uri)
18+
});
19+
20+
}
21+
22+
23+
public provideCodeLenses(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> {
24+
let promise = this.symbolProvider.provideDocumentSymbols(document, token) as PromiseLike<SymbolInformation[]>;
25+
return promise.then(symbols => {
26+
return symbols.filter(symbol => {
27+
return symbol.kind === vscode.SymbolKind.Function ||
28+
symbol.kind === vscode.SymbolKind.Method ||
29+
symbol.kind === vscode.SymbolKind.Class;
30+
}).map(symbol => {
31+
let lens = new CodeLens(symbol.location.range);//, { command: 'python.sortImports', title: 'Wow, 1, 2, 3', arguments: [] });
32+
return lens;
33+
// return <CodeLens>{ range: symbol.location.range, isResolved: false } as CodeLens;
34+
});
35+
});
36+
}
37+
38+
public resolveCodeLens(codeLens: CodeLens, token: CancellationToken): Thenable<CodeLens> {
39+
return new Promise<CodeLens>(resolve => {
40+
codeLens.isResolved = true;
41+
codeLens.command = { command: 'extension.sayHello', title: 'Wow, 1, 2, 3', arguments: [] };
42+
resolve(codeLens);
43+
});
44+
// return codeLens;
45+
}
46+
}

src/client/unittests/codeLenses/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export function activateCodeLenses(): vscode.Disposable {
1212
disposables.forEach(d => d.dispose());
1313
}
1414
}
15-
}
15+
}

src/client/unittests/codeLenses/testFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class TestFileCodeLensProvider implements CodeLensProvider {
2727
let cancelTokenSrc = new vscode.CancellationTokenSource();
2828
token.onCancellationRequested(() => { cancelTokenSrc.cancel(); });
2929

30-
// Strop trying to build the code lenses if unable to get a list of
30+
// Strop trying to build the code lenses if unable to get a list of
3131
// symbols in this file afrer x time
3232
setTimeout(() => {
3333
if (!cancelTokenSrc.token.isCancellationRequested) {

src/client/unittests/nosetest/runner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ export function updateResultsFromLogFiles(tests: Tests, outputXmlFile: string):
4949
return tests;
5050
});
5151
}
52-
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import {CodeLensProvider, TextDocument, CancellationToken, CodeLens, SymbolInformation} from 'vscode';
5+
import * as telemetryContracts from '../common/telemetryContracts';
6+
import {Tests} from './common/contracts';
7+
import {getDiscoveredTests} from './common/testUtils';
8+
9+
export class TestFileCodeLensProvider implements CodeLensProvider {
10+
constructor(private context: vscode.ExtensionContext) {
11+
// The command has been defined in the package.json file
12+
// Now provide the implementation of the command with registerCommand
13+
// The commandId parameter must match the command field in package.json
14+
vscode.commands.registerCommand('extension.sayHello', () => {
15+
// The code you place here will be executed every time your command is executed
16+
17+
// Display a message box to the user
18+
vscode.window.showInformationMessage('Hello World!');
19+
vscode.commands.executeCommand('vscode.executeCodeLensProvider', vscode.window.activeTextEditor.document.uri);
20+
});
21+
22+
}
23+
24+
// private _onDidChange = new vscode.EventEmitter<CodeLensProvider>();
25+
// get onDidChange(): vscode.Event<CodeLensProvider> {
26+
// return this._onDidChange.event;
27+
// }
28+
29+
// public update() {
30+
// this._onDidChange.fire(this);
31+
// }
32+
33+
public provideCodeLenses(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> {
34+
let testItems = getDiscoveredTests();
35+
if (!testItems) {
36+
return Promise.resolve([]);
37+
}
38+
39+
let items: CodeLens[] = [];
40+
return vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', document.uri).then((symbols: vscode.SymbolInformation[]) => {
41+
return symbols.filter(symbol => {
42+
return symbol.kind === vscode.SymbolKind.Function ||
43+
symbol.kind === vscode.SymbolKind.Method ||
44+
symbol.kind === vscode.SymbolKind.Class;
45+
}).map(symbol => {
46+
// let lens = new CodeLens(symbol.location.range);//, { command: 'python.sortImports', title: 'Wow, 1, 2, 3', arguments: [] });
47+
// return lens;
48+
return <CodeLens>{ range: symbol.location.range, isResolved: false } as CodeLens;
49+
});
50+
});
51+
}
52+
53+
private counter = 0;
54+
public resolveCodeLens(codeLens: CodeLens, token: CancellationToken): Thenable<CodeLens> {
55+
return new Promise<CodeLens>(resolve => {
56+
codeLens.isResolved = true;
57+
codeLens.command = { command: 'extension.sayHello', title: 'Wow ' + this.counter++, arguments: [] };
58+
resolve(codeLens);
59+
});
60+
// return codeLens;
61+
}
62+
}

src/client/unittests/todo.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ Do we use the vscode.executeCodeLensProvider? (complex commands)
2121

2222
**Status Bar**
2323
- Add command for satusbar:
24+
<<<<<<< b0927e0baf2e1c2fd0cc96b48ae637343410c4b2:src/client/unittests/todo.md
2425
+ In the pick list of functions, if a function is selected:
2526
+ View test result for selected function
2627
+ Debug function
2728
+ Run test function
2829
+ Navigate to that test function
2930

31+
=======
32+
+ Run all tests
33+
+ Run failed tests
34+
+ Run previous tests
35+
+ Run specific test
36+
+ This displays a picklist of tests (user can filter and select)
37+
(again low priority)
38+
>>>>>>> support python unittest framework #239:src/client/unittests/todo.md

0 commit comments

Comments
 (0)