Skip to content

Commit 4b24e75

Browse files
committed
package.json: add go.toolsManagement.checkForUpdates
This deprecates go.useGoProxyToCheckForToolUpdates. And, add go.toolsManagement.checkForUpdates off mode that avoids version check entirely. We will start actively prompting users of this change from the next release. We don't do that right now to avoid prompt until dev containers update their settings and get released. Updates #963 Change-Id: Id49103b37e2e6e19f0313792d7d3e72648e84ce5 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/278353 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 63b4bd1 commit 4b24e75

File tree

6 files changed

+121
-9
lines changed

6 files changed

+121
-9
lines changed

docs/settings.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ Location to install the Go tools that the extension depends on if you don't want
372372

373373
Default: ``
374374

375+
### `go.toolsManagement.checkForUpdates`
376+
377+
Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on
378+
379+
Allowed Values:`[proxy local off]`
380+
381+
Default: `proxy`
382+
375383
### `go.trace.server`
376384

377385
Trace the communication between VS Code and the Go language server.
@@ -392,8 +400,9 @@ Complete functions with their parameter signature, excluding the variable types.
392400

393401
Default: `false`
394402

395-
### `go.useGoProxyToCheckForToolUpdates`
403+
### `go.useGoProxyToCheckForToolUpdates (deprecated)`
396404

405+
Use `go.toolsManagement.checkForUpdates` instead.
397406
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
398407

399408
Default: `true`

package.json

+17-1
Original file line numberDiff line numberDiff line change
@@ -1641,10 +1641,26 @@
16411641
"description": "The logging level the extension logs at, defaults to 'error'",
16421642
"scope": "machine-overridable"
16431643
},
1644+
"go.toolsManagement.checkForUpdates": {
1645+
"type": "string",
1646+
"default": "proxy",
1647+
"enum": [
1648+
"proxy",
1649+
"local",
1650+
"off"
1651+
],
1652+
"enumDescriptions": [
1653+
"keeps notified of new releases by checking the Go module proxy (GOPROXY)",
1654+
"checks only the minimum tools versions required by the extension",
1655+
"completely disables version check (not recommended)"
1656+
],
1657+
"markdownDescription": "Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on"
1658+
},
16441659
"go.useGoProxyToCheckForToolUpdates": {
16451660
"type": "boolean",
16461661
"default": true,
1647-
"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"
1662+
"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",
1663+
"markdownDeprecationMessage": "Use `go.toolsManagement.checkForUpdates` instead."
16481664
},
16491665
"go.gotoSymbol.includeImports": {
16501666
"type": "boolean",

src/goEnvironmentStatus.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { toolInstallationEnvironment } from './goEnv';
1717
import { logVerbose } from './goLogging';
1818
import { addGoStatus, goEnvStatusbarItem, outputChannel, removeGoStatus } from './goStatus';
1919
import { getFromGlobalState, getFromWorkspaceState, updateGlobalState, updateWorkspaceState } from './stateUtils';
20-
import { getBinPath, getGoConfig, getGoVersion, getTempFilePath, GoVersion, rmdirRecursive } from './util';
20+
import {
21+
getBinPath, getCheckForToolsUpdatesConfig, getGoConfig, getGoVersion,
22+
getTempFilePath, GoVersion, rmdirRecursive } from './util';
2123
import {
2224
correctBinname,
2325
executableFileExists,
@@ -517,7 +519,8 @@ const dismissedGoVersionUpdatesKey = 'dismissedGoVersionUpdates';
517519

518520
export async function offerToInstallLatestGoVersion() {
519521
const goConfig = getGoConfig();
520-
if (!goConfig['useGoProxyToCheckForToolUpdates']) {
522+
const checkForUpdate = getCheckForToolsUpdatesConfig(goConfig);
523+
if (checkForUpdate === 'off' || checkForUpdate === 'local') { // 'proxy' or misconfiguration..
521524
return;
522525
}
523526

src/goLanguageServer.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { GoTypeDefinitionProvider } from './goTypeDefinition';
5757
import { getFromGlobalState, updateGlobalState } from './stateUtils';
5858
import {
5959
getBinPath,
60+
getCheckForToolsUpdatesConfig,
6061
getCurrentGoPath,
6162
getGoConfig,
6263
getGoplsConfig,
@@ -77,7 +78,7 @@ export interface LanguageServerConfig {
7778
diagnostics: boolean;
7879
documentLink: boolean;
7980
};
80-
checkForUpdates: boolean;
81+
checkForUpdates: string;
8182
}
8283

8384
// Global variables used for management of the language client.
@@ -698,7 +699,7 @@ export function buildLanguageServerConfig(goConfig: vscode.WorkspaceConfiguratio
698699
documentLink: goConfig['languageServerExperimentalFeatures']['documentLink']
699700
},
700701
env: toolExecutionEnvironment(),
701-
checkForUpdates: goConfig['useGoProxyToCheckForToolUpdates']
702+
checkForUpdates: getCheckForToolsUpdatesConfig(goConfig),
702703
};
703704
// Don't look for the path if the server is not enabled.
704705
if (!cfg.enabled) {
@@ -785,7 +786,7 @@ export async function shouldUpdateLanguageServer(
785786
cfg: LanguageServerConfig,
786787
): Promise<semver.SemVer> {
787788
// Only support updating gopls for now.
788-
if (tool.name !== 'gopls') {
789+
if (tool.name !== 'gopls' || cfg.checkForUpdates === 'off') {
789790
return null;
790791
}
791792

@@ -800,7 +801,7 @@ export async function shouldUpdateLanguageServer(
800801
}
801802

802803
// Get the latest gopls version. If it is for nightly, using the prereleased version is ok.
803-
let latestVersion = cfg.checkForUpdates ? await getLatestGoplsVersion(tool) : tool.latestVersion;
804+
let latestVersion = cfg.checkForUpdates === 'local' ? tool.latestVersion : await getLatestGoplsVersion(tool);
804805

805806
// If we failed to get the gopls version, pick the one we know to be latest at the time of this extension's last update
806807
if (!latestVersion) {

src/util.ts

+16
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ export function getGoplsConfig() {
166166
return getConfig('gopls');
167167
}
168168

169+
// getCheckForToolsUpdatesConfig returns go.toolsManagement.checkForUpdates configuration.
170+
export function getCheckForToolsUpdatesConfig(gocfg: vscode.WorkspaceConfiguration) {
171+
// useGoProxyToCheckForToolUpdates deprecation
172+
// TODO: Step 1. mark as deprecated in Dec 2020 release, and update dev containers.
173+
// Step 2. prompt users to switch config. Jan 2020
174+
// Step 3. delete useGoProxyToCheckForToolUpdates support. Feb 2020
175+
const legacyCfg = gocfg.get('useGoProxyToCheckForToolUpdates');
176+
if (legacyCfg === false) {
177+
const cfg = gocfg.inspect('toolsManagement.checkForUpdates');
178+
if (cfg.globalValue === undefined && cfg.workspaceValue === undefined) {
179+
return 'local';
180+
}
181+
}
182+
return gocfg.get('toolsManagement.checkForUpdates') as string;
183+
}
184+
169185
function getConfig(section: string, uri?: vscode.Uri) {
170186
if (!uri) {
171187
if (vscode.window.activeTextEditor) {

test/gopls/update.test.ts

+68-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,78 @@
44
*--------------------------------------------------------*/
55

66
import * as assert from 'assert';
7+
import { defaultCipherList } from 'constants';
78
import moment = require('moment');
89
import semver = require('semver');
910
import sinon = require('sinon');
11+
import * as vscode from 'vscode';
1012
import * as lsp from '../../src/goLanguageServer';
1113
import { getTool, Tool } from '../../src/goTools';
14+
import { getCheckForToolsUpdatesConfig as getCheckForToolUpdatesConfig, getGoConfig } from '../../src/util';
15+
16+
suite('getCheckForToolUpdatesConfig tests', () => {
17+
const CHECK_FOR_UPDATES = 'toolsManagement.checkForUpdates';
18+
const LEGACY_CHECK_FOR_UPDATES = 'useGoProxyToCheckForToolUpdates';
19+
const defaultConfigInspector = getGoConfig().inspect(CHECK_FOR_UPDATES);
20+
21+
test('default is as expected', () => {
22+
const {key, defaultValue, globalValue, workspaceValue} = defaultConfigInspector;
23+
assert.deepStrictEqual(
24+
{ key, defaultValue, globalValue, workspaceValue },
25+
{ key: `go.${CHECK_FOR_UPDATES}`, defaultValue : 'proxy', globalValue: undefined, workspaceValue: undefined},
26+
CHECK_FOR_UPDATES);
27+
assert.strictEqual(getGoConfig().get(LEGACY_CHECK_FOR_UPDATES), true, LEGACY_CHECK_FOR_UPDATES);
28+
});
29+
30+
// wrapper class of vscode.WorkspaceConfiguration - the object returned by
31+
// vscode.getConfiguration is read-only, and doesn't allow property modification
32+
// so working with sinon directly doesn't seem possible.
33+
class TestWorkspaceConfiguration implements vscode.WorkspaceConfiguration {
34+
constructor(private _wrapped: vscode.WorkspaceConfiguration) {}
35+
public get<T>(params: string) { return this._wrapped.get<T>(params); }
36+
public has(params: string) { return this._wrapped.has(params); }
37+
public inspect<T>(params: string) { return this._wrapped.inspect<T>(params); }
38+
public update<T>(
39+
section: string, value: any,
40+
configurationTarget?: vscode.ConfigurationTarget | boolean, overrideInLanguage?: boolean) {
41+
return this._wrapped.update(section, value, configurationTarget, overrideInLanguage);
42+
}
43+
[key: string]: any;
44+
}
45+
46+
teardown(() => { sinon.restore(); });
47+
48+
test('default checkForUpdates returns proxy', () => {
49+
const gocfg = getGoConfig();
50+
assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy');
51+
});
52+
test('local when new config is not set and legacy config is set to false', () => {
53+
const gocfg = new TestWorkspaceConfiguration(getGoConfig());
54+
sinon.stub(gocfg, 'get')
55+
.withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false);
56+
57+
assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'local');
58+
});
59+
test('proxy when new config is "proxy" and legacy config is set to false', () => {
60+
const gocfg = new TestWorkspaceConfiguration(getGoConfig());
61+
sinon.stub(gocfg, 'get')
62+
.withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false)
63+
.withArgs(CHECK_FOR_UPDATES).returns('proxy');
64+
sinon.stub(gocfg, 'inspect').withArgs(CHECK_FOR_UPDATES).returns(
65+
Object.assign({}, defaultConfigInspector, { globalValue: 'proxy' }));
66+
67+
assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy');
68+
});
69+
test('off when new config (workspace) is "off" and legacy config is set to false', () => {
70+
const gocfg = new TestWorkspaceConfiguration(getGoConfig());
71+
sinon.stub(gocfg, 'get')
72+
.withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false)
73+
.withArgs(CHECK_FOR_UPDATES).returns('off');
74+
sinon.stub(gocfg, 'inspect').withArgs(CHECK_FOR_UPDATES).returns(
75+
Object.assign({}, defaultConfigInspector, { workspaceValue: 'off' }));
76+
assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'off');
77+
});
78+
});
1279

1380
suite('gopls update tests', () => {
1481
test('prompt for update', async () => {
@@ -105,7 +172,7 @@ suite('gopls update tests', () => {
105172
enabled: true,
106173
path: 'bad/path/to/gopls',
107174
version: '',
108-
checkForUpdates: true,
175+
checkForUpdates: 'proxy',
109176
env: {},
110177
features: {
111178
diagnostics: true,

0 commit comments

Comments
 (0)