Skip to content

Commit a9a5551

Browse files
committed
src/goTestExplorer: support VSCode 1.58
1 parent 9ad01bf commit a9a5551

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"yarn": "^1.22.4"
8888
},
8989
"engines": {
90-
"vscode": "^1.59.0"
90+
"vscode": "^1.58.0"
9191
},
9292
"activationEvents": [
9393
"workspaceContains:**/*.go",
@@ -1291,7 +1291,10 @@
12911291
},
12921292
"go.testExplorerPackages": {
12931293
"type": "string",
1294-
"enum": ["flat", "nested"],
1294+
"enum": [
1295+
"flat",
1296+
"nested"
1297+
],
12951298
"default": "flat",
12961299
"description": "Control whether packages are presented flat or nested",
12971300
"scope": "resource"

src/goMain.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ import { getFormatTool } from './goFormat';
114114
import { resetSurveyConfig, showSurveyConfig, timeMinute } from './goSurvey';
115115
import { ExtensionAPI } from './export';
116116
import extensionAPI from './extensionAPI';
117-
import { TestExplorer } from './goTestExplorer';
117+
import { isVscodeTestingAPIAvailable, TestExplorer } from './goTestExplorer';
118118

119119
export let buildDiagnosticCollection: vscode.DiagnosticCollection;
120120
export let lintDiagnosticCollection: vscode.DiagnosticCollection;
@@ -336,13 +336,15 @@ If you would like additional configuration for diagnostics from gopls, please se
336336
})
337337
);
338338

339-
const testExplorer = TestExplorer.setup(ctx);
339+
if (isVscodeTestingAPIAvailable) {
340+
const testExplorer = TestExplorer.setup(ctx);
340341

341-
ctx.subscriptions.push(
342-
vscode.commands.registerCommand('go.test.refresh', (args) => {
343-
if (args) testExplorer.resolve(args);
344-
})
345-
);
342+
ctx.subscriptions.push(
343+
vscode.commands.registerCommand('go.test.refresh', (args) => {
344+
if (args) testExplorer.resolve(args);
345+
})
346+
);
347+
}
346348

347349
ctx.subscriptions.push(
348350
vscode.commands.registerCommand('go.subtest.cursor', (args) => {

src/goTestExplorer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ import { getGoConfig } from './config';
3636
import { getTestFlags, goTest, GoTestOutput } from './testUtils';
3737
import { outputChannel } from './goStatus';
3838

39+
// Set true only if the vscode is the recent version that has the workspace trust API AND
40+
// if the security.workspace.trust is enabled. Change of this configuration requires restart
41+
// of VSCode, so we don't need to set up the configuration change listener.
42+
// TODO(hyangah): remove this and Configuration & WrappedConfiguration when we update
43+
// our extension to require 2021 June VSCode engine.
44+
export const isVscodeTestingAPIAvailable =
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46+
'object' === typeof (vscode as any).tests && 'function' === typeof vscode.tests.createTestController;
47+
3948
// eslint-disable-next-line @typescript-eslint/no-namespace
4049
export namespace TestExplorer {
4150
// exported for tests
@@ -86,6 +95,8 @@ async function doSafe<T>(context: string, p: Thenable<T> | (() => T | Thenable<T
8695

8796
export class TestExplorer {
8897
static setup(context: ExtensionContext): TestExplorer {
98+
if (!isVscodeTestingAPIAvailable) throw new Error('VSCode Testing API is unavailable');
99+
89100
const ctrl = vscode.tests.createTestController('go', 'Go');
90101
const getSym = new GoDocumentSymbolProvider().provideDocumentSymbols;
91102
const inst = new this(ctrl, workspace, getSym);

0 commit comments

Comments
 (0)