diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index 0fd4c275..7ffbb75f 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -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, diff --git a/go.mod b/go.mod index 42867300..d94ec6ce 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5ffd14c0..88d78615 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/langserver/handlers/complete.go b/internal/langserver/handlers/complete.go index 73b23f7f..3d1bc280 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 a0c2de63..e9ef163b 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 5f586b5c..5e6c03e8 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 {