From 183acf2caddea3a4468ca7f9eb0db1a1138844f3 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Mon, 1 Aug 2022 17:24:04 +0200 Subject: [PATCH] Review feedback --- internal/decoder/decoder.go | 11 ++++------- internal/hooks/hooks.go | 12 +----------- internal/langserver/handlers/completion_resolve.go | 9 +-------- internal/lsp/completion.go | 1 - internal/protocol/completion.go | 9 +++++++++ 5 files changed, 15 insertions(+), 27 deletions(-) create mode 100644 internal/protocol/completion.go diff --git a/internal/decoder/decoder.go b/internal/decoder/decoder.go index 27cc1f362..ad608cc09 100644 --- a/internal/decoder/decoder.go +++ b/internal/decoder/decoder.go @@ -74,13 +74,10 @@ func varsPathContext(mod *state.Module) (*decoder.PathContext, error) { } func DecoderContext(ctx context.Context) decoder.DecoderContext { - dCtx := decoder.DecoderContext{ - UtmSource: utm.UtmSource, - UtmMedium: utm.UtmMedium(ctx), - UseUtmContent: true, - CompletionHooks: make(decoder.CompletionFuncMap), - CompletionResolveHooks: make(decoder.CompletionResolveFuncMap), - } + dCtx := decoder.NewDecoderContext() + dCtx.UtmSource = utm.UtmSource + dCtx.UtmMedium = utm.UtmMedium(ctx) + dCtx.UseUtmContent = true cc, err := ilsp.ClientCapabilities(ctx) if err == nil { diff --git a/internal/hooks/hooks.go b/internal/hooks/hooks.go index f1735e7de..64ddf7b49 100644 --- a/internal/hooks/hooks.go +++ b/internal/hooks/hooks.go @@ -1,16 +1,6 @@ // Package hooks enables the implementation of hooks for dynamic // autocompletion. Hooks should be added to this package and -// registered in AppendCompletionHooks in completion_hooks.go. -// -// A hook must have the following signature: -// func (h *Hooks) Name(ctx context.Context, value cty.Value) ([]decoder.Candidate, error) -// It receives the current value of the attribute and must return -// a list of completion candidates. -// -// All hooks have access to path, filename and pos via context: -// path, ok := decoder.PathFromContext(ctx) -// filename, ok := decoder.FilenameFromContext(ctx) -// pos, ok := decoder.PosFromContext(ctx) +// registered via AppendCompletionHooks in completion_hooks.go. package hooks import "github.com/hashicorp/terraform-ls/internal/state" diff --git a/internal/langserver/handlers/completion_resolve.go b/internal/langserver/handlers/completion_resolve.go index d3436c439..87629cc40 100644 --- a/internal/langserver/handlers/completion_resolve.go +++ b/internal/langserver/handlers/completion_resolve.go @@ -4,19 +4,12 @@ import ( "context" "github.com/hashicorp/hcl-lang/decoder" - "github.com/hashicorp/hcl-lang/lang" ilsp "github.com/hashicorp/terraform-ls/internal/lsp" "github.com/hashicorp/terraform-ls/internal/mdplain" lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -type CompletionItem struct { - lsp.CompletionItem - - ResolveHook *lang.ResolveHook `json:"data,omitempty"` -} - -func (svc *service) CompletionItemResolve(ctx context.Context, params CompletionItem) (CompletionItem, error) { +func (svc *service) CompletionItemResolve(ctx context.Context, params lsp.CompletionItemR) (lsp.CompletionItemR, error) { cc, err := ilsp.ClientCapabilities(ctx) if err != nil { return params, err diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index c779856bf..c01214516 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -71,7 +71,6 @@ func toCompletionItem(candidate lang.Candidate, caps lsp.CompletionClientCapabil TextEdit: textEdit(candidate.TextEdit, snippetSupport), Command: cmd, AdditionalTextEdits: TextEdits(candidate.AdditionalTextEdits, snippetSupport), - // TODO set deprecated via `tags` if supported. } if candidate.ResolveHook != nil { diff --git a/internal/protocol/completion.go b/internal/protocol/completion.go new file mode 100644 index 000000000..39341eeb3 --- /dev/null +++ b/internal/protocol/completion.go @@ -0,0 +1,9 @@ +package protocol + +import "github.com/hashicorp/hcl-lang/lang" + +type CompletionItemR struct { + CompletionItem + + ResolveHook *lang.ResolveHook `json:"data,omitempty"` +}