From cefbc64fbd4787e413d613910bab4406f4d58d0b Mon Sep 17 00:00:00 2001 From: Peter Weinberger Date: Wed, 20 Nov 2019 08:53:37 -0500 Subject: [PATCH] internal/lsp: make Range a pointer in Change events Change 207598 overenthusiastically (and incorrectly) changed the Range field in a TextDocumentContentChangeEvent from type *Range to type Range, which created a bug in text_synchronization.go. This CL attempts to repair the damage. Change-Id: I19e7418cd5ebaedf5448adfcc60ca86e71eb9b2f Reviewed-on: https://go-review.googlesource.com/c/tools/+/208097 Run-TryBot: Peter Weinberger TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/protocol/tsprotocol.go | 2 +- internal/lsp/text_synchronization.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/lsp/protocol/tsprotocol.go b/internal/lsp/protocol/tsprotocol.go index 1008a7f720..5657378cb8 100644 --- a/internal/lsp/protocol/tsprotocol.go +++ b/internal/lsp/protocol/tsprotocol.go @@ -2871,7 +2871,7 @@ type TextDocumentContentChangeEvent struct { /** * The range of the document that changed. */ - Range Range `json:"range,omitempty"` + Range *Range `json:"range,omitempty"` /** * The length of the range that got replaced. */ diff --git a/internal/lsp/text_synchronization.go b/internal/lsp/text_synchronization.go index 0a31b78e64..57e8b008cb 100644 --- a/internal/lsp/text_synchronization.go +++ b/internal/lsp/text_synchronization.go @@ -97,7 +97,7 @@ func fullChange(changes []protocol.TextDocumentContentChangeEvent) (string, bool } // The length of the changes must be 1 at this point. // TODO: This breaks if you insert a character at the beginning of the file. - if (changes[0].Range == protocol.Range{} && changes[0].RangeLength == 0) { + if changes[0].Range == nil && changes[0].RangeLength == 0 { return changes[0].Text, true } @@ -118,7 +118,7 @@ func (s *Server) applyChanges(ctx context.Context, uri span.URI, changes []proto Content: content, } - spn, err := m.RangeSpan(change.Range) + spn, err := m.RangeSpan(*change.Range) // Could Range be nil here? if err != nil { return "", err }