diff --git a/package-lock.json b/package-lock.json index ec07edc1b5..cd32598e12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "yarn": "^1.22.4" }, "engines": { - "vscode": "^1.59.0" + "vscode": "^1.58.0" } }, "node_modules/@babel/code-frame": { diff --git a/package.json b/package.json index 2567bcda51..0adcb9aa2c 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "yarn": "^1.22.4" }, "engines": { - "vscode": "^1.59.0" + "vscode": "^1.58.0" }, "activationEvents": [ "workspaceContains:**/*.go", @@ -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" diff --git a/src/goMain.ts b/src/goMain.ts index 351d625cf0..5f7d26d46f 100644 --- a/src/goMain.ts +++ b/src/goMain.ts @@ -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; @@ -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) => { diff --git a/src/goTestExplorer.ts b/src/goTestExplorer.ts index b18fc7d205..94a74a94e1 100644 --- a/src/goTestExplorer.ts +++ b/src/goTestExplorer.ts @@ -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 @@ -86,6 +91,8 @@ async function doSafe(context: string, p: Thenable | (() => T | Thenable