From a3d76a551242c61fcdc0aacc08009c2e68725ca8 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Thu, 12 Oct 2023 23:21:51 -0400 Subject: [PATCH] package.json: remove deprecated settings and remove legacy tools installation code. Deleted settings - Gocode related settings (go.gocodeFlags, go.gocodeAutoBuild, go.gocodePackageLookupMode) - Code suggestion settings (go.useCodeSnippetsOnFunctionSuggest, go.useCodeSnippetsOnFunctionSuggestWithoutType, go.autocompleteUnimportedPackages) - go.gotoSymbol.includeCoroot - go.docsTool - go.useGoProxyToCheckForToolUpdates (obsolete by go.toolsManagement flag in 2020. Delete all the transition code as well) - go.liveErrors For golang/vscode-go#2799 Change-Id: Id949d2f4ea5963553170a9c168b08752cc2e825f Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/535097 Commit-Queue: Hyang-Ah Hana Kim Reviewed-by: Robert Findley Reviewed-by: Suzy Mueller TryBot-Result: kokoro --- docs/settings.md | 84 +------------------ package.json | 121 +-------------------------- src/commands/getConfiguredGoTools.ts | 2 +- src/commands/startLanguageServer.ts | 15 ---- src/goExplorer.ts | 5 +- src/goInstallTools.ts | 25 ++---- src/goMain.ts | 22 ----- src/goTools.ts | 52 ++---------- src/language/goLanguageServer.ts | 37 -------- src/util.ts | 11 --- test/gopls/update.test.ts | 91 -------------------- test/integration/goExplorer.test.ts | 4 +- test/integration/install.test.ts | 27 +----- 13 files changed, 25 insertions(+), 471 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index 7a264708..1409958a 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -55,12 +55,6 @@ Alternate tools or alternate paths for the same tools used by the Go extension. | `dlv` | Alternate tool to use instead of the dlv binary or alternate path to use for the dlv binary.
Default: `"dlv"` | | `go` | Alternate tool to use instead of the go binary or alternate path to use for the go binary.
Default: `"go"` | | `gopls` | Alternate tool to use instead of the gopls binary or alternate path to use for the gopls binary.
Default: `"gopls"` | -### `go.autocompleteUnimportedPackages (deprecated)` - -Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -Include unimported packages in auto-complete suggestions. Not applicable when using the language server. - -Default: `false` ### `go.buildFlags` Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified. @@ -170,13 +164,6 @@ Default: `"Off"` If true, tests will not run concurrently. When a new test run is started, the previous will be cancelled. Default: `false` -### `go.docsTool (deprecated)` - -Documentation support without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -Pick 'godoc' or 'gogetdoc' to get documentation. Not applicable when using the language server.
-Allowed Options: `godoc`, `gogetdoc`, `guru` - -Default: `"godoc"` ### `go.editorContextMenuCommands` Experimental Feature: Enable/Disable entries from the context menu in the editor. @@ -251,47 +238,12 @@ Default: `"default"` ### `go.generateTestsFlags` Additional command line flags to pass to `gotests` for generating tests. -### `go.gocodeAutoBuild (deprecated)` - -`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`). -Enable gocode's autobuild feature. Not applicable when using the language server. - -Default: `false` -### `go.gocodeFlags (deprecated)` - -`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`). -Additional flags to pass to gocode. Not applicable when using the language server. - -Default: `["-builtin", "-ignore-case", "-unimported-packages"]` -### `go.gocodePackageLookupMode (deprecated)` - -`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`). -Used to determine the Go package lookup rules for completions by gocode. Not applicable when using the language server.
-Allowed Options: `go`, `gb`, `bzl` - -Default: `"go"` ### `go.gopath` Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true. ### `go.goroot` Specifies the GOROOT to use when no environment variable is set. -### `go.gotoSymbol.ignoreFolders (deprecated)` - -Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -Folder names (not paths) to ignore while using Go to Symbol in Workspace feature. Not applicable when using the language server. -### `go.gotoSymbol.includeGoroot (deprecated)` - -Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -If false, the standard library located at $GOROOT will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server. - -Default: `false` -### `go.gotoSymbol.includeImports (deprecated)` - -Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -If false, the import statements will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server. - -Default: `false` ### `go.inferGopath` Infer GOPATH from the workspace root. This is ignored when using Go Modules. @@ -393,22 +345,6 @@ Specifies Lint tool name.
Allowed Options: `staticcheck`, `golint`, `golangci-lint`, `revive` Default: `"staticcheck"` -### `go.liveErrors (deprecated)` - -Real-time diagnostics without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`). -Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay. Not applicable when using the language server. -| Properties | Description | -| --- | --- | -| `delay` | The number of milliseconds to delay before execution. Resets with each keystroke.
Default: `500` | -| `enabled` | If true, runs gotype on the file currently being edited and reports any semantic or syntactic errors found. Disabled when the language server is enabled.
Default: `false` | - -Default: -``` -{ - "delay" : 500, - "enabled" : false, -} -``` ### `go.logging.level` The logging level the extension logs at, defaults to 'error'
@@ -555,24 +491,6 @@ Trace the communication between VS Code and the Go language server.
Allowed Options: `off`, `messages`, `verbose` Default: `"off"` -### `go.useCodeSnippetsOnFunctionSuggest (deprecated)` - -Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`) and use [`gopls's `ui.completion.usePlaceholders` setting](https://github.com/golang/vscode-go/wiki/settings#uicompletionuseplaceholders) instead. -Complete functions with their parameter signature, including the variable type. Not propagated to the language server. - -Default: `false` -### `go.useCodeSnippetsOnFunctionSuggestWithoutType (deprecated)` - -Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`) and use [`gopls's `ui.completion.usePlaceholders` setting](https://github.com/golang/vscode-go/wiki/settings#uicompletionuseplaceholders) instead. -Complete functions with their parameter signature, excluding the variable types. Use `gopls.usePlaceholders` when using the language server. - -Default: `false` -### `go.useGoProxyToCheckForToolUpdates (deprecated)` - -Use `go.toolsManagement.checkForUpdates` instead. -When enabled, the extension automatically checks the Go proxy if there are updates available for Go and the Go tools (at present, only gopls) it depends on and prompts the user accordingly - -Default: `true` ### `go.useLanguageServer` Enable intellisense, code navigation, refactoring, formatting & diagnostics for Go. The features are powered by the Go language server "gopls". @@ -580,7 +498,7 @@ Enable intellisense, code navigation, refactoring, formatting & diagnostics for Default: `true` ### `go.vetFlags` -Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"]) +Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"]). Not applicable when using the language server's diagnostics. ### `go.vetOnSave` Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
diff --git a/package.json b/package.json index 558f678f..a56d9664 100644 --- a/package.json +++ b/package.json @@ -1229,7 +1229,7 @@ "type": "string" }, "default": [], - "description": "Flags to pass to `go tool vet` (e.g. [\"-all\", \"-shadow\"])", + "description": "Flags to pass to `go tool vet` (e.g. [\"-all\", \"-shadow\"]). Not applicable when using the language server's diagnostics.", "scope": "resource" }, "go.formatTool": { @@ -1513,72 +1513,6 @@ "description": "Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with `envFile` and `env` values with precedence `env` > `envFile` > `go.toolsEnvVars`.", "scope": "resource" }, - "go.gocodeFlags": { - "type": "array", - "items": { - "type": "string" - }, - "default": [ - "-builtin", - "-ignore-case", - "-unimported-packages" - ], - "description": "Additional flags to pass to gocode. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`)." - }, - "go.gocodeAutoBuild": { - "type": "boolean", - "default": false, - "description": "Enable gocode's autobuild feature. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`)." - }, - "go.gocodePackageLookupMode": { - "type": "string", - "enum": [ - "go", - "gb", - "bzl" - ], - "default": "go", - "description": "Used to determine the Go package lookup rules for completions by gocode. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "`gocode` is deprecated by the Go language server. Enable the Go language server (`#go.useLanguageServer#`)." - }, - "go.useCodeSnippetsOnFunctionSuggest": { - "type": "boolean", - "default": false, - "description": "Complete functions with their parameter signature, including the variable type. Not propagated to the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`) and use [`gopls's `ui.completion.usePlaceholders` setting](https://github.com/golang/vscode-go/wiki/settings#uicompletionuseplaceholders) instead." - }, - "go.useCodeSnippetsOnFunctionSuggestWithoutType": { - "type": "boolean", - "default": false, - "description": "Complete functions with their parameter signature, excluding the variable types. Use `gopls.usePlaceholders` when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`) and use [`gopls's `ui.completion.usePlaceholders` setting](https://github.com/golang/vscode-go/wiki/settings#uicompletionuseplaceholders) instead." - }, - "go.autocompleteUnimportedPackages": { - "type": "boolean", - "default": false, - "description": "Include unimported packages in auto-complete suggestions. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code completion without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, - "go.docsTool": { - "type": "string", - "default": "godoc", - "description": "Pick 'godoc' or 'gogetdoc' to get documentation. Not applicable when using the language server.", - "scope": "resource", - "enum": [ - "godoc", - "gogetdoc", - "guru" - ], - "markdownDeprecationMessage": "Documentation support without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, "go.useLanguageServer": { "type": "boolean", "default": true, @@ -1638,26 +1572,6 @@ "description": "Automatically update the tools used by the extension, without prompting the user.", "scope": "resource" }, - "go.useGoProxyToCheckForToolUpdates": { - "type": "boolean", - "default": true, - "description": "When enabled, the extension automatically checks the Go proxy if there are updates available for Go and the Go tools (at present, only gopls) it depends on and prompts the user accordingly", - "markdownDeprecationMessage": "Use `go.toolsManagement.checkForUpdates` instead." - }, - "go.gotoSymbol.includeImports": { - "type": "boolean", - "default": false, - "description": "If false, the import statements will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, - "go.gotoSymbol.includeGoroot": { - "type": "boolean", - "default": false, - "description": "If false, the standard library located at $GOROOT will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, "go.enableCodeLens": { "type": "object", "properties": { @@ -1721,29 +1635,6 @@ "description": "Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.", "scope": "resource" }, - "go.liveErrors": { - "type": "object", - "properties": { - "enabled": { - "type": "boolean", - "default": false, - "description": "If true, runs gotype on the file currently being edited and reports any semantic or syntactic errors found. Disabled when the language server is enabled." - }, - "delay": { - "type": "number", - "default": 500, - "description": "The number of milliseconds to delay before execution. Resets with each keystroke." - } - }, - "additionalProperties": false, - "default": { - "enabled": false, - "delay": 500 - }, - "description": "Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Real-time diagnostics without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, "go.removeTags": { "type": "object", "properties": { @@ -1904,16 +1795,6 @@ "description": "Experimental Feature: Enable/Disable entries from the context menu in the editor.", "scope": "resource" }, - "go.gotoSymbol.ignoreFolders": { - "type": "array", - "items": { - "type": "string" - }, - "default": [], - "description": "Folder names (not paths) to ignore while using Go to Symbol in Workspace feature. Not applicable when using the language server.", - "scope": "resource", - "markdownDeprecationMessage": "Code navigation without the language server is deprecated. Enable the Go language server (`#go.useLanguageServer#`)." - }, "go.delveConfig": { "type": "object", "properties": { diff --git a/src/commands/getConfiguredGoTools.ts b/src/commands/getConfiguredGoTools.ts index 6325e6ba..cc8296c1 100644 --- a/src/commands/getConfiguredGoTools.ts +++ b/src/commands/getConfiguredGoTools.ts @@ -39,7 +39,7 @@ export const getConfiguredGoTools: CommandFactory = () => { outputChannel.appendLine(''); const goVersion = await getGoVersion(); - const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig()); + const allTools = getConfiguredTools(getGoConfig(), getGoplsConfig()); const goVersionTooOld = goVersion?.lt('1.12') || false; outputChannel.appendLine(`\tgo:\t${goVersion?.binaryPath}: ${goVersion?.version}`); diff --git a/src/commands/startLanguageServer.ts b/src/commands/startLanguageServer.ts index 7f56f3e4..6c672fb5 100644 --- a/src/commands/startLanguageServer.ts +++ b/src/commands/startLanguageServer.ts @@ -9,18 +9,15 @@ import { CommandFactory } from '.'; import { getGoConfig } from '../config'; import { GoExtensionContext } from '../context'; import { outputChannel, updateLanguageServerIconGoStatusBar } from '../goStatus'; -import { getTool } from '../goTools'; import { buildLanguageClient, buildLanguageClientOption, buildLanguageServerConfig, errorKind, - languageServerUsingDefault, RestartReason, scheduleGoplsSuggestions, stopLanguageClient, suggestGoplsIssueReport, - suggestUpdateGopls, toServerInfo, updateRestartHistory } from '../language/goLanguageServer'; @@ -73,18 +70,6 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => { scheduleGoplsSuggestions(goCtx); } - // If the language server is gopls, we enable a few additional features. - if (cfg.serverName === 'gopls') { - const tool = getTool(cfg.serverName); - if (tool) { - // If the language server is turned on because it is enabled by default, - // make sure that the user is using a new enough version. - if (cfg.enabled && languageServerUsingDefault(goConfig)) { - suggestUpdateGopls(tool, cfg); - } - } - } - if (!cfg.enabled) { const legacyService = new LegacyLanguageService(); goCtx.legacyLanguageService = legacyService; diff --git a/src/goExplorer.ts b/src/goExplorer.ts index 52fdbc38..75a61e87 100644 --- a/src/goExplorer.ts +++ b/src/goExplorer.ts @@ -7,7 +7,7 @@ import vscodeUri = require('vscode-uri'); import os = require('os'); import path = require('path'); import { getGoConfig, getGoplsConfig } from './config'; -import { getBinPath, getGoVersion } from './util'; +import { getBinPath } from './util'; import { getConfiguredTools } from './goTools'; import { inspectGoToolVersion } from './goInstallTools'; import { runGoEnv } from './goModules'; @@ -159,8 +159,7 @@ export class GoExplorerProvider implements vscode.TreeDataProvider this.toolDetailCache.get(tool.name))); const items = []; for (const t of toolsInfo) { diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 17180680..a00fcd83 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -39,13 +39,7 @@ import { GoVersion, rmdirRecursive } from './util'; -import { - correctBinname, - getEnvPath, - executableFileExists, - getCurrentGoRoot, - setCurrentGoRoot -} from './utils/pathUtils'; +import { correctBinname, getEnvPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils'; import util = require('util'); import vscode = require('vscode'); import { RestartReason } from './language/goLanguageServer'; @@ -60,7 +54,7 @@ const declinedInstalls: Tool[] = []; export async function installAllTools(updateExistingToolsOnly = false) { const goVersion = await getGoVersion(); - let allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig()); + let allTools = getConfiguredTools(getGoConfig(), getGoplsConfig()); // exclude tools replaced by alternateTools. const alternateTools: { [key: string]: string } = getGoConfig().get('alternateTools') ?? {}; @@ -405,7 +399,7 @@ export async function promptForMissingTool(toolName: string) { } const installOptions = ['Install']; - let missing = await getMissingTools(goVersion); + let missing = await getMissingTools(); if (!containsTool(missing, tool)) { // If this function has been called, we want to display the prompt whether // it appears in missing or not. @@ -587,7 +581,7 @@ export async function offerToInstallTools() { alreadyOfferedToInstallTools = true; const goVersion = await getGoVersion(); - let missing = await getMissingTools(goVersion); + let missing = await getMissingTools(); missing = missing.filter((x) => x.isImportant); if (missing.length > 0) { addGoStatus( @@ -628,15 +622,10 @@ export async function offerToInstallTools() { }); }); } - - const goConfig = getGoConfig(); - if (!goConfig['useLanguageServer']) { - return; - } } -function getMissingTools(goVersion: GoVersion): Promise { - const keys = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig()); +function getMissingTools(): Promise { + const keys = getConfiguredTools(getGoConfig(), getGoplsConfig()); return Promise.all( keys.map( (tool) => @@ -790,7 +779,7 @@ export async function suggestUpdates() { return; } - const allTools = getConfiguredTools(configuredGoVersion, getGoConfig(), getGoplsConfig()); + const allTools = getConfiguredTools(getGoConfig(), getGoplsConfig()); const toolsToUpdate = await listOutdatedTools(configuredGoVersion, allTools); if (toolsToUpdate.length === 0) { return; diff --git a/src/goMain.ts b/src/goMain.ts index cad4893d..a4e0783e 100644 --- a/src/goMain.ts +++ b/src/goMain.ts @@ -94,7 +94,6 @@ export async function activate(ctx: vscode.ExtensionContext): Promise { - const forceUpdatedGoplsKey = 'forceUpdateForGoplsOnDefault'; - // forceUpdated is true when the process of updating has been succesfully completed. - const forceUpdated = getFromGlobalState(forceUpdatedGoplsKey, false); - // TODO: If we want to force update again, switch this to be a comparison for a newer version. - if (forceUpdated) { - return false; - } - // Update the state to the latest version to show the last version that was checked. - await updateGlobalState(forceUpdatedGoplsKey, tool.latestVersion); - - const latestVersion = await shouldUpdateLanguageServer(tool, cfg); - - if (!latestVersion) { - // The user is using a new enough version - return; - } - - const updateMsg = - "'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/README.md#installation) for the best experience."; - promptForUpdatingTool(tool.name, latestVersion, false, updateMsg); -} - // Copied from src/cmd/go/internal/modfetch.go. const pseudoVersionRE = /^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+incompatible)?$/; @@ -1625,11 +1593,6 @@ export function sanitizeGoplsTrace(logs?: string): { sanitizedLog?: string; fail return { failureReason: GoplsFailureModes.UNRECOGNIZED_CRASH_PATTERN }; } -export function languageServerUsingDefault(cfg: vscode.WorkspaceConfiguration): boolean { - const useLanguageServer = cfg.inspect('useLanguageServer'); - return useLanguageServer?.globalValue === undefined && useLanguageServer?.workspaceValue === undefined; -} - const GOPLS_FETCH_VULNCHECK_RESULT = 'gopls.fetch_vulncheck_result'; async function goplsFetchVulncheckResult(goCtx: GoExtensionContext, uri: string): Promise { const { languageClient } = goCtx; diff --git a/src/util.ts b/src/util.ts index 22adca49..1ebb298a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -159,17 +159,6 @@ let toolsGopath: string; // getCheckForToolsUpdatesConfig returns go.toolsManagement.checkForUpdates configuration. export function getCheckForToolsUpdatesConfig(gocfg: vscode.WorkspaceConfiguration) { - // useGoProxyToCheckForToolUpdates deprecation - // TODO: Step 1. mark as deprecated in Dec 2020 release, and update dev containers. - // Step 2. prompt users to switch config. Jan 2020 - // Step 3. delete useGoProxyToCheckForToolUpdates support. Feb 2020 - const legacyCfg = gocfg.get('useGoProxyToCheckForToolUpdates'); - if (legacyCfg === false) { - const cfg = gocfg.inspect('toolsManagement.checkForUpdates'); - if (cfg?.globalValue === undefined && cfg?.workspaceValue === undefined) { - return 'local'; - } - } return gocfg.get('toolsManagement.checkForUpdates') as string; } diff --git a/test/gopls/update.test.ts b/test/gopls/update.test.ts index a8ea1971..a452fd14 100644 --- a/test/gopls/update.test.ts +++ b/test/gopls/update.test.ts @@ -12,101 +12,10 @@ import { getGoConfig } from '../../src/config'; import * as lsp from '../../src/language/goLanguageServer'; import * as goInstallTools from '../../src/goInstallTools'; import { getTool, Tool } from '../../src/goTools'; -import { getCheckForToolsUpdatesConfig as getCheckForToolUpdatesConfig } from '../../src/util'; import moment = require('moment'); import semver = require('semver'); import sinon = require('sinon'); -suite('getCheckForToolUpdatesConfig tests', () => { - const CHECK_FOR_UPDATES = 'toolsManagement.checkForUpdates'; - const LEGACY_CHECK_FOR_UPDATES = 'useGoProxyToCheckForToolUpdates'; - const defaultConfigInspector = getGoConfig().inspect(CHECK_FOR_UPDATES); - - test('default is as expected', () => { - const { key, defaultValue, globalValue, workspaceValue } = defaultConfigInspector ?? {}; - assert.deepStrictEqual( - { key, defaultValue, globalValue, workspaceValue }, - { - key: `go.${CHECK_FOR_UPDATES}`, - defaultValue: 'proxy', - globalValue: undefined, - workspaceValue: undefined - }, - CHECK_FOR_UPDATES - ); - assert.strictEqual(getGoConfig().get(LEGACY_CHECK_FOR_UPDATES), true, LEGACY_CHECK_FOR_UPDATES); - }); - - // wrapper class of vscode.WorkspaceConfiguration - the object returned by - // vscode.getConfiguration is read-only, and doesn't allow property modification - // so working with sinon directly doesn't seem possible. - class TestWorkspaceConfiguration implements vscode.WorkspaceConfiguration { - constructor(private _wrapped: vscode.WorkspaceConfiguration) {} - public get(params: string) { - return this._wrapped.get(params); - } - public has(params: string) { - return this._wrapped.has(params); - } - public inspect(params: string) { - return this._wrapped.inspect(params); - } - public update( - section: string, - value: any, - configurationTarget?: vscode.ConfigurationTarget | boolean, - overrideInLanguage?: boolean - ) { - return this._wrapped.update(section, value, configurationTarget, overrideInLanguage); - } - [key: string]: any; - } - - teardown(() => { - sinon.restore(); - }); - - test('default checkForUpdates returns proxy', () => { - const gocfg = getGoConfig(); - assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy'); - }); - test('local when new config is not set and legacy config is set to false', () => { - const gocfg = new TestWorkspaceConfiguration(getGoConfig()); - sinon.stub(gocfg, 'get').withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false); - - assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'local'); - }); - test('proxy when new config is "proxy" and legacy config is set to false', () => { - const gocfg = new TestWorkspaceConfiguration(getGoConfig()); - sinon - .stub(gocfg, 'get') - .withArgs(LEGACY_CHECK_FOR_UPDATES) - .returns(false) - .withArgs(CHECK_FOR_UPDATES) - .returns('proxy'); - sinon - .stub(gocfg, 'inspect') - .withArgs(CHECK_FOR_UPDATES) - .returns(Object.assign({}, defaultConfigInspector, { globalValue: 'proxy' })); - - assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy'); - }); - test('off when new config (workspace) is "off" and legacy config is set to false', () => { - const gocfg = new TestWorkspaceConfiguration(getGoConfig()); - sinon - .stub(gocfg, 'get') - .withArgs(LEGACY_CHECK_FOR_UPDATES) - .returns(false) - .withArgs(CHECK_FOR_UPDATES) - .returns('off'); - sinon - .stub(gocfg, 'inspect') - .withArgs(CHECK_FOR_UPDATES) - .returns(Object.assign({}, defaultConfigInspector, { workspaceValue: 'off' })); - assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'off'); - }); -}); - suite('gopls okForStagedRollout', () => { const tool = getTool('gopls'); const sandbox = sinon.createSandbox(); diff --git a/test/integration/goExplorer.test.ts b/test/integration/goExplorer.test.ts index 27ce1500..48d1f753 100644 --- a/test/integration/goExplorer.test.ts +++ b/test/integration/goExplorer.test.ts @@ -10,7 +10,6 @@ import { getGoConfig, getGoplsConfig } from '../../src/config'; import { GoExplorerProvider } from '../../src/goExplorer'; import { getConfiguredTools } from '../../src/goTools'; -import { getGoVersion } from '../../src/util'; import { resolveHomeDir } from '../../src/utils/pathUtils'; import { MockExtensionContext } from '../mocks/MockContext'; @@ -51,8 +50,7 @@ suite('GoExplorerProvider', () => { }); test('tools tree items', async () => { - const goVersion = await getGoVersion(); - const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig()); + const allTools = getConfiguredTools(getGoConfig(), getGoplsConfig()); const expectTools = allTools.map((t) => t.name); const [, tools] = await explorer.getChildren()!; const items = (await explorer.getChildren(tools)) as TreeItem[]; diff --git a/test/integration/install.test.ts b/test/integration/install.test.ts index faf806b2..761c53af 100644 --- a/test/integration/install.test.ts +++ b/test/integration/install.test.ts @@ -283,37 +283,16 @@ function shouldRunSlowTests(): boolean { } suite('getConfiguredTools', () => { - test('do not require legacy tools when using language server', async () => { - const configured = getConfiguredTools( - fakeGoVersion('go version go1.15.6 linux/amd64'), - { useLanguageServer: true }, - {} - ); + test('require gopls when using language server', async () => { + const configured = getConfiguredTools({ useLanguageServer: true }, {}); const got = configured.map((tool) => tool.name) ?? []; assert(got.includes('gopls'), `omitted 'gopls': ${JSON.stringify(got)}`); - assert(!got.includes('guru') && !got.includes('gocode'), `suggested legacy tools: ${JSON.stringify(got)}`); }); test('do not require gopls when not using language server', async () => { - const configured = getConfiguredTools( - fakeGoVersion('go version go1.15.6 linux/amd64'), - { useLanguageServer: false }, - {} - ); + const configured = getConfiguredTools({ useLanguageServer: false }, {}); const got = configured.map((tool) => tool.name) ?? []; assert(!got.includes('gopls'), `suggested 'gopls': ${JSON.stringify(got)}`); - assert(got.includes('guru') && got.includes('gocode'), `omitted legacy tools: ${JSON.stringify(got)}`); - }); - - test('do not require gopls when the go version is old', async () => { - const configured = getConfiguredTools( - fakeGoVersion('go version go1.9 linux/amd64'), - { useLanguageServer: true }, - {} - ); - const got = configured.map((tool) => tool.name) ?? []; - assert(!got.includes('gopls'), `suggested 'gopls' for old go: ${JSON.stringify(got)}`); - assert(got.includes('guru') && got.includes('gocode'), `omitted legacy tools: ${JSON.stringify(got)}`); }); });