From aa52ea03eb610f376a96e84a8c0d6ab478c7f33a Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 29 Sep 2021 10:34:08 -0400 Subject: [PATCH] Prefill Required Attributes This adds a new experimental setting for prefilling required fields as blocks are completed from intellisense. For example, completing a resource provider will fill in the required attributes automatically. --- go.mod | 2 ++ go.sum | 4 ---- internal/langserver/handlers/complete.go | 7 +++++++ internal/langserver/handlers/service.go | 1 + internal/settings/settings.go | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0e3d6f6ac..44e102f91 100644 --- a/go.mod +++ b/go.mod @@ -35,3 +35,5 @@ require ( github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e ) + +replace github.com/hashicorp/hcl-lang => ../hcl-lang diff --git a/go.sum b/go.sum index b562a78af..bcf6b3a7f 100644 --- a/go.sum +++ b/go.sum @@ -190,9 +190,6 @@ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+l github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl-lang v0.0.0-20210803155453-7c098e4940bc/go.mod h1:xzXU6Fn+TWVaZUFxV8CyAsObi2oMgSEFAmLvCx2ArzM= -github.com/hashicorp/hcl-lang v0.0.0-20210823185445-8fcbc27a6a22 h1:Yji8S7wFSfEj/KyzP/0J/f007tyKboV9rBz5u4uZ2r4= -github.com/hashicorp/hcl-lang v0.0.0-20210823185445-8fcbc27a6a22/go.mod h1:D7lBT7dekCcgbxzIHHBFvaRm42u5jY0pDoiC2J6A2KM= github.com/hashicorp/hcl/v2 v2.10.1 h1:h4Xx4fsrRE26ohAk/1iGF/JBqRQbyUqu5Lvj60U54ys= github.com/hashicorp/hcl/v2 v2.10.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= @@ -383,7 +380,6 @@ github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.8.4/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.9.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.9.1 h1:viqrgQwFl5UpSxc046qblj78wZXVDFnSOufaOTER+cc= github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= diff --git a/internal/langserver/handlers/complete.go b/internal/langserver/handlers/complete.go index 73b23f7f0..3d1bc280f 100644 --- a/internal/langserver/handlers/complete.go +++ b/internal/langserver/handlers/complete.go @@ -47,6 +47,13 @@ func (h *logHandler) TextDocumentComplete(ctx context.Context, params lsp.Comple } d.SetSchema(schema) + expFeatures, err := lsctx.ExperimentalFeatures(ctx) + if err != nil { + return list, err + } + + d.PrefillRequiredFields = expFeatures.PrefillRequiredFields + fPos, err := ilsp.FilePositionFromDocumentPosition(params.TextDocumentPositionParams, file) if err != nil { return list, err diff --git a/internal/langserver/handlers/service.go b/internal/langserver/handlers/service.go index a0c2de63a..e9ef163b6 100644 --- a/internal/langserver/handlers/service.go +++ b/internal/langserver/handlers/service.go @@ -217,6 +217,7 @@ func (svc *service) Assigner() (jrpc2.Assigner, error) { ctx = lsctx.WithDocumentStorage(ctx, svc.fs) ctx = lsctx.WithClientCapabilities(ctx, cc) ctx = lsctx.WithModuleFinder(ctx, svc.modMgr) + ctx = lsctx.WithExperimentalFeatures(ctx, &expFeatures) return handle(ctx, req, lh.TextDocumentComplete) }, diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 5f586b5c0..5e6c03e8f 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -9,7 +9,8 @@ import ( ) type ExperimentalFeatures struct { - ValidateOnSave bool `mapstructure:"validateOnSave"` + ValidateOnSave bool `mapstructure:"validateOnSave"` + PrefillRequiredFields bool `mapstructure:"prefillRequiredFields"` } type Options struct {