Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/ls/lsconv/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,16 @@ func diagnosticToLSP(ctx context.Context, converters *Converters, diagnostic *as

var tags []lsproto.DiagnosticTag
if len(opts.tagValueSet) > 0 && (diagnostic.ReportsUnnecessary() || diagnostic.ReportsDeprecated()) {
tags = make([]lsproto.DiagnosticTag, 0, 2)
tags = make([]lsproto.DiagnosticTag, 0, 3)
if diagnostic.ReportsUnnecessary() && slices.Contains(opts.tagValueSet, lsproto.DiagnosticTagUnnecessary) {
tags = append(tags, lsproto.DiagnosticTagUnnecessary)
// Visual Studio's LSP client only renders Unnecessary diagnostics as
// faded-out text when they also carry the VS-internal HiddenInEditor
// tag; otherwise they appear as a regular squiggle. Emit it so VS
// matches the LSP-spec intent of the Unnecessary tag.
if opts.visualStudio {
tags = append(tags, lsproto.VSDiagnosticTagHiddenInEditor)
}
}
if diagnostic.ReportsDeprecated() && slices.Contains(opts.tagValueSet, lsproto.DiagnosticTagDeprecated) {
tags = append(tags, lsproto.DiagnosticTagDeprecated)
Expand Down
13 changes: 13 additions & 0 deletions internal/lsp/lsproto/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,16 @@ const (
CodeActionKindSourceRemoveUnusedImports CodeActionKind = "source.removeUnusedImports"
CodeActionKindSourceSortImports CodeActionKind = "source.sortImports"
)

const (
// VSDiagnosticTagHiddenInEditor is a Visual Studio-specific DiagnosticTag
// (see Microsoft.VisualStudio.LanguageServer.Protocol.Extensions.VSDiagnosticTags)
// indicating the diagnostic should not be rendered with a squiggle in the
// editor. When combined with DiagnosticTagUnnecessary, Visual Studio
// renders the affected code as faded-out text (the typical "unused
// variable" appearance). VS extension tags use sentinel values near
// int32.MaxValue to avoid colliding with future standard DiagnosticTag
// additions. Only emit when the client advertises
// _vs_supportsVisualStudioExtensions.
VSDiagnosticTagHiddenInEditor DiagnosticTag = 2147483641 // int32.MaxValue - 6
)