Skip to content

Commit

Permalink
feat: make Terraform functions available in stacks files
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm committed Jul 31, 2024
1 parent 1ca689b commit 92b3693
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/features/stacks/decoder/path_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/hcl-lang/decoder"
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/reference"
"github.com/hashicorp/hcl-lang/schema"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform-ls/internal/features/stacks/ast"
"github.com/hashicorp/terraform-ls/internal/features/stacks/state"
Expand Down Expand Up @@ -100,6 +101,7 @@ func stackPathContext(record *state.StackRecord, stateReader CombinedReader) (*d
ReferenceOrigins: make(reference.Origins, 0),
ReferenceTargets: make(reference.Targets, 0),
Files: make(map[string]*hcl.File, 0),
Functions: mustFunctionsForVersion(version),
}

// TODO: Add reference origins and targets if needed
Expand Down Expand Up @@ -179,3 +181,12 @@ func (pr *PathReader) Paths(ctx context.Context) []lang.Path {

return paths
}

func mustFunctionsForVersion(v *version.Version) map[string]schema.FunctionSignature {
s, err := tfschema.FunctionsForVersion(v)
if err != nil {
// this should never happen
panic(err)
}
return s
}

0 comments on commit 92b3693

Please sign in to comment.