-
Notifications
You must be signed in to change notification settings - Fork 131
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
Introduce a new job for running early validation #1346
Conversation
6399262
to
36dee47
Compare
74e43a0
to
0b65393
Compare
0b65393
to
b2c3405
Compare
4f3c074
to
91febd3
Compare
Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future.
b2c3405
to
86e41f7
Compare
f92c827
to
d81461c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from that one in-line comment and minor comment wording change.
@@ -124,6 +124,19 @@ func (idx *Indexer) decodeModule(ctx context.Context, modHandle document.DirHand | |||
} | |||
ids = append(ids, refOriginsId) | |||
|
|||
_, err = idx.jobStore.EnqueueJob(ctx, job.Job{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a thought process behind why we should or should not wait for this job to finish? We seem to wait for all of them except for the one below.
I believe the original idea was that anything that would be affected by the change (such as parsing) and where it matters that we process changes in the right order, we should wait. Technically the client won't really wait in the sense that the UI shouldn't be blocked but it may affect how we process next change notifications.
Here I think we should try to avoid publishing outdated diagnostics.
TL;DR I think we should wait, i.e. return job ID and append to the slice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were waiting on all jobs to make sure we're done processing everything when a user hits autocomplete (or hovers, or...).
Diagnostics require no user interaction, are owned by the server, and can be published whenever they're ready. Since validation depends on parsing and decoding, we'll always use the latest parsed information for validation.
I don't see how waiting for the validation job would change things, so I discarded the job id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can observe the UX to later understand the impact of that. I suppose most of the concerns I have about outdated diagnostics could be alleviated by us using the document version
in our requests
/**
* Optional the version number of the document the diagnostics are published
* for.
*
* @since 3.15.0
*/
version?: [integer](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#integer);
It still seems wasteful to be computing diagnostics for a version which is already outdated by the time we compute them but maybe that's a different problem that we can't really address here anyway.
So TL;DR feel free to merge as-is, we can look into it later if necessary.
Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
* Implement unreferenced variable validation (#1357) Add the ability to use the collected origin and target references in early validation by providing a hook for validation funcs. This also adds a validator for unreferenced variables. Validation funcs will be provided by terraform-ls for now, but may be moved into hcl-lang in the future. * Introduce ValidationDiagnostics field to module * Publish early validation diagnostics * Include validation diagnotics in changes check * Introduce early validation job * Check ValidationDiagnosticsState when running validation * Run early validation job after collection jobs * Bump hcl-lang to `b6a3f8` * Update internal/terraform/module/module_ops.go Co-authored-by: Radek Simko <radek.simko@gmail.com> --------- Co-authored-by: James Pogran <jpogran@outlook.com> Co-authored-by: Radek Simko <radek.simko@gmail.com>
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
This PR adds a new job for running the early validation logic.
After discussing different approaches (e.g., running validation inside a module hook), we decided to use a new job instead. This allows us to decouple the validation from the diagnostic publishing, which still runs as a module hook. The decoupling makes integrating with the existing
terraform validate
logic in thedidSave
handler easier.It is planned to create a follow-up PR that splits the job into two different jobs. Two jobs will allow us to publish AST-based validations earlier than reference-based validations (which require the results from additional jobs).
Closes #1338