internal/lsp: add unnecessary tags for unused vars and imports

Diagnostic Tags add another hint for the client for how to
display diagnostics. The Unnecessary tags allows clients to
fade out the diagnostic instead of adding a squiggle. This adds
this tag to unused import errors as well as unused vars.

For golang/vscode-go#2285

Change-Id: I0c93b28a6a2ef4eed314dcf30a37c27dd65940ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/415499
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Suzy Mueller 2022-06-30 17:09:03 -04:00
parent 3807419523
commit 37a81b68a0
1 changed files with 4 additions and 0 deletions

View File

@ -123,6 +123,10 @@ func typeErrorDiagnostics(snapshot *snapshot, pkg *pkg, e extendedError) ([]*sou
diag.Code = code.String()
diag.CodeHref = typesCodeHref(snapshot, code)
}
switch code {
case typesinternal.UnusedVar, typesinternal.UnusedImport:
diag.Tags = append(diag.Tags, protocol.Unnecessary)
}
for _, secondary := range e.secondaries {
_, secondarySpan, err := typeErrorData(snapshot.FileSet(), pkg, secondary)