1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:14:40 -07:00
go/internal/lsp/diagnostics.go
Rebecca Stambler 7f27c5d70a internal/lsp: move diagnostics logic to source directory
Change-Id: I6bea7a76501e852bbf381eb5dbc79217e1ad10ac
Reviewed-on: https://go-review.googlesource.com/c/148889
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-12 22:54:56 +00:00

39 lines
1.1 KiB
Go

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lsp
import (
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
)
func toProtocolDiagnostics(v *source.View, diagnostics []source.Diagnostic) []protocol.Diagnostic {
reports := []protocol.Diagnostic{}
for _, diag := range diagnostics {
tok := v.Config.Fset.File(diag.Range.Start)
reports = append(reports, protocol.Diagnostic{
Message: diag.Message,
Range: toProtocolRange(tok, diag.Range),
Severity: toProtocolSeverity(diag.Severity),
Source: "LSP",
})
}
return reports
}
func toProtocolSeverity(severity source.DiagnosticSeverity) protocol.DiagnosticSeverity {
switch severity {
case source.SeverityError:
return protocol.SeverityError
case source.SeverityWarning:
return protocol.SeverityWarning
case source.SeverityHint:
return protocol.SeverityHint
case source.SeverityInformation:
return protocol.SeverityInformation
}
return protocol.SeverityError // default
}