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

decoder: Enable completion when turning invalid config into valid #347

Open
radeksimko opened this issue Nov 20, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

Background

Currently when the user attempts completion (either by simply typing or explicitly via Ctrl+Space or equivalent hotkey) and we cannot offer any candidates, we often times treat the completion list as complete.

Specifically, in LSP terms we return isIncomplete: false along with empty list of candidates.

In reality though this is only appropriate if we have confidence in that empty list. There can be situations we cannot know until the user continues to type and makes the configuration valid, which in turn makes it possible for us to provide candidates.

These candidates are currently ignored because the isIncomplete: false effectively instructs the clients to cache that empty list and avoid asking for candidates again in that context. The LSP doesn't go into detail about what is considered context worth caching/invalidating but anecdotally it impacts completion within the same expression.

Example:

default = {
  foo = "foo-${}"
}

^ this is considered invalid configuration, to the point that we're unable to calculate any candidates at all as the whole LOC beginning with foo = ... is ignored.

Even after the user types a single character, making it valid (at least in HCL's terms), e.g.

default = {
  foo = "foo-${v}"
}

the client does not ask for completion again.

While the question of partial AST returned for the first example is to be addressed in hashicorp/hcl#641 we could dampen the impact of that on our end by still enabling completion in the second example. i.e. we may not be able to offer completion on the first keystroke but at least on the second one.

Proposal

Consider avoiding IsComplete: true as a default state here and maybe consider updating the expression interface to also include IsComplete, i.e. return lang.Candidates instead of []lang.Candidate here.

@radeksimko radeksimko added the enhancement New feature or request label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant