Skip to content

Commit

Permalink
fix: extract NodeToRange
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Jul 1, 2024
1 parent 9219696 commit 1e124c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 2 additions & 6 deletions internal/lsp/variables_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lsp

import (
"github.com/mrjosh/helm-ls/internal/tree-sitter/gotemplate"
"github.com/mrjosh/helm-ls/internal/util"
sitter "github.com/smacker/go-tree-sitter"
)

Expand Down Expand Up @@ -114,12 +115,7 @@ func (v *VariablesVisitor) addVariableDefinition(variableType VariableType, defi
}

func (v *VariablesVisitor) addVariableUsage(node *sitter.Node) {
v.symbolTable.AddVariableUsage(node.Content(v.content), sitter.Range{
StartPoint: node.StartPoint(),
EndPoint: node.EndPoint(),
StartByte: node.StartByte(),
EndByte: node.EndByte(),
})
v.symbolTable.AddVariableUsage(node.Content(v.content), util.NodeToRange(node))
}

func (v *VariablesVisitor) EnterContextShift(_ *sitter.Node, _ string) {}
Expand Down
9 changes: 9 additions & 0 deletions internal/util/ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ import sitter "github.com/smacker/go-tree-sitter"
func RangeContainsRange(surrounding, including sitter.Range) bool {
return surrounding.StartByte <= including.StartByte && surrounding.EndByte >= including.EndByte
}

func NodeToRange(node *sitter.Node) sitter.Range {
return sitter.Range{
StartPoint: node.StartPoint(),
EndPoint: node.EndPoint(),
StartByte: node.StartByte(),
EndByte: node.EndByte(),
}
}

0 comments on commit 1e124c3

Please sign in to comment.