Skip to content

Commit

Permalink
remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Apr 28, 2024
1 parent 4fd11e5 commit 27e73fb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 187 deletions.
5 changes: 1 addition & 4 deletions internal/handler/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (h *langHandler) Completion(ctx context.Context, params *lsp.CompletionPara
Row: params.Position.Line,
Column: params.Position.Character,
}
relevantChildNode = lsplocal.FindRelevantChildNode(currentNode, pointToLoopUp)
relevantChildNode = lsplocal.FindRelevantChildNodeCompletion(currentNode, pointToLoopUp)
)
genericDocumentUseCase = genericDocumentUseCase.WithNode(relevantChildNode)

Expand Down Expand Up @@ -165,9 +165,6 @@ func completionAstParsing(doc *lsplocal.Document, position lsp.Position) (string
case gotemplate.NodeTypeDot:
logger.Debug("TraverseIdentifierPathUp for dot node")
word = lsplocal.TraverseIdentifierPathUp(relevantChildNode, doc)
case gotemplate.NodeTypeDotSymbol, gotemplate.NodeTypeFieldIdentifier:
logger.Debug("GetFieldIdentifierPath")
word = lsplocal.GetFieldIdentifierPath(relevantChildNode, doc)
case gotemplate.NodeTypeText, gotemplate.NodeTypeTemplate:
return word, true
}
Expand Down
19 changes: 0 additions & 19 deletions internal/handler/completion_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"testing"

"github.com/mrjosh/helm-ls/internal/charts"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
"github.com/mrjosh/helm-ls/pkg/chart"
"github.com/stretchr/testify/assert"
"go.lsp.dev/protocol"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -87,23 +85,6 @@ func TestWrongValues(t *testing.T) {
}
}

func TestCompletionAstParsing(t *testing.T) {
documentText := `{{ .Values.global. }}`
expectedWord := ".Values.global."
doc := &lsplocal.Document{
Content: documentText,
Ast: lsplocal.ParseAst(nil, documentText),
}
position := protocol.Position{
Line: 0,
Character: 18,
}
word, _ := completionAstParsing(doc, position)
if expectedWord != word {
t.Errorf("Expected word '%s', but got '%s'", expectedWord, word)
}
}

func TestGetValuesCompletions(t *testing.T) {
handler := &langHandler{
linterName: "helm-lint",
Expand Down
1 change: 1 addition & 0 deletions internal/language_features/template_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (f *TemplateContextFeature) Completion() (result *lsp.CompletionList, err e

return &lsp.CompletionList{Items: completions, IsIncomplete: false}, nil
case "Chart", "Release", "Files", "Capabilities", "Template":
// TODO: make this more fine, by checking the lenght

Check failure on line 176 in internal/language_features/template_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

`lenght` is a misspelling of `length` (misspell)
result, ok := helmdocs.BuiltInOjectVals[templateContext[0]]
if !ok {
result := helmdocs.BuiltInObjects
Expand Down
49 changes: 14 additions & 35 deletions internal/lsp/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lsp

import (
"context"
"fmt"

"github.com/mrjosh/helm-ls/internal/tree-sitter/gotemplate"
sitter "github.com/smacker/go-tree-sitter"
Expand Down Expand Up @@ -32,14 +31,27 @@ func FindDirectChildNodeByStart(currentNode *sitter.Node, pointToLookUp sitter.P
}

func FindRelevantChildNode(currentNode *sitter.Node, pointToLookUp sitter.Point) *sitter.Node {
for i := 0; i < int(currentNode.ChildCount()); i++ {
child := currentNode.Child(i)
if child == nil {
continue
}
if isPointLargerOrEq(pointToLookUp, child.StartPoint()) && isPointLargerOrEq(child.EndPoint(), pointToLookUp) {
return FindRelevantChildNode(child, pointToLookUp)
}
}
return currentNode
}

func FindRelevantChildNodeCompletion(currentNode *sitter.Node, pointToLookUp sitter.Point) *sitter.Node {
childCount := int(currentNode.ChildCount())
for i := childCount - 1; i >= 0; i-- {
child := currentNode.Child(i)
if child == nil {
continue
}
if isPointLargerOrEq(pointToLookUp, child.StartPoint()) && isPointLargerOrEq(child.EndPoint(), pointToLookUp) {
return FindRelevantChildNode(child, pointToLookUp)
return FindRelevantChildNodeCompletion(child, pointToLookUp)
}
}
return currentNode
Expand All @@ -52,39 +64,6 @@ func isPointLargerOrEq(a sitter.Point, b sitter.Point) bool {
return a.Row > b.Row
}

func GetFieldIdentifierPath(node *sitter.Node, doc *Document) (path string) {
path = buildFieldIdentifierPath(node, doc)
logger.Debug(fmt.Sprintf("buildFieldIdentifierPath: %s for node %s with parent %s", path, node, node.Parent()))

return path
}

func buildFieldIdentifierPath(node *sitter.Node, doc *Document) string {
prepend := node.PrevNamedSibling()

currentPath := node.Content([]byte(doc.Content))
if prepend != nil {
nodeContent := node.Content([]byte(doc.Content))
if nodeContent == "." {
nodeContent = ""
}
currentPath = prepend.Content([]byte(doc.Content)) + "." + nodeContent
logger.Println("Adding currentpath", currentPath)
} else if node.Parent() != nil && node.Parent().Type() == gotemplate.NodeTypeError {
return buildFieldIdentifierPath(node.Parent(), doc)
}

if currentPath[0:1] == "$" {
return currentPath
}

if currentPath[0:1] != "." {
currentPath = "." + currentPath
}

return TraverseIdentifierPathUp(node, doc) + currentPath
}

func TraverseIdentifierPathUp(node *sitter.Node, doc *Document) string {
parent := node.Parent()

Expand Down
127 changes: 0 additions & 127 deletions internal/lsp/ast_field_identifier_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/lsp/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFindRelevantChildNode(t *testing.T) {
func TestFindRelevantChildNodeCompletio(t *testing.T) {

template := `{{ .Values. }}
{{ .Values.re }}
Expand All @@ -21,7 +21,7 @@ func TestFindRelevantChildNode(t *testing.T) {

logger.Println("RootNode:", ast.RootNode().String())

node := FindRelevantChildNode(ast.RootNode(), sitter.Point{
node := FindRelevantChildNodeCompletion(ast.RootNode(), sitter.Point{
Row: 0,
Column: 11,
})
Expand Down
1 change: 1 addition & 0 deletions internal/protocol/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (c *CompletionResult) ToLSP() (result lsp.CompletionItem) {
Detail: c.Documentation.Detail,
InsertText: c.Documentation.Name,
InsertTextFormat: lsp.InsertTextFormatSnippet,
Kind: lsp.CompletionItemKindConstant,
}
}

Expand Down

0 comments on commit 27e73fb

Please sign in to comment.