Skip to content

Commit

Permalink
Prefill Required Attributes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jpogran committed Oct 6, 2021
1 parent 8840e7b commit aa52ea0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
7 changes: 7 additions & 0 deletions internal/langserver/handlers/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
3 changes: 2 additions & 1 deletion internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

type ExperimentalFeatures struct {
ValidateOnSave bool `mapstructure:"validateOnSave"`
ValidateOnSave bool `mapstructure:"validateOnSave"`
PrefillRequiredFields bool `mapstructure:"prefillRequiredFields"`
}

type Options struct {
Expand Down

0 comments on commit aa52ea0

Please sign in to comment.