-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.ts
49 lines (44 loc) · 1.85 KB
/
main.ts
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
import * as vscode from 'vscode';
import {
TestEvent,
testExplorerExtensionId,
TestHub,
TestLoadStartedEvent,
TestLoadFinishedEvent,
TestRunStartedEvent,
TestRunFinishedEvent,
TestSuiteEvent
} from 'vscode-test-adapter-api';
import { Log, TestAdapterRegistrar } from 'vscode-test-adapter-util';
import { RustAdapter } from './rust-adapter';
type TestRunEvent = TestRunStartedEvent | TestRunFinishedEvent | TestSuiteEvent | TestEvent;
type TestLoadEvent = TestLoadStartedEvent | TestLoadFinishedEvent;
const registerAdapter = (
testExplorerExtension: vscode.Extension<TestHub>,
context: vscode.ExtensionContext,
adapterFactory: (workspaceFolder: vscode.WorkspaceFolder) => RustAdapter) => {
const testHub = testExplorerExtension.exports;
context.subscriptions.push(new TestAdapterRegistrar(testHub, adapterFactory));
};
export async function activate(context: vscode.ExtensionContext) {
const workspaceFolder = (vscode.workspace.workspaceFolders || [])[0];
const log = new Log('rustTestExplorer', workspaceFolder, 'Rust Explorer Log');
context.subscriptions.push(log);
const testExplorerExtension = vscode.extensions.getExtension<TestHub>(testExplorerExtensionId);
if (log.enabled) {
log.info(`Test Explorer ${testExplorerExtension ? '' : 'not '}found`);
}
if (testExplorerExtension) {
const testsEmitter = new vscode.EventEmitter<TestLoadEvent>();
const testStatesEmitter = new vscode.EventEmitter<TestRunEvent>();
const autorunEmitter = new vscode.EventEmitter<void>();
const adapterFactory = workspaceFolder => new RustAdapter(
workspaceFolder.uri.fsPath,
log,
testsEmitter,
testStatesEmitter,
autorunEmitter
);
registerAdapter(testExplorerExtension, context, adapterFactory);
}
}