Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-fill required local module inputs on source completion #1040

Open
dbanck opened this issue Aug 12, 2022 · 5 comments
Open

Pre-fill required local module inputs on source completion #1040

dbanck opened this issue Aug 12, 2022 · 5 comments
Labels
enhancement New feature or request modules Functionality related to the module block and modules generally textDocument/completion

Comments

@dbanck
Copy link
Member

dbanck commented Aug 12, 2022

Background

In #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:
2022-08-05 11 26 59

This includes:

  • Using snippets with placeholders for tabbing through all inputs after insertion
  • Showing a preview if a user has editor.suggest.preview enabled

Proposal

hashicorp/terraform-ls

  • Modify the a CompleteLocalModuleSources hook
  • Get the module inputs from mod.Meta.Variables
  • Extend the textEdit for each candidate with a snippet based on the inputs
    • We're doing something similar for resource fields here
  • Make sure the range of the textEdit still is a single line, while the snippet may contain multiple newlines.

Additional context / links

@dbanck dbanck added enhancement New feature or request textDocument/completion modules Functionality related to the module block and modules generally labels Aug 12, 2022
@nocode99
Copy link

nocode99 commented Apr 7, 2023

@dbanck apologies for the hijack as I didn't want to open a new issue and can't comment on #1024 Would #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!

@dbanck
Copy link
Member Author

dbanck commented Apr 10, 2023

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.

@nocode99
Copy link

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.

@travisby
Copy link

travisby commented Aug 8, 2024

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)

@dbanck
Copy link
Member Author

dbanck commented Oct 1, 2024

Hi @travisby, can you please open a separate bug if this is still happening for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request modules Functionality related to the module block and modules generally textDocument/completion
Projects
None yet
Development

No branches or pull requests

3 participants