Skip to content

Commit

Permalink
internal/lsp: fix incorrect line and start of semantic tokens
Browse files Browse the repository at this point in the history
Current implementation returns incorrect result when some of the items are skipped, because positions could be relative to a skipped item. Instead, each position must be relative to the previous item added to the result.

Change-Id: I3c1a68d37bf0c9cfc1bccfe6f76c25b536224293
GitHub-Last-Rev: 6eedc7c
GitHub-Pull-Request: #376
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396715
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Trust: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hiroebe authored and pjweinbgo committed Mar 31, 2022
1 parent 41787c4 commit cda13e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/lsp/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,19 +829,20 @@ func (e *encoded) Data() []uint32 {
// (see Integer Encoding for Tokens in the LSP spec)
x := make([]uint32, 5*len(e.items))
var j int
var last semItem
for i := 0; i < len(e.items); i++ {
typ, ok := typeMap[e.items[i].typeStr]
if !ok {
continue // client doesn't want typeStr
}
if i == 0 {
if j == 0 {
x[0] = e.items[0].line
} else {
x[j] = e.items[i].line - e.items[i-1].line
x[j] = e.items[i].line - last.line
}
x[j+1] = e.items[i].start
if i > 0 && e.items[i].line == e.items[i-1].line {
x[j+1] = e.items[i].start - e.items[i-1].start
if j > 0 && x[j] == 0 {
x[j+1] = e.items[i].start - last.start
}
x[j+2] = e.items[i].len
x[j+3] = uint32(typ)
Expand All @@ -852,6 +853,7 @@ func (e *encoded) Data() []uint32 {
}
x[j+4] = uint32(mask)
j += 5
last = e.items[i]
}
return x[:j]
}
Expand Down

0 comments on commit cda13e2

Please sign in to comment.