Skip to content

Commit a63d4e9

Browse files
committed
fix: highlight multiline-comments with correct offsets
1 parent 7280a58 commit a63d4e9

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

langsrv/handler-text-document-semantic-tokens-full.go

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package langsrv
22

33
import (
4+
"strings"
5+
46
sitter "github.com/smacker/go-tree-sitter"
57
"github.com/tliron/glsp"
68
protocol "github.com/tliron/glsp/protocol_3_16"
@@ -99,26 +101,31 @@ func textDocumentSemanticTokensFull(context *glsp.Context, params *protocol.Sema
99101
continue
100102
}
101103
tokenModifiers := tokenModifiersForCaptureName(captureName)
102-
column := uint32(capturedNode.StartPoint().Column)
103-
for row := uint32(capturedNode.StartPoint().Row); row <= capturedNode.EndPoint().Row; row++ {
104-
if row == capturedNode.EndPoint().Row {
105-
tokens = append(tokens, highlightedToken{
106-
line: row,
107-
column: column,
108-
length: capturedNode.EndPoint().Column,
109-
tokenType: *tokenType,
110-
tokenModifiers: tokenModifiers,
111-
})
104+
if capturedNode.StartPoint().Row < capturedNode.EndPoint().Row {
105+
tokens = append(tokens, highlightedToken{
106+
line: capturedNode.StartPoint().Row,
107+
column: capturedNode.StartPoint().Column,
108+
length: capturedNode.StartPoint().Column - capturedNode.EndPoint().Column,
109+
tokenType: *tokenType,
110+
tokenModifiers: tokenModifiers,
111+
})
112+
}
113+
content := entry.item.Text[capturedNode.StartByte():capturedNode.EndByte()]
114+
lines := strings.Split(content, "\n")
115+
for i, line := range lines {
116+
var column uint32
117+
if i == 0 {
118+
column = capturedNode.StartPoint().Column
112119
} else {
113-
tokens = append(tokens, highlightedToken{
114-
line: row,
115-
column: column,
116-
length: capturedNode.EndByte() - capturedNode.StartByte(),
117-
tokenType: *tokenType,
118-
tokenModifiers: tokenModifiers,
119-
})
120120
column = 0
121121
}
122+
tokens = append(tokens, highlightedToken{
123+
line: capturedNode.StartPoint().Row + uint32(i),
124+
column: column,
125+
length: uint32(len(line)),
126+
tokenType: *tokenType,
127+
tokenModifiers: tokenModifiers,
128+
})
122129
}
123130
}
124131
}

0 commit comments

Comments
 (0)