Skip to content

Commit

Permalink
Index defs assignation text.
Browse files Browse the repository at this point in the history
  • Loading branch information
pherrymason committed Jan 14, 2024
1 parent 9640d90 commit ac55944
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions server/lsp/indexables/DefBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func NewDefBuilder(name string, docId string) *DefBuilder {
}
}

func (d *DefBuilder) WithResolvesTo(resolvesTo string) *DefBuilder {
d.def.resolvesTo = resolvesTo
return d
}

func (d *DefBuilder) WithIdentifierRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *DefBuilder {
d.def.BaseIndexable.identifierRange = NewRange(lineStart, CharStart, lineEnd, CharEnd)
return d
Expand Down
8 changes: 5 additions & 3 deletions server/lsp/indexables/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
)

type Def struct {
name string
name string
resolvesTo string
BaseIndexable
}

func NewDef(name string, docId string, idRange Range, docRange Range) Def {
func NewDef(name string, resolvesTo string, docId string, idRange Range, docRange Range) Def {
return Def{
name: name,
name: name,
resolvesTo: resolvesTo,
BaseIndexable: BaseIndexable{
documentURI: docId,
identifierRange: idRange,
Expand Down
9 changes: 2 additions & 7 deletions server/lsp/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,9 @@ func (p *Parser) nodeToEnum(doc *Document, node *sitter.Node, sourceCode []byte)

func (p *Parser) nodeToDef(doc *Document, node *sitter.Node, sourceCode []byte) idx.Def {
identifierNode := node.Child(1)
//definition := node.Child(4)
definition := node.Child(3)

return idx.NewDef(
identifierNode.Content(sourceCode),
doc.URI,
idx.NewRangeFromSitterPositions(identifierNode.StartPoint(), identifierNode.EndPoint()),
idx.NewRangeFromSitterPositions(node.StartPoint(), node.EndPoint()),
)
return idx.NewDef(identifierNode.Content(sourceCode), definition.Content(sourceCode), doc.URI, idx.NewRangeFromSitterPositions(identifierNode.StartPoint(), identifierNode.EndPoint()), idx.NewRangeFromSitterPositions(node.StartPoint(), node.EndPoint()))
}

func (p *Parser) FindVariableDeclarations(doc *Document, node *sitter.Node) []idx.Variable {
Expand Down
2 changes: 2 additions & 0 deletions server/lsp/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ func TestExtractSymbols_finds_definition(t *testing.T) {
symbols := parser.ExtractSymbols(&doc)

expectedDefKilo := idx.NewDefBuilder("Kilo", "x").
WithResolvesTo("int").
WithIdentifierRange(1, 5, 1, 9).
WithDocumentRange(1, 1, 1, 16).
Build()

expectedDefKiloPtr := idx.NewDefBuilder("KiloPtr", "x").
WithResolvesTo("Kilo*").
WithIdentifierRange(2, 5, 2, 12).
WithDocumentRange(2, 1, 2, 21).
Build()
Expand Down

0 comments on commit ac55944

Please sign in to comment.