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 7, 2021
1 parent 4a42854 commit cedf396
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ Enabling this feature will run terraform validate within the folder of the file
- Validation is not run on file open, only once it's saved.
- When editing a module file, validation is not run due to not knowing which "rootmodule" to run validation from (there could be multiple). This creates an awkward workflow where when saving a file in a rootmodule, a diagnostic is raised in a module file. Editing the module file will not clear the diagnostic for the reason mentioned above, it will only clear once a file is saved back in the original "rootmodule". We will continue to attempt improve this user experience.

### `experimentalFeatures.prefillRequiredFields`

Enables advanced completion for `provider`, `resource`, and `data` blocks where any required fields for that block are pre-filled. All such attributes and blocks are sorted alphabetically to ensure consistent ordering.

When disabled (unset or set to `false`), completion only provides the label name.

For example, when completing the `aws_appmesh_route` resource the `mesh_name`, `name`, `virtual_router_name` attributes and the `spec` block will fill and prompt you for appropriate values.

## How to pass settings

The server expects static settings to be passed as part of LSP `initialize` call,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/go-memdb v1.3.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/hcl-lang v0.0.0-20210823185445-8fcbc27a6a22
github.com/hashicorp/hcl-lang v0.0.0-20211007132635-f22d3c2adf6c
github.com/hashicorp/hcl/v2 v2.10.1
github.com/hashicorp/terraform-exec v0.15.0
github.com/hashicorp/terraform-json v0.13.0
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG
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-lang v0.0.0-20210824132129-4bf451bad31e h1:RJJCsEHFbEh3GByXTyKvNVMRN8VRVOWd45WQfb5oddQ=
github.com/hashicorp/hcl-lang v0.0.0-20210824132129-4bf451bad31e/go.mod h1:D7lBT7dekCcgbxzIHHBFvaRm42u5jY0pDoiC2J6A2KM=
github.com/hashicorp/hcl-lang v0.0.0-20211006152007-86c2c237ce8d h1:5v9AxvjOjmen1wYFD1x2LpsY7d8YZSSPwYa8ahLY5bM=
github.com/hashicorp/hcl-lang v0.0.0-20211006152007-86c2c237ce8d/go.mod h1:D7lBT7dekCcgbxzIHHBFvaRm42u5jY0pDoiC2J6A2KM=
github.com/hashicorp/hcl-lang v0.0.0-20211007132635-f22d3c2adf6c h1:98h0kdFx2qqS8lMAbGxR+b/HO3d52NdJsIgzG6Ikucg=
github.com/hashicorp/hcl-lang v0.0.0-20211007132635-f22d3c2adf6c/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
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 cedf396

Please sign in to comment.