Skip to content

Commit

Permalink
fix: remove yaml ast parsing
Browse files Browse the repository at this point in the history
is currently not used.
Maybe fixes #68
  • Loading branch information
qvalentin committed Mar 30, 2024
1 parent 89f77e3 commit 3237b01
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
12 changes: 0 additions & 12 deletions internal/lsp/yaml_ast.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package lsp

import (
"context"

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

func getRangeForNode(node *sitter.Node) sitter.Range {
Expand All @@ -31,15 +28,6 @@ func getTextNodeRanges(gotemplateNode *sitter.Node) []sitter.Range {
return textNodes
}

func ParseYamlAst(gotemplateTree *sitter.Tree, content string) *sitter.Tree {
parser := sitter.NewParser()
parser.SetLanguage(yaml.GetLanguage())
parser.SetIncludedRanges(getTextNodeRanges(gotemplateTree.RootNode()))

tree, _ := parser.ParseCtx(context.Background(), nil, []byte(content))
return tree
}

// TrimTemplate removes all template nodes.
// This is done by keeping only the text nodes
// which is easier then removing the template nodes
Expand Down
33 changes: 0 additions & 33 deletions internal/lsp/yaml_ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,6 @@ b: not`,
}
}

func TestParseYamlAst(t *testing.T) {
type args struct {
content string
}
tests := []struct {
name string
args args
wantSexpr string
}{
{
name: "simple template node",
args: args{
"a: {{ .test }}",
},
wantSexpr: "(stream (document (block_node (block_mapping (block_mapping_pair key: (flow_node (plain_scalar (string_scalar))))))))",
},
{
name: "key value",
args: args{
"a: value",
},
wantSexpr: "(stream (document (block_node (block_mapping (block_mapping_pair key: (flow_node (plain_scalar (string_scalar))) value: (flow_node (plain_scalar (string_scalar))))))))",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotemplateTree := ParseAst(nil, tt.args.content)
got := ParseYamlAst(gotemplateTree, tt.args.content)
assert.Equal(t, tt.wantSexpr, got.RootNode().String())
})
}
}

func TestTrimTemplate(t *testing.T) {
tests := []struct {
documentText string
Expand Down

0 comments on commit 3237b01

Please sign in to comment.