Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls: deduplicate diagnostics from gopls / linters #142

Closed
ramya-rao-a opened this issue Jun 1, 2020 · 9 comments
Closed

gopls: deduplicate diagnostics from gopls / linters #142

ramya-rao-a opened this issue Jun 1, 2020 · 9 comments
Assignees
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@ramya-rao-a
Copy link
Contributor

Below is an example where we have the same diagnostic being presented by both the language server and the linter

image

When LSP was not in the picture, such duplicates were removed in https://github.com/microsoft/vscode-go/blob/0.10.2/src/util.ts#L747 and https://github.com/microsoft/vscode-go/blob/0.10.2/src/util.ts#L756

We might have to do something similar to remove duplicates between LSP and the linting tool.

This issue is created from microsoft/vscode-go#2517 by @lggomez

@ramya-rao-a ramya-rao-a changed the title De-duplicate diagnostics from gopls and linters De-duplicate errors from gopls and linters Jun 1, 2020
@stamblerre stamblerre changed the title De-duplicate errors from gopls and linters gopls: deduplicate diagnostics from gopls / linters Jun 2, 2020
@stamblerre
Copy link
Contributor

My preference here would be that we leave this behavior as-is. golint will likely be deprecated soon (golang/go#38968) and staticcheck is already part of gopls, which leaves golangci-lint and revive.

The error shown in the image here is a build error, so I would hope that these linters don't return such errors. If there are duplicate errors, I'm not sure that it is worth deduping them.

@stamblerre stamblerre added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 3, 2020
@dominikh
Copy link
Member

dominikh commented Jun 3, 2020

The error shown in the image here is a build error, so I would hope that these linters don't return such errors. If there are duplicate errors, I'm not sure that it is worth deduping them.

Linters do return build errors if being run on code with build errors.

@stamblerre
Copy link
Contributor

Hm ok, I didn't realize. Then maybe this issue is specific to golint, and if that's deprecated we can deprecate it as a lintOnSave option.

@ramya-rao-a
Copy link
Contributor Author

You can try changing the go.lintTool to other tools and see what the behavior then is

@ramya-rao-a
Copy link
Contributor Author

But it has happened that go vet and a linter would provide the same diagnostics. If gopls does vetting, then the case of duplication would still be valid and also the need for de-duplicaton

@stamblerre
Copy link
Contributor

Sure. Adding a bit of deduplication will not be difficult, as long as the error range and message are exactly the same.

@hyangah hyangah added this to the Gopls by default milestone Sep 3, 2020
@hyangah
Copy link
Contributor

hyangah commented Oct 15, 2020

The existing deduplication code for go vet/lint/build errors:

vscode-go/src/util.ts

Lines 908 to 932 in cf03db6

diagnosticMap.forEach((newDiagnostics, file) => {
const fileUri = vscode.Uri.parse(file);
if (diagnosticCollection === buildDiagnosticCollection) {
// If there are lint/vet warnings on current file, remove the ones co-inciding with the new build errors
if (lintDiagnosticCollection && lintDiagnosticCollection.has(fileUri)) {
lintDiagnosticCollection.set(
fileUri,
deDupeDiagnostics(newDiagnostics, lintDiagnosticCollection.get(fileUri).slice())
);
}
if (vetDiagnosticCollection && vetDiagnosticCollection.has(fileUri)) {
vetDiagnosticCollection.set(
fileUri,
deDupeDiagnostics(newDiagnostics, vetDiagnosticCollection.get(fileUri).slice())
);
}
} else if (buildDiagnosticCollection && buildDiagnosticCollection.has(fileUri)) {
// If there are build errors on current file, ignore the new lint/vet warnings co-inciding with them
newDiagnostics = deDupeDiagnostics(buildDiagnosticCollection.get(fileUri).slice(), newDiagnostics);
}
diagnosticCollection.set(fileUri, newDiagnostics);
});
}

BuildOnSave also provides diagnostics so will create duplicates.

We can intercept the diagnostics from Language Server using handleDiagnostics middleware. (e.g. https://go-review.googlesource.com/c/vscode-go/+/222338/1/src/goLanguageServer.ts)

cc @suzmue

@hyangah hyangah modified the milestones: Gopls by default, v0.20.0 Nov 20, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/279212 mentions this issue: src/goLint: switch the default lint tool to staticcheck

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/282557 mentions this issue: src/goLanguageServer.ts: deduplicate diagnostics from language client

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants