From 37a81b68a061ab2fad895d022a5a665d87c44e40 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Thu, 30 Jun 2022 17:09:03 -0400 Subject: [PATCH] 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 --- internal/lsp/cache/errors.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go index a1aecb35c7..80ae5451c8 100644 --- a/internal/lsp/cache/errors.go +++ b/internal/lsp/cache/errors.go @@ -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)