1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

internal/lsp: set severity levels for compiler errors and vet checks

This change adds severity levels to source.Diagnostics, allowing us to
pass this information along to the LSP. This allows compiler errors to
show up in red, while vet results show up in green.

Change-Id: I2bc0b27ed6629f987c05affe00fdbe4b9bfb3b3e
Reviewed-on: https://go-review.googlesource.com/c/164299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-02-27 18:08:04 -05:00
parent 8dcc6e70cd
commit f0a709d59f
3 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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,
}

View File

@ -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,
})
})