internal/lsp: return spanForRange function to fix build

This function was removed in CL 202298, but used in CL 200597.
Analysis diagnostics should be converted to the source.Error type in the
analysis runner as a complete fix, but this is fine for now.

Change-Id: Ie5f3f566719073d7df6ab4646f855c9f9ce22ad7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202539
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2019-10-21 15:10:19 -04:00
parent ce0314c87e
commit a0af95a55c

View File

@ -5,6 +5,7 @@
package source
import (
"bytes"
"context"
"fmt"
@ -274,6 +275,35 @@ func relatedInformation(ctx context.Context, view View, diag *analysis.Diagnosti
return out, nil
}
// spanToRange converts a span.Span to a protocol.Range,
// assuming that the span belongs to the package whose diagnostics are being computed.
func spanToRange(ctx context.Context, view View, pkg Package, spn span.Span, isTypeError bool) (protocol.Range, error) {
ph, err := pkg.File(spn.URI())
if err != nil {
return protocol.Range{}, err
}
_, m, _, err := ph.Cached(ctx)
if err != nil {
return protocol.Range{}, err
}
data, _, err := ph.File().Read(ctx)
if err != nil {
return protocol.Range{}, err
}
// Try to get a range for the diagnostic.
// TODO: Don't just limit ranges to type errors.
if spn.IsPoint() && isTypeError {
if s, err := spn.WithOffset(m.Converter); err == nil {
start := s.Start()
offset := start.Offset()
if width := bytes.IndexAny(data[offset:], " \n,():;[]"); width > 0 {
spn = span.New(spn.URI(), start, span.NewPoint(start.Line(), start.Column()+width, offset+width))
}
}
}
return m.Range(spn)
}
func clearReports(v View, reports map[span.URI][]Diagnostic, uri span.URI) {
if v.Ignore(uri) {
return