Skip to content

Commit

Permalink
update grammar back to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed May 3, 2024
1 parent f051d2e commit 9c7182f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 48 deletions.
4 changes: 4 additions & 0 deletions internal/handler/completion_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/ast_diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 6 additions & 12 deletions internal/lsp/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import (
)

func TestFindRelevantChildNodeCompletio(t *testing.T) {

template := `{{ .Values. }}
{{ .Values.re }}
{{ toY }}
{{ .Chart.N }}
{{ . }}
`
ast := ParseAst(nil, template)

Expand All @@ -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())
}
15 changes: 5 additions & 10 deletions internal/lsp/ast_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,31 +30,29 @@ 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 {
t.Errorf("Could not get definitionNode")
} 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]
Expand All @@ -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")
}
Expand Down
18 changes: 14 additions & 4 deletions internal/lsp/symbol_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -62,6 +63,8 @@ func TestSymbolTableForValues(t *testing.T) {
{{ .Test }}
{{ . }}
{{ .Unfished. }}
`

ast := ParseAst(nil, content)
Expand Down Expand Up @@ -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 {
Expand Down
70 changes: 50 additions & 20 deletions internal/lsp/yaml_ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c7182f

Please sign in to comment.