1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:24:39 -07:00

internal/lsp: update column mapper with content on incremental changes

Fixes golang/go#32114

Change-Id: If2ffade3d8d1e026e3b0aa7f2c9db4dc46d7c8b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178157
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2019-05-20 14:56:01 -04:00
parent d88f79806b
commit 9558fe4a78
4 changed files with 14 additions and 13 deletions

View File

@ -23,14 +23,13 @@ func NewURI(uri span.URI) string {
return string(uri)
}
func NewColumnMapper(uri span.URI, fn string, fset *token.FileSet, f *token.File, content []byte) *ColumnMapper {
func NewColumnMapper(uri span.URI, filename string, fset *token.FileSet, f *token.File, content []byte) *ColumnMapper {
var converter *span.TokenConverter
if f == nil {
converter = span.NewContentConverter(fn, content)
converter = span.NewContentConverter(filename, content)
} else {
converter = span.NewTokenConverter(fset, f)
}
return &ColumnMapper{
URI: uri,
Converter: converter,

View File

@ -88,10 +88,6 @@ func Diagnostics(ctx context.Context, v View, uri span.URI) (map[span.URI][]Diag
}
// Updates to the diagnostics for this package may need to be propagated.
for _, f := range gof.GetActiveReverseDeps(ctx) {
if f == nil {
v.Session().Logger().Errorf(ctx, "nil file in reverse active dependencies for %s", f.URI())
continue
}
pkg := f.GetPackage(ctx)
if pkg == nil {
continue

View File

@ -65,11 +65,16 @@ func (s *Server) applyChanges(ctx context.Context, params *protocol.DidChangeTex
uri := span.NewURI(params.TextDocument.URI)
view := s.session.ViewOf(uri)
file, m, err := getSourceFile(ctx, view, uri)
f, m, err := getSourceFile(ctx, view, uri)
if err != nil {
return "", jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "file not found")
}
content := file.GetContent(ctx)
fset := f.GetFileSet(ctx)
filename, err := f.URI().Filename()
if err != nil {
return "", jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "no filename for %s", uri)
}
content := f.GetContent(ctx)
for _, change := range params.ContentChanges {
spn, err := m.RangeSpan(*change.Range)
if err != nil {
@ -87,6 +92,9 @@ func (s *Server) applyChanges(ctx context.Context, params *protocol.DidChangeTex
buf.WriteString(change.Text)
buf.Write(content[end:])
content = buf.Bytes()
// Update column mapper along with the content.
m = protocol.NewColumnMapper(f.URI(), filename, fset, nil, content)
}
return string(content), nil
}

View File

@ -51,13 +51,11 @@ func getSourceFile(ctx context.Context, v source.View, uri span.URI) (source.Fil
if err != nil {
return nil, nil, err
}
fname, err := f.URI().Filename()
filename, err := f.URI().Filename()
if err != nil {
return nil, nil, err
}
m := protocol.NewColumnMapper(f.URI(), fname, f.GetFileSet(ctx), f.GetToken(ctx), f.GetContent(ctx))
m := protocol.NewColumnMapper(f.URI(), filename, f.GetFileSet(ctx), f.GetToken(ctx), f.GetContent(ctx))
return f, m, nil
}