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 33ba500 commit 7d8ab99
Show file tree
Hide file tree
Showing 4 changed files with 26 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 @@ -1290,7 +1290,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
11 changes: 11 additions & 0 deletions src/goTestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ import { getGoConfig } from './config';
import { getTestFlags, goTest, GoTestOutput } from './testUtils';
import { outputChannel } from './goStatus';

// Set true only if the vscode is the recent version that has the workspace trust API AND
// if the security.workspace.trust is enabled. Change of this configuration requires restart
// of VSCode, so we don't need to set up the configuration change listener.
// TODO(hyangah): remove this and Configuration & WrappedConfiguration when we update
// our extension to require 2021 June VSCode engine.
export const isVscodeTestingAPIAvailable =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'object' === typeof (vscode as any).tests && 'function' === typeof vscode.tests.createTestController;

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace TestExplorer {
// exported for tests
Expand Down Expand Up @@ -86,6 +95,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 7d8ab99

Please sign in to comment.