|
1 | 1 | package langsrv
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "strings" |
| 5 | + |
4 | 6 | sitter "github.com/smacker/go-tree-sitter"
|
5 | 7 | "github.com/tliron/glsp"
|
6 | 8 | protocol "github.com/tliron/glsp/protocol_3_16"
|
@@ -99,26 +101,31 @@ func textDocumentSemanticTokensFull(context *glsp.Context, params *protocol.Sema
|
99 | 101 | continue
|
100 | 102 | }
|
101 | 103 | 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 |
112 | 119 | } 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 |
| - }) |
120 | 120 | column = 0
|
121 | 121 | }
|
| 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 | + }) |
122 | 129 | }
|
123 | 130 | }
|
124 | 131 | }
|
|
0 commit comments