decoder: Pick core schema only based on required_version
constraint
#993
Labels
enhancement
New feature or request
modules
Functionality related to the module block and modules generally
Milestone
#992 removes the other reason we run
terraform version
, so this issue may depend on it - at least we cannot avoid running it until we have other ways to get provider versions.Background
Currently we pick core schema based on version that we determine by running
terraform version -json
viaGetTerraformVersion
jobterraform-ls/internal/terraform/module/module_ops.go
Lines 54 to 89 in 81b49a1
which we in turn run within every walked directory
terraform-ls/internal/indexer/walker.go
Lines 61 to 73 in 81b49a1
This makes walking through a deep hierarchy with many modules quite an expensive process.
The scheduler already de-duplicates jobs (including
GetTerraformVersion
), such that we never run the same job for the same folder more than once, if it's already in the queue. This is a good barrier, but we anticipate the following features to put more pressure on the scheduler and create more situations of duplicate work (same job for the same folder) scheduled more sparsely, which the scheduler itself has no chance of catching.both of which increase the chance of us scheduling the same jobs for the same directory repeatedly.
Proposal
terraform-schema
: Introduce a function similar to the existingCoreModuleSchemaForVersion
which takes version constraint instead of version and returns relevant root schemadecoder
: Update logic responsible for picking core schematerraform-ls/internal/decoder/module_schema.go
Lines 14 to 26 in 81b49a1
Notes
While running
terraform version
for every walked directory is expensive, there's still value in knowing Terraform version.We should therefore retain the following logic in
textDocument/didOpen
:terraform-ls/internal/langserver/handlers/did_open.go
Lines 68 to 81 in 81b49a1
i.e. continue obtaining TF version when the user opens a module in the editor and we don't know the version yet.
The text was updated successfully, but these errors were encountered: