diff --git a/package-lock.json b/package-lock.json index ddda5fd9b6..40622d80e2 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 ca8de271bb..8437377105 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", @@ -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" 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..89ed23b0c0 100644 --- a/src/goTestExplorer.ts +++ b/src/goTestExplorer.ts @@ -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 @@ -86,6 +95,8 @@ async function doSafe(context: string, p: Thenable | (() => T | Thenable