Skip to content

Commit ea221fb

Browse files
committed
[release] src/goLanguageServer: partial revert of cl/280601
This partially reverts commit 4c91c38. In https://go-review.googlesource.com/c/vscode-go/+/280601, we tried to remove the languageServerExperimentalFeatures setting because gopls's diagnostics feature is no longer in its experimental state and that was the only flag left in this setting. However, we learned some users depend on this flag because the extension turns off buildOnSave and vetOnSave features when gopls's diagnostics is used and they need to run custom vet analyzers. This is not ideal and the extension shouldn't prevent users from running their custom analyzers. That needs more investigation and experiment. For now, we rollback the change, but place the deprecation notice. Update #50 Fixes #1110 Change-Id: I376692b152d3011aaa8da7a1b5121ba33e2188b6 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/285253 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]> (cherry picked from commit fbd2fc4) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/285256
1 parent 392e7d7 commit ea221fb

File tree

6 files changed

+67
-12
lines changed

6 files changed

+67
-12
lines changed

docs/settings.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Flags to `go build`/`go test` used during build-on-save or running tests. (e.g.
7676

7777
### `go.buildOnSave`
7878

79-
Compiles code on file save using 'go build -i' or 'go test -c -i'. Options are 'workspace', 'package', or 'off'.
79+
Compiles code on file save using 'go build' or 'go test -c'. Options are 'workspace', 'package', or 'off'. Not applicable when using the language server's diagnostics is used. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
8080

8181
Allowed Values:`[package workspace off]`
8282

@@ -324,6 +324,21 @@ If true, then `-i` flag will be passed to `go build` everytime the code is compi
324324

325325
Default: `false`
326326

327+
### `go.languageServerExperimentalFeatures`
328+
329+
Temporary flag to enable/disable diagnostics from the language server. This setting will be deprecated soon. Please see and response to [Issue 50](https://github.com/golang/vscode-go/issues/50).
330+
331+
| Properties | Description |
332+
| --- | --- |
333+
| `diagnostics` | If true, the language server will provide build, vet errors and the extension will ignore the `buildOnSave`, `vetOnSave` settings. |
334+
| | |
335+
336+
337+
Default:{<br/>
338+
&nbsp;&nbsp;`"diagnostics": true`,<br/>
339+
}
340+
341+
327342
### `go.languageServerFlags`
328343

329344
Flags like -rpc.trace and -logfile to be used while running the language server.
@@ -515,7 +530,7 @@ Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"])
515530

516531
### `go.vetOnSave`
517532

518-
Vets code on file save using 'go tool vet'. Not applicable when using the language server.
533+
Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics is used. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
519534

520535
Allowed Values:`[package workspace off]`
521536

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@
865865
"off"
866866
],
867867
"default": "package",
868-
"description": "Compiles code on file save using 'go build -i' or 'go test -c -i'. Options are 'workspace', 'package', or 'off'.",
868+
"description": "Compiles code on file save using 'go build' or 'go test -c'. Options are 'workspace', 'package', or 'off'. Not applicable when using the language server's diagnostics is used. See 'go.languageServerExperimentalFeatures.diagnostics' setting.",
869869
"scope": "resource"
870870
},
871871
"go.buildFlags": {
@@ -939,7 +939,7 @@
939939
"off"
940940
],
941941
"default": "package",
942-
"description": "Vets code on file save using 'go tool vet'. Not applicable when using the language server.",
942+
"description": "Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics is used. See 'go.languageServerExperimentalFeatures.diagnostics' setting.",
943943
"scope": "resource"
944944
},
945945
"go.vetFlags": {
@@ -1253,6 +1253,21 @@
12531253
"default": [],
12541254
"description": "Flags like -rpc.trace and -logfile to be used while running the language server."
12551255
},
1256+
"go.languageServerExperimentalFeatures": {
1257+
"type": "object",
1258+
"properties": {
1259+
"diagnostics": {
1260+
"type": "boolean",
1261+
"default": true,
1262+
"description": "If true, the language server will provide build, vet errors and the extension will ignore the `buildOnSave`, `vetOnSave` settings."
1263+
}
1264+
},
1265+
"additionalProperties": false,
1266+
"default": {
1267+
"diagnostics": true
1268+
},
1269+
"markdownDescription": "Temporary flag to enable/disable diagnostics from the language server. This setting will be deprecated soon. Please see and response to [Issue 50](https://github.com/golang/vscode-go/issues/50)."
1270+
},
12561271
"go.trace.server": {
12571272
"type": "string",
12581273
"enum": [

src/goCheck.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function check(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurati
6060
// If a user has enabled diagnostics via a language server,
6161
// then we disable running build or vet to avoid duplicate errors and warnings.
6262
const lspConfig = buildLanguageServerConfig(goConfig);
63-
const disableBuildAndVet = lspConfig.enabled;
63+
const disableBuildAndVet = lspConfig.enabled && lspConfig.features.diagnostics;
6464

6565
let testPromise: Thenable<boolean>;
6666
const testConfig: TestConfig = {

src/goLanguageServer.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
Message,
2828
ProvideCodeLensesSignature,
2929
ProvideCompletionItemsSignature,
30+
ProvideDocumentLinksSignature,
3031
ResponseError,
3132
RevealOutputChannelOn
3233
} from 'vscode-languageclient';
@@ -74,6 +75,9 @@ export interface LanguageServerConfig {
7475
enabled: boolean;
7576
flags: string[];
7677
env: any;
78+
features: {
79+
diagnostics: boolean;
80+
};
7781
checkForUpdates: string;
7882
}
7983

@@ -105,6 +109,7 @@ let lastUserAction: Date = new Date();
105109
// startLanguageServerWithFallback starts the language server, if enabled,
106110
// or falls back to the default language providers.
107111
export async function startLanguageServerWithFallback(ctx: vscode.ExtensionContext, activation: boolean) {
112+
108113
for (const folder of vscode.workspace.workspaceFolders || []) {
109114
if (folder.uri.scheme === 'vsls') {
110115
outputChannel.appendLine(`Language service on the guest side is disabled. ` +
@@ -400,10 +405,14 @@ export async function buildLanguageClient(cfg: BuildLanguageClientOption): Promi
400405
diagnostics: vscode.Diagnostic[],
401406
next: HandleDiagnosticsSignature
402407
) => {
408+
if (!cfg.features.diagnostics) {
409+
return null;
410+
}
403411
// Deduplicate diagnostics with those found by the other tools.
404412
removeDuplicateDiagnostics(vetDiagnosticCollection, uri, diagnostics);
405413
removeDuplicateDiagnostics(buildDiagnosticCollection, uri, diagnostics);
406414
removeDuplicateDiagnostics(lintDiagnosticCollection, uri, diagnostics);
415+
407416
return next(uri, diagnostics);
408417
},
409418
provideCompletionItem: async (
@@ -716,6 +725,11 @@ export function buildLanguageServerConfig(goConfig: vscode.WorkspaceConfiguratio
716725
modtime: null,
717726
enabled: goConfig['useLanguageServer'] === true,
718727
flags: goConfig['languageServerFlags'] || [],
728+
features: {
729+
// TODO: We should have configs that match these names.
730+
// Ultimately, we should have a centralized language server config rather than separate fields.
731+
diagnostics: goConfig['languageServerExperimentalFeatures']['diagnostics'],
732+
},
719733
env: toolExecutionEnvironment(),
720734
checkForUpdates: getCheckForToolsUpdatesConfig(goConfig),
721735
};

src/goMain.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,27 @@ export async function activate(ctx: vscode.ExtensionContext) {
126126
// Present a warning about the deprecation of the go.documentLink setting.
127127
const experimentalFeatures = getGoConfig()['languageServerExperimentalFeatures'];
128128
if (experimentalFeatures) {
129-
// TODO(rstambler): Eventually notify about deprecation of all of the settings.
129+
// TODO(golang/vscode-go#50): Eventually notify about deprecation of
130+
// all of the settings. See golang/vscode-go#1109 too.
131+
// The `diagnostics` setting is still used as a workaround for running custom vet.
130132
if (experimentalFeatures['documentLink'] === false) {
131133
vscode.window.showErrorMessage(`The 'go.languageServerExperimentalFeature.documentLink' setting is now deprecated.
132-
Please use 'gopls.importShortcut' instead.
133-
See https://github.com/golang/tools/blob/master/gopls/doc/settings.md#importshortcut-enum for more details.`);
134+
Please use 'gopls.importShortcut' instead.
135+
See https://github.com/golang/tools/blob/master/gopls/doc/settings.md#importshortcut-enum for more details.`);
134136
}
135-
if (experimentalFeatures['diagnostics'] === false) {
136-
vscode.window.showErrorMessage(`The 'go.languageServerExperimentalFeature.diagnostics' setting is now deprecated.
137+
const promptKey = 'promptedLanguageServerExperimentalFeatureDeprecation';
138+
const prompted = getFromGlobalState(promptKey, false);
139+
if (!prompted && experimentalFeatures['diagnostics'] === false) {
140+
const msg = `The 'go.languageServerExperimentalFeature.diagnostics' setting will be deprecated soon.
137141
If you would like additional configuration for diagnostics from gopls, please see and response to
138-
https://github.com/golang/vscode-go/issues/50.`);
142+
https://github.com/golang/vscode-go/issues/50.`;
143+
const selected = await vscode.window.showInformationMessage(msg, `Don't show again`);
144+
switch (selected) {
145+
case `Don't show again`:
146+
updateGlobalState(promptKey, true);
147+
}
139148
}
140149
}
141-
142150
updateGoVarsFromConfig().then(async () => {
143151
suggestUpdates(ctx);
144152
offerToInstallLatestGoVersion();

test/gopls/update.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ suite('gopls update tests', () => {
175175
version: '',
176176
checkForUpdates: 'proxy',
177177
env: {},
178+
features: {
179+
diagnostics: true,
180+
},
178181
flags: [],
179182
modtime: new Date(),
180183
serverName: 'gopls',

0 commit comments

Comments
 (0)