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 <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Hana (Hyang-Ah) Kim 2023-10-12 23:21:51 -04:00 коммит произвёл Hyang-Ah Hana Kim
Родитель 5c1eda7601
Коммит a3d76a5512
13 изменённых файлов: 25 добавлений и 471 удалений

Просмотреть файл

@ -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. <br/> Default: `"dlv"` |
| `go` | Alternate tool to use instead of the go binary or alternate path to use for the go binary. <br/> Default: `"go"` |
| `gopls` | Alternate tool to use instead of the gopls binary or alternate path to use for the gopls binary. <br/> 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.<br/>
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.<br/>
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.<br/>
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. <br/> 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. <br/> Default: `false` |
Default:
```
{
"delay" : 500,
"enabled" : false,
}
```
### `go.logging.level`
The logging level the extension logs at, defaults to 'error'<br/>
@ -555,24 +491,6 @@ Trace the communication between VS Code and the Go language server.<br/>
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.<br/>

Просмотреть файл

@ -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": {

Просмотреть файл

@ -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}`);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<vscode.TreeIt
}
private async toolTreeItems() {
const goVersion = await getGoVersion();
const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig());
const allTools = getConfiguredTools(getGoConfig(), getGoplsConfig());
const toolsInfo = await Promise.all(allTools.map((tool) => this.toolDetailCache.get(tool.name)));
const items = [];
for (const t of toolsInfo) {

Просмотреть файл

@ -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<Tool[]> {
const keys = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig());
function getMissingTools(): Promise<Tool[]> {
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;

Просмотреть файл

@ -94,7 +94,6 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<ExtensionA
await setGOROOTEnvVar(configGOROOT);
}
await showDeprecationWarning();
await updateGoVarsFromConfig(goCtx);
suggestUpdates();
@ -373,24 +372,3 @@ function lintDiagnosticCollectionName(lintToolName: string) {
}
return `go-${lintToolName}`;
}
async function showDeprecationWarning() {
const cfg = getGoConfig();
const disableLanguageServer = cfg['useLanguageServer'];
if (disableLanguageServer === false) {
const promptKey = 'promptedLegacyLanguageServerDeprecation';
const prompted = getFromGlobalState(promptKey, false);
if (!prompted) {
const msg =
'When [go.useLanguageServer](command:workbench.action.openSettings?%5B%22go.useLanguageServer%22%5D) is false, IntelliSense, code navigation, and refactoring features for Go will stop working. Linting, debugging and testing other than debug/test code lenses will continue to work. Please see [Issue 2799](https://go.dev/s/vscode-issue/2799).';
const selected = await vscode.window.showInformationMessage(msg, 'Open settings', "Don't show again");
switch (selected) {
case 'Open settings':
vscode.commands.executeCommand('workbench.action.openSettings', 'go.useLanguageServer');
break;
case "Don't show again":
updateGlobalState(promptKey, true);
}
}
}
}

Просмотреть файл

@ -129,16 +129,12 @@ export function isGocode(tool: Tool): boolean {
return tool.name === 'gocode' || tool.name === 'gocode-gomod';
}
export function getConfiguredTools(
goVersion: GoVersion,
goConfig: { [key: string]: any },
goplsConfig: { [key: string]: any }
): Tool[] {
export function getConfiguredTools(goConfig: { [key: string]: any }, goplsConfig: { [key: string]: any }): Tool[] {
// If language server is enabled, don't suggest tools that are replaced by gopls.
// TODO(github.com/golang/vscode-go/issues/388): decide what to do when
// the go version is no longer supported by gopls while the legacy tools are
// no longer working (or we remove the legacy language feature providers completely).
const useLanguageServer = goConfig['useLanguageServer'] && goVersion?.gt('1.11');
const useLanguageServer = goConfig['useLanguageServer'];
const tools: Tool[] = [];
function maybeAddTool(name: string) {
@ -150,20 +146,13 @@ export function getConfiguredTools(
}
}
// Add the language server if the user has chosen to do so.
if (useLanguageServer) {
maybeAddTool('gopls');
}
// Start with default tools that should always be installed.
for (const name of [
'gocode',
'go-outline',
'go-symbols',
'guru',
'gorename',
'gotests',
'gomodifytags',
'impl',
'fillstruct',
'goplay',
'godoctor'
]) {
for (const name of ['gotests', 'gomodifytags', 'impl', 'fillstruct', 'goplay']) {
maybeAddTool(name);
}
@ -174,24 +163,9 @@ export function getConfiguredTools(
maybeAddTool('dlv');
}
// gocode-gomod needed in go 1.11 & higher
if (goVersion?.gt('1.10')) {
maybeAddTool('gocode-gomod');
}
// Add the doc/def tool that was chosen by the user.
switch (goConfig['docsTool']) {
case 'godoc':
maybeAddTool('godef');
break;
default:
maybeAddTool(goConfig['docsTool']);
break;
}
// Only add format tools if the language server is disabled or the
// format tool is known to us.
if (goConfig['useLanguageServer'] === false || usingCustomFormatTool(goConfig)) {
if (!useLanguageServer || usingCustomFormatTool(goConfig)) {
maybeAddTool(getFormatTool(goConfig));
}
@ -201,13 +175,6 @@ export function getConfiguredTools(
if (goConfig['lintTool'] !== 'staticcheck' || !goplsStaticheckEnabled) {
maybeAddTool(goConfig['lintTool']);
}
// Add the language server if the user has chosen to do so.
// Even though we arranged this to run after the first attempt to start gopls
// this is still useful if we've fail to start gopls.
if (useLanguageServer) {
maybeAddTool('gopls');
}
return tools;
}
@ -216,7 +183,6 @@ export function goplsStaticcheckEnabled(
goplsConfig: { [key: string]: any }
): boolean {
if (
goConfig['useLanguageServer'] !== true ||
goplsConfig['ui.diagnostic.staticcheck'] === false ||
(goplsConfig['ui.diagnostic.staticcheck'] === undefined && goplsConfig['staticcheck'] !== true)
) {

Просмотреть файл

@ -1127,38 +1127,6 @@ export async function shouldUpdateLanguageServer(
return semver.lt(usersVersionSemver!, latestVersion!) ? latestVersion : null;
}
/**
* suggestUpdateGopls will make sure the user is using the latest version of `gopls`,
* when go.useLanguageServer is changed to true by default.
*
* @param tool Object of type `Tool` for gopls tool.
* @param cfg Object of type `Language Server Config` for the users language server
* configuration.
* @returns true if the tool was updated
*/
export async function suggestUpdateGopls(tool: Tool, cfg: LanguageServerConfig): Promise<boolean | undefined> {
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<boolean>('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<VulncheckReport> {
const { languageClient } = goCtx;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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<T>(params: string) {
return this._wrapped.get<T>(params);
}
public has(params: string) {
return this._wrapped.has(params);
}
public inspect<T>(params: string) {
return this._wrapped.inspect<T>(params);
}
public update<T>(
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();

Просмотреть файл

@ -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[];

Просмотреть файл

@ -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)}`);
});
});