Skip to content

Commit

Permalink
src/goTestExplorer: support VSCode 1.58
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Aug 13, 2021
1 parent 9ad01bf commit 5e41e65
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"yarn": "^1.22.4"
},
"engines": {
"vscode": "^1.59.0"
"vscode": "^1.58.0"
},
"activationEvents": [
"workspaceContains:**/*.go",
Expand Down Expand Up @@ -1291,7 +1291,10 @@
},
"go.testExplorerPackages": {
"type": "string",
"enum": ["flat", "nested"],
"enum": [
"flat",
"nested"
],
"default": "flat",
"description": "Control whether packages are presented flat or nested",
"scope": "resource"
Expand Down
16 changes: 9 additions & 7 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ import { getFormatTool } from './goFormat';
import { resetSurveyConfig, showSurveyConfig, timeMinute } from './goSurvey';
import { ExtensionAPI } from './export';
import extensionAPI from './extensionAPI';
import { TestExplorer } from './goTestExplorer';
import { isVscodeTestingAPIAvailable, TestExplorer } from './goTestExplorer';

export let buildDiagnosticCollection: vscode.DiagnosticCollection;
export let lintDiagnosticCollection: vscode.DiagnosticCollection;
Expand Down Expand Up @@ -336,13 +336,15 @@ If you would like additional configuration for diagnostics from gopls, please se
})
);

const testExplorer = TestExplorer.setup(ctx);
if (isVscodeTestingAPIAvailable) {
const testExplorer = TestExplorer.setup(ctx);

ctx.subscriptions.push(
vscode.commands.registerCommand('go.test.refresh', (args) => {
if (args) testExplorer.resolve(args);
})
);
ctx.subscriptions.push(
vscode.commands.registerCommand('go.test.refresh', (args) => {
if (args) testExplorer.resolve(args);
})
);
}

ctx.subscriptions.push(
vscode.commands.registerCommand('go.subtest.cursor', (args) => {
Expand Down
7 changes: 7 additions & 0 deletions src/goTestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import { getGoConfig } from './config';
import { getTestFlags, goTest, GoTestOutput } from './testUtils';
import { outputChannel } from './goStatus';

// Set true only if the Testing API is available (VSCode version >= 1.59).
export const isVscodeTestingAPIAvailable =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'object' === typeof (vscode as any).tests && 'function' === typeof (vscode as any).tests.createTestController;

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace TestExplorer {
// exported for tests
Expand Down Expand Up @@ -86,6 +91,8 @@ async function doSafe<T>(context: string, p: Thenable<T> | (() => T | Thenable<T

export class TestExplorer {
static setup(context: ExtensionContext): TestExplorer {
if (!isVscodeTestingAPIAvailable) throw new Error('VSCode Testing API is unavailable');

const ctrl = vscode.tests.createTestController('go', 'Go');
const getSym = new GoDocumentSymbolProvider().provideDocumentSymbols;
const inst = new this(ctrl, workspace, getSym);
Expand Down

0 comments on commit 5e41e65

Please sign in to comment.