1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:04:52 -07:00

internal/lsp: temporarily disable incremental changes

It is difficult to debug gopls in combination with the incremental
changes feature. Because gopls is slow (caching CL is in progress), it
seems like the incremental changes can sometimes produce strange
behavior. Disable it for now until we can prioritize work on it.

Change-Id: I931aa39756f198d1af21dca359acc83ca3392c4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165023
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-03-04 17:50:16 -05:00
parent fd53dfa087
commit ac1696789e

View File

@ -69,6 +69,8 @@ type server struct {
signatureHelpEnabled bool signatureHelpEnabled bool
snippetsSupported bool snippetsSupported bool
textDocumentSyncKind protocol.TextDocumentSyncKind
viewMu sync.Mutex viewMu sync.Mutex
view source.View view source.View
} }
@ -98,6 +100,10 @@ func (s *server) Initialize(ctx context.Context, params *protocol.InitializePara
return nil, err return nil, err
} }
// TODO(rstambler): Change this default to protocol.Incremental (or add a
// flag). Disabled for now to simplify debugging.
s.textDocumentSyncKind = protocol.Full
s.view = cache.NewView(&packages.Config{ s.view = cache.NewView(&packages.Config{
Context: ctx, Context: ctx,
Dir: rootPath, Dir: rootPath,
@ -124,7 +130,7 @@ func (s *server) Initialize(ctx context.Context, params *protocol.InitializePara
TriggerCharacters: []string{"(", ","}, TriggerCharacters: []string{"(", ","},
}, },
TextDocumentSync: protocol.TextDocumentSyncOptions{ TextDocumentSync: protocol.TextDocumentSyncOptions{
Change: float64(protocol.Incremental), Change: float64(s.textDocumentSyncKind),
OpenClose: true, OpenClose: true,
}, },
TypeDefinitionProvider: true, TypeDefinitionProvider: true,
@ -186,6 +192,7 @@ func bytesOffset(content []byte, pos protocol.Position) int {
if line == int(pos.Line) && char == int(pos.Character) { if line == int(pos.Line) && char == int(pos.Character) {
return offset return offset
} }
r, size := utf8.DecodeRune(content) r, size := utf8.DecodeRune(content)
char++ char++
// The offsets are based on a UTF-16 string representation. // The offsets are based on a UTF-16 string representation.
@ -250,10 +257,22 @@ func (s *server) DidChange(ctx context.Context, params *protocol.DidChangeTextDo
return jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "no content changes provided") return jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "no content changes provided")
} }
text, err := s.applyChanges(ctx, params) var text string
switch s.textDocumentSyncKind {
case protocol.Incremental:
var err error
text, err = s.applyChanges(ctx, params)
if err != nil { if err != nil {
return err return err
} }
case protocol.Full:
// We expect the full content of file, i.e. a single change with no range.
change := params.ContentChanges[0]
if change.RangeLength != 0 {
return jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "unexpected change range provided")
}
text = change.Text
}
s.cacheAndDiagnose(ctx, params.TextDocument.URI, text) s.cacheAndDiagnose(ctx, params.TextDocument.URI, text)
return nil return nil
} }