Pre-fill required local module inputs on source completion
Background
In https://github.com/hashicorp/terraform-ls/pull/1024, we introduced completion for local module sources. It uses the local indexed modules to build a list of source strings relative to the current file. The indexed modules also contain a list of module inputs (and outputs). So we can use those inputs to build a text snippet containing only the required ones.
Contrary to the registry module sources we can accomplish this without a resolve handler for completion items, since it doesn't involve any HTTP requests. All the data we need is already present.
Expected User Experience
Fill the required module inputs when completing a local module source, providing a similar experience as for resources:

This includes:
- Using snippets with placeholders for tabbing through all inputs after insertion
- Showing a preview if a user has
editor.suggest.previewenabled
Proposal
hashicorp/terraform-ls
- Modify the a
CompleteLocalModuleSourceshook - Get the module inputs from
mod.Meta.Variables - Extend the
textEditfor each candidate with a snippet based on the inputs- We're doing something similar for resource fields here
- Make sure the range of the
textEditstill is a single line, while the snippet may contain multiple newlines.
Additional context / links
- https://github.com/hashicorp/terraform-ls/issues/1029 similar issue for registry module sources
@dbanck apologies for the hijack as I didn't want to open a new issue and can't comment on https://github.com/hashicorp/terraform-ls/pull/1024 Would https://github.com/hashicorp/terraform-ls/pull/1024 work for neovim folks? I'm having a hard time finding a way to trigger the autocomplete like in your gif. My init.vim is configured with coc's recommended settings. I can do things like ctrl+enter and it will provide me the list of options for a resource and help fill whether it's a list or map, but dunno how to trigger something in your example or when calling a module, have it auto-fillin the options. Thanks!
Hi @nocode99,
Module source and version completion should work for all editors. However, you might see different results depending on your Terraform LS installation source. This is because the binaries we build and publish on releases.hashicorp.com contain the static schema for the top registry providers and Algolia tokens, which power the module search. Both aren't included if you compile the language server or install it via the default Homebrew formula.
You can check which version you use via the -v flag.
Installation via Homebrew community reports
$ terraform-ls -v
0.30.3+Homebrew
Installation via HashiCorp Homebrew Tab or releases.hashicorp.com or Linux packaging reports
$ terraform-ls -v
0.30.3
When using the latter, module source and version completion should work. Autocompleting the source to a local module should work for all language server versions.
Thanks for the reply @dbanck. I'm running on Ubuntu. I'll be sure to review my settings and see what I need to do to get this to work.
Following on nocode99's issue -- I'm also unable to complete remote module sources. I've verified I have 0.34.2 from upstream (md5sum db742e18bf7a32f71960dfc12abbbd1d)
Version completion works fine, which is interesting! (local version also completes, but that's not as interesting since it doesn't require the algolia key)
Hi @travisby, can you please open a separate bug if this is still happening for you.