diff --git a/internal/handler/completion_main_test.go b/internal/handler/completion_main_test.go index d3b3fd5e..14c02320 100644 --- a/internal/handler/completion_main_test.go +++ b/internal/handler/completion_main_test.go @@ -161,6 +161,10 @@ func TestCompletionMain(t *testing.T) { assert.Equal(t, tt.expectedError, err) assert.NotNil(t, result) + if result == nil { + return + } + insertTexts := []string{} for _, item := range result.Items { insertTexts = append(insertTexts, item.InsertText) diff --git a/internal/lsp/ast_diagnostics_test.go b/internal/lsp/ast_diagnostics_test.go index c3354598..eacd7cfe 100644 --- a/internal/lsp/ast_diagnostics_test.go +++ b/internal/lsp/ast_diagnostics_test.go @@ -36,8 +36,8 @@ func TestIsInElseBranch(t *testing.T) { t2Content := t2.Content([]byte(template)) t3Content := t3.Content([]byte(template)) t4Content := t4.Content([]byte(template)) - if (t1Content != " t1") || t2Content != " t2" || t3Content != " t3" || t4Content != " t4" { - t.Errorf("Nodes were not correctly selected") + if (t1Content != " t1 ") || t2Content != " t2 " || t3Content != " t3 " || t4Content != " t4 " { + t.Errorf("Nodes were not correctly selected, got %s, %s, %s, %s", t1Content, t2Content, t3Content, t4Content) } if IsInElseBranch(t1) { diff --git a/internal/lsp/ast_test.go b/internal/lsp/ast_test.go index 775220f6..ce3f8e06 100644 --- a/internal/lsp/ast_test.go +++ b/internal/lsp/ast_test.go @@ -8,14 +8,7 @@ import ( ) func TestFindRelevantChildNodeCompletio(t *testing.T) { - template := `{{ .Values. }} -{{ .Values.re }} - -{{ toY }} - -{{ .Chart.N }} -{{ . }} ` ast := ParseAst(nil, template) @@ -26,12 +19,13 @@ func TestFindRelevantChildNodeCompletio(t *testing.T) { Column: 11, }) - assert.Equal(t, node.StartPoint(), sitter.Point{ + assert.Equal(t, sitter.Point{ Row: 0, - Column: 11, - }) - assert.Equal(t, node.EndPoint(), sitter.Point{ + Column: 10, + }, node.StartPoint()) + + assert.Equal(t, sitter.Point{ Row: 0, Column: 11, - }) + }, node.EndPoint()) } diff --git a/internal/lsp/ast_variable_test.go b/internal/lsp/ast_variable_test.go index a0cc5585..063a52d1 100644 --- a/internal/lsp/ast_variable_test.go +++ b/internal/lsp/ast_variable_test.go @@ -9,19 +9,17 @@ import ( ) func TestGetVariableDefinitionDirectDecleration(t *testing.T) { - - var template = ` + template := ` {{ $variable := "text" }} {{ $variable }} ` node, err := sitter.ParseCtx(context.Background(), []byte(template), gotemplate.GetLanguage()) - if err != nil { t.Errorf("Parsing did not work") } - usageNode := node.NamedChild(1) + usageNode := node.NamedChild(3) definitionNode := GetVariableDefinitionOfNode(usageNode, template) if definitionNode == nil { @@ -32,19 +30,18 @@ func TestGetVariableDefinitionDirectDecleration(t *testing.T) { } func TestGetVariableDefinitionOtherDecleration(t *testing.T) { - var template = ` + template := ` {{ $variable := "text" }} {{ $someOther := "text" }} {{ $variable }} ` node, err := sitter.ParseCtx(context.Background(), []byte(template), gotemplate.GetLanguage()) - if err != nil { t.Errorf("Parsing did not work") } - usageNode := node.NamedChild(2) + usageNode := node.NamedChild(5) definitionNode := GetVariableDefinitionOfNode(usageNode, template) if definitionNode == nil { @@ -52,11 +49,10 @@ func TestGetVariableDefinitionOtherDecleration(t *testing.T) { } else if definitionNode.Content([]byte(template)) != "$variable := \"text\"" { t.Errorf("Definition did not match but was %s", definitionNode.Content([]byte(template))) } - } func TestGetVariableDefinitionRange(t *testing.T) { - var template = `{{ range $index, $element := pipeline }}{{ $index }}{{ $element }}{{ end }}` + template := `{{ range $index, $element := pipeline }}{{ $index }}{{ $element }}{{ end }}` // (template [0, 0] - [1, 0] // (range_action [0, 0] - [0, 75] // (range_variable_definition [0, 9] - [0, 37] @@ -72,7 +68,6 @@ func TestGetVariableDefinitionRange(t *testing.T) { // name: (identifier [0, 56] - [0, 63])))) node, err := sitter.ParseCtx(context.Background(), []byte(template), gotemplate.GetLanguage()) - if err != nil { t.Errorf("Parsing did not work") } diff --git a/internal/lsp/symbol_table_test.go b/internal/lsp/symbol_table_test.go index 62ab6fe4..1fedcd89 100644 --- a/internal/lsp/symbol_table_test.go +++ b/internal/lsp/symbol_table_test.go @@ -25,18 +25,19 @@ func TestSymbolTableForIncludeDefinitions(t *testing.T) { assert.Len(t, symbolTable.includeDefinitions, 2) - assert.Equal(t, symbolTable.includeDefinitions["bar"], []sitter.Range{{ + assert.Equal(t, []sitter.Range{{ StartPoint: sitter.Point{ Row: 5, - Column: 0, + Column: 1, }, EndPoint: sitter.Point{ Row: 7, Column: 10, }, - StartByte: 56, + StartByte: 57, EndByte: 110, - }}) + }}, + symbolTable.includeDefinitions["bar"]) } func TestSymbolTableForValues(t *testing.T) { @@ -62,6 +63,8 @@ func TestSymbolTableForValues(t *testing.T) { {{ .Test }} {{ . }} + +{{ .Unfished. }} ` ast := ParseAst(nil, content) @@ -164,6 +167,13 @@ func TestSymbolTableForValues(t *testing.T) { Column: 3, }, }, + { + path: []string{"Unfished"}, + startPoint: sitter.Point{ + Row: 23, + Column: 4, + }, + }, } for _, v := range expected { diff --git a/internal/lsp/yaml_ast_test.go b/internal/lsp/yaml_ast_test.go index 05b4bded..644c6b27 100644 --- a/internal/lsp/yaml_ast_test.go +++ b/internal/lsp/yaml_ast_test.go @@ -31,47 +31,41 @@ func Test_getTextNodeRanges(t *testing.T) { want: []sitter.Range{ { StartPoint: sitter.Point{Row: 0, Column: 0}, - EndPoint: sitter.Point{Row: 0, Column: 2}, + EndPoint: sitter.Point{Row: 0, Column: 3}, StartByte: 0, - EndByte: 2, + EndByte: 3, }, }, }, { - name: "to simple text nodes", + name: "two simple text nodes", args: args{ ` a: {{ .test }} b: not`, }, want: []sitter.Range{ - {StartPoint: sitter.Point{ - Row: 0x1, Column: 0x0, - }, EndPoint: sitter.Point{ - Row: 0x1, Column: 0x2, - }, StartByte: 0x1, EndByte: 0x3}, { StartPoint: sitter.Point{ - Row: 0x2, - Column: 0x0, + Row: 0, + Column: 0, }, EndPoint: sitter.Point{ - Row: 0x2, - Column: 0x2, + Row: 1, Column: 3, }, - StartByte: 0x10, - EndByte: 0x12, + StartByte: 0, + EndByte: 4, }, { StartPoint: sitter.Point{ - Row: 0x2, - Column: 0x2, + Row: 1, + Column: 14, }, EndPoint: sitter.Point{ - Row: 0x2, - Column: 0x6, + Row: 2, + Column: 6, }, - StartByte: 0x12, - EndByte: 0x16, + StartByte: 15, + EndByte: 22, }, }, }, @@ -113,6 +107,42 @@ yaml: test trimmedText: ` +yaml: test + + T1 +`, + }, + { + documentText: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "example.fullname" . }} + labels: + {{- include "example.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "example.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "example.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: +`, + + trimmedText: ` + yaml: test T1