Skip to content

Commit

Permalink
feat(completion): fallback for nothing typed yet
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed May 4, 2024
1 parent 5f95b6b commit f31671d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
16 changes: 8 additions & 8 deletions internal/handler/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

languagefeatures "github.com/mrjosh/helm-ls/internal/language_features"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
"github.com/mrjosh/helm-ls/internal/protocol"
lsp "go.lsp.dev/protocol"

helmdocs "github.com/mrjosh/helm-ls/internal/documentation/helm"
Expand All @@ -29,14 +30,13 @@ func (h *langHandler) Completion(ctx context.Context, params *lsp.CompletionPara
}
}

items := []lsp.CompletionItem{}
items := []helmdocs.HelmDocumentation{}
for _, v := range helmdocs.BuiltInObjects {
items = append(items, lsp.CompletionItem{
Label: v.Name,
InsertText: "." + v.Name,
Detail: v.Detail,
Documentation: v.Doc,
})
v.Name = "." + v.Name
items = append(items, v)
}
return &lsp.CompletionList{IsIncomplete: false, Items: items}, err

return protocol.CompletionResults{}.
WithDocs(items, lsp.CompletionItemKindConstant).
WithDocs(helmdocs.AllFuncs, lsp.CompletionItemKindFunction).ToList(), nil
}
25 changes: 13 additions & 12 deletions internal/handler/completion_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ func TestCompletionMain(t *testing.T) {
notExpectedInsertTexts []string
expectedError error
}{
{
desc: "Test completion on {{ not }}",
position: lsp.Position{
Line: 11,
Character: 7,
},
expectedInsertText: "toYaml",
notExpectedInsertTexts: []string{
"replicaCount",
},
expectedError: nil,
},
{
desc: "Test completion on text",
position: lsp.Position{
Expand Down Expand Up @@ -83,6 +95,7 @@ func TestCompletionMain(t *testing.T) {
expectedInsertText: "Chart",
notExpectedInsertTexts: []string{
helmdocs.HelmFuncs[0].Name,
"js",
"replicaCount",
"toYaml",
},
Expand Down Expand Up @@ -112,18 +125,6 @@ func TestCompletionMain(t *testing.T) {
},
expectedError: nil,
},
// {
// desc: "Test completion on {{ }}",
// position: lsp.Position{
// Line: 4,
// Character: 3,
// },
// expectedInsertText: "toYaml",
// notExpectedInsertTexts: []string{
// "replicaCount",
// },
// expectedError: nil,
// },
}
for _, tt := range testCases {
t.Run(tt.desc, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testdata/example/templates/completion-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
{{ if (and .Values. ) }}

{{ end }}
{{ if }}

0 comments on commit f31671d

Please sign in to comment.