Skip to content

Commit

Permalink
fix(lsp): correct line numbers for tree-sitter highlights in injected…
Browse files Browse the repository at this point in the history
… code

- Update row numbers for highlights in injected code sections
- Improve handling of highlight lines in injected code to maintain correct line numbers
  • Loading branch information
wellcomez committed Nov 1, 2024
1 parent efe9a27 commit eeaf598
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/lsp/lsp_treesitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,21 @@ func (inject *ts_inject) hl() {
t := NewTreeSitterParse(inject.lang, v.Code)
if t.load_ts_def() {
t.Loadfile(t.tsdef.tslang, nil)

var HlLine = make(TreesiterSymbolLine)
for k, l := range t.HlLine {
newline := int(v.Begin.Row) + k
if line, ok := inject.hline[newline]; ok {
for i := range l {
l[i].Begin.Row = v.Begin.Row + l[i].Begin.Row
l[i].End.Row = v.Begin.Row + l[i].End.Row
}
HlLine[k+int(v.Begin.Row)] = l
}
for k, l := range HlLine {
if line, ok := inject.hline[k]; ok {
line = append(line, l...)
inject.hline[newline] = line
inject.hline[k] = line
} else {
inject.hline[newline] = l
inject.hline[k] = l
}
}
}
Expand Down Expand Up @@ -783,7 +791,7 @@ func (ts TreeSitter) get_higlight(queryname string) (ret TreesiterSymbolLine, er
v.hl()
}
for _, inj := range inejcts {
for lienno,v:=range inj.hline {
for lienno, v := range inj.hline {
if line, ok := ret[lienno]; ok {
line = append(line, v...)
ret[lienno] = line
Expand Down

0 comments on commit eeaf598

Please sign in to comment.