diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index e9286134699..85205895db7 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -51,15 +51,22 @@ func toProtocolDiagnostics(ctx context.Context, v source.View, diagnostics []sou reports := []protocol.Diagnostic{} for _, diag := range diagnostics { tok := v.FileSet().File(diag.Start) - source := diag.Source - if source == "" { - source = "LSP" + src := diag.Source + if src == "" { + src = "LSP" + } + var severity protocol.DiagnosticSeverity + switch diag.Severity { + case source.SeverityError: + severity = protocol.SeverityError + case source.SeverityWarning: + severity = protocol.SeverityWarning } reports = append(reports, protocol.Diagnostic{ Message: diag.Message, Range: toProtocolRange(tok, diag.Range), - Severity: protocol.SeverityError, // all diagnostics have error severity for now - Source: source, + Severity: severity, + Source: src, }) } return reports diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index eea102f666f..d0fa18b880b 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -182,9 +182,13 @@ func (d diagnostics) collect(fset *token.FileSet, rng packagestest.Range, msgSou if msg == "" { return } + severity := protocol.SeverityError + if strings.Contains(f.Name(), "analyzer") { + severity = protocol.SeverityWarning + } want := protocol.Diagnostic{ Range: toProtocolRange(f, source.Range(rng)), - Severity: protocol.SeverityError, + Severity: severity, Source: msgSource, Message: msg, } diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index 99a8fd9fd5e..395a248fb88 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -41,10 +41,18 @@ import ( type Diagnostic struct { Range - Message string - Source string + Message string + Source string + Severity DiagnosticSeverity } +type DiagnosticSeverity int + +const ( + SeverityWarning DiagnosticSeverity = iota + SeverityError +) + func Diagnostics(ctx context.Context, v View, uri URI) (map[string][]Diagnostic, error) { f, err := v.GetFile(ctx, uri) if err != nil { @@ -98,7 +106,8 @@ func Diagnostics(ctx context.Context, v View, uri URI) (map[string][]Diagnostic, Start: startPos, End: endPos, }, - Message: diag.Msg, + Message: diag.Msg, + Severity: SeverityError, } if _, ok := reports[pos.Filename]; ok { reports[pos.Filename] = append(reports[pos.Filename], diagnostic) @@ -116,9 +125,10 @@ func Diagnostics(ctx context.Context, v View, uri URI) (map[string][]Diagnostic, } reports[pos.Filename] = append(reports[pos.Filename], Diagnostic{ - Source: category, - Range: Range{Start: diag.Pos, End: diag.Pos}, - Message: fmt.Sprintf(diag.Message), + Source: category, + Range: Range{Start: diag.Pos, End: diag.Pos}, + Message: fmt.Sprintf(diag.Message), + Severity: SeverityWarning, }) })