From f31671ddbae0209ad21dbc8659584188f740b270 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 4 May 2024 15:28:43 +0200 Subject: [PATCH] feat(completion): fallback for nothing typed yet --- internal/handler/completion.go | 16 ++++++------ internal/handler/completion_main_test.go | 25 ++++++++++--------- .../example/templates/completion-test.yaml | 1 + 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/internal/handler/completion.go b/internal/handler/completion.go index 76875a34..7f301f5e 100644 --- a/internal/handler/completion.go +++ b/internal/handler/completion.go @@ -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" @@ -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 } diff --git a/internal/handler/completion_main_test.go b/internal/handler/completion_main_test.go index f40d6f7c..4e304e1a 100644 --- a/internal/handler/completion_main_test.go +++ b/internal/handler/completion_main_test.go @@ -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{ @@ -83,6 +95,7 @@ func TestCompletionMain(t *testing.T) { expectedInsertText: "Chart", notExpectedInsertTexts: []string{ helmdocs.HelmFuncs[0].Name, + "js", "replicaCount", "toYaml", }, @@ -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) { diff --git a/testdata/example/templates/completion-test.yaml b/testdata/example/templates/completion-test.yaml index 09367806..0944f3dd 100644 --- a/testdata/example/templates/completion-test.yaml +++ b/testdata/example/templates/completion-test.yaml @@ -9,3 +9,4 @@ {{ if (and .Values. ) }} {{ end }} +{{ if }}