-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load embedded provider schemas for providers found in stacks fi…
…le while early decoding
- Loading branch information
Showing
9 changed files
with
247 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package jobs | ||
|
||
import ( | ||
"context" | ||
"io/fs" | ||
"log" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/hashicorp/terraform-ls/internal/document" | ||
"github.com/hashicorp/terraform-ls/internal/features/stacks/state" | ||
"github.com/hashicorp/terraform-ls/internal/job" | ||
globalState "github.com/hashicorp/terraform-ls/internal/state" | ||
"github.com/hashicorp/terraform-ls/internal/terraform/module/operation" | ||
tfaddr "github.com/hashicorp/terraform-registry-address" | ||
) | ||
|
||
func PreloadEmbeddedSchema(ctx context.Context, logger *log.Logger, fs fs.ReadDirFS, stackStore *state.StackStore, schemaStore *globalState.ProviderSchemaStore, stackPath string) error { | ||
record, err := stackStore.StackRecordByPath(stackPath) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Avoid preloading schema if it is already in progress or already known | ||
if record.PreloadEmbeddedSchemaState != operation.OpStateUnknown && !job.IgnoreState(ctx) { | ||
return job.StateNotChangedErr{Dir: document.DirHandleFromPath(stackPath)} | ||
} | ||
|
||
err = stackStore.SetPreloadEmbeddedSchemaState(stackPath, operation.OpStateLoading) | ||
if err != nil { | ||
return err | ||
} | ||
defer stackStore.SetPreloadEmbeddedSchemaState(stackPath, operation.OpStateLoaded) | ||
|
||
pReqs := make(map[tfaddr.Provider]version.Constraints, len(record.Meta.ProviderRequirements)) | ||
for _, req := range record.Meta.ProviderRequirements { | ||
pReqs[req.Source] = req.VersionConstraints | ||
Check failure on line 40 in internal/features/stacks/jobs/schema.go GitHub Actions / test (ubuntu-latest)
Check failure on line 40 in internal/features/stacks/jobs/schema.go GitHub Actions / test (ubuntu-latest)
Check failure on line 40 in internal/features/stacks/jobs/schema.go GitHub Actions / test (windows-latest)
Check failure on line 40 in internal/features/stacks/jobs/schema.go GitHub Actions / test (windows-latest)
Check failure on line 40 in internal/features/stacks/jobs/schema.go GitHub Actions / test (macos-latest)
|
||
} | ||
|
||
missingReqs, err := schemaStore.MissingSchemas(pReqs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(missingReqs) == 0 { | ||
// avoid preloading any schemas if we already have all | ||
return nil | ||
} | ||
|
||
for _, pAddr := range missingReqs { | ||
err := globalState.PreloadSchemaForProviderAddr(ctx, pAddr, fs, schemaStore, logger) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.