Skip to content

Commit

Permalink
add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Apr 14, 2024
1 parent 2a73006 commit 388d686
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/language_features/variables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package languagefeatures

import (
"fmt"

lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
"github.com/mrjosh/helm-ls/internal/tree-sitter/gotemplate"
"github.com/mrjosh/helm-ls/internal/util"
sitter "github.com/smacker/go-tree-sitter"
lsp "go.lsp.dev/protocol"
)

type VariablesFeature struct {
*GenericDocumentUseCase
}

func NewVariablesFeature(genericDocumentUseCase *GenericDocumentUseCase) *VariablesFeature {
return &VariablesFeature{
GenericDocumentUseCase: genericDocumentUseCase,
}
}

func (f *VariablesFeature) AppropriateForNode(currentNodeType string, parentNodeType string, node *sitter.Node) bool {
return currentNodeType == gotemplate.NodeTypeIdentifier && parentNodeType == gotemplate.NodeTypeVariable
}

func (f *VariablesFeature) Definition() (result []lsp.Location, err error) {
variableName := f.GenericDocumentUseCase.NodeContent()
definitionNode := lsplocal.GetVariableDefinition(variableName, f.GenericDocumentUseCase.ParentNode, f.Document.Content)
if definitionNode == nil {
return []lsp.Location{}, fmt.Errorf("Could not find definition for %s. Variable definition not found", variableName)
}
return []lsp.Location{{URI: f.Document.URI, Range: lsp.Range{Start: util.PointToPosition(definitionNode.StartPoint())}}}, nil
}

0 comments on commit 388d686

Please sign in to comment.