use function-hcl API to load module and composition metadata#58
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the language server and fn-hcl-tools to use the newer function-hcl module-loading API (directory-based, composition.yaml metadata) so both tools can consistently load HCL source files, optional library files, and XRD metadata.
Changes:
- Switch module loading to
composition.yamlvia thefunction/api.LoadModuleAPI, including support for explicit library files. - Introduce a new internal
compositionpackage infunction/that handles loading, analysis, and txtar packaging from a directory. - Update examples/test fixtures and tooling to reflect directory-based packaging and
main.hclnaming in txtar scripts.
Reviewed changes
Copilot reviewed 42 out of 44 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| language-server/internal/funchcl/decoder/completion/testdata/.xrd.yaml | Removes old XRD metadata test fixture file. |
| language-server/internal/funchcl/decoder/completion/testdata/.gitignore | Ignores composition.yaml in completion decoder testdata. |
| language-server/internal/funchcl/decoder/completion/scaffold_test.go | Writes composition.yaml with xrd: top-level metadata for completion scaffolds. |
| language-server/internal/features/modules/store/store.go | Reuses function/api.XRD type via alias instead of redefining. |
| language-server/internal/features/modules/parser.go | Parses module from explicit sourceFiles list instead of scanning directory. |
| language-server/internal/features/modules/modules_test.go | Updates XRD metadata test to use composition.yaml with xrd: wrapper. |
| language-server/internal/features/modules/events.go | Loads XRD + source file list via function/api.LoadModule and parses those files. |
| language-server/internal/features/modules/api.go | Removes old .xrd.yaml constant definition. |
| language-server/go.mod | Adds dependency on github.com/crossplane-contrib/function-hcl/function and bumps several deps. |
| language-server/go.sum | Dependency resolution updates matching go.mod changes. |
| function/internal/composition/testdata/with-libs/main.hcl | New packaging/analyze fixture: module HCL using a library function. |
| function/internal/composition/testdata/with-libs/lib/bar.hcl | New fixture: library HCL file referenced by config. |
| function/internal/composition/testdata/with-libs/composition.yaml | New fixture: declares xrd and libraryFiles. |
| function/internal/composition/testdata/multi-hcl/a.hcl | New fixture: multi-file module input. |
| function/internal/composition/testdata/multi-hcl/b.hcl | New fixture: multi-file module input. |
| function/internal/composition/testdata/missing-lib/main.hcl | New fixture: missing library reference scenario. |
| function/internal/composition/testdata/missing-lib/composition.yaml | New fixture: config referencing a non-existent library file. |
| function/internal/composition/testdata/invalid-yaml-config/main.hcl | New fixture: invalid YAML config scenario. |
| function/internal/composition/testdata/invalid-yaml-config/composition.yaml | New fixture: intentionally invalid YAML. |
| function/internal/composition/testdata/invalid-hcl/main.hcl | New fixture: intentionally invalid HCL for analysis failure tests. |
| function/internal/composition/testdata/dir-only/main.hcl | New fixture: simple module directory with a single HCL file. |
| function/internal/composition/testdata/dir-as-lib/main.hcl | New fixture: directory specified as library file scenario. |
| function/internal/composition/testdata/dir-as-lib/lib/.gitkeep | Ensures lib/ directory exists in fixture. |
| function/internal/composition/testdata/dir-as-lib/composition.yaml | New fixture: libraryFiles points at a directory. |
| function/internal/composition/os-fs.go | Adds osFs implementation for the composition loader filesystem interface. |
| function/internal/composition/composition_test.go | Adds tests for directory-based packaging and analysis behavior. |
| function/internal/composition/composition.go | Implements config loading, file selection, txtar creation, and analysis helper. |
| function/internal/composition/api_test.go | Adds API-level test for Load, Package, and Analyze behavior. |
| function/internal/composition/api.go | Exposes Load, Package, and Analyze plus config/XRD/fs types. |
| function/example/user-function/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/spec-example/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/set-status/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/set-status-incomplete/src/expected.yaml | Updates expected diagnostic filenames from src/main.hcl to main.hcl. |
| function/example/set-status-incomplete/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/set-context/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/extra-resources-present/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/extra-resources-absent/src/expected.yaml | Updates expected diagnostic filenames from src/main.hcl to main.hcl. |
| function/example/extra-resources-absent/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/basic-resource/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/basic-resource-list/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/example/basic-locals/composition.yaml | Updates embedded txtar header path to -- main.hcl --. |
| function/cmd/fn-hcl-tools/tools.go | Switches CLI analyze/package to accept a directory and uses new composition package. |
| function/api/api.go | Exposes ConfigFile, FS, XRD, and adds LoadModule wrapper around composition loader. |
| function/.scripts/gen-comp.sh | Updates script generation to call fn-hcl-tools package with a directory (src/). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
958727e to
cfb141b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 44 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 48 out of 50 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
language-server/internal/features/modules/store/store.go:27
- The
Content.Files/Content.Diagscomments say the maps are keyed by “unqualified filename”, butfullParsenow uses thesourceFilesvalues returned byapi.LoadModuleas keys (which can include paths likelib/bar.hcl). Please update these comments (or normalize keys) so they accurately describe the data shape.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
As copilot correctly points out, this only allows modules that pull libraries from elsewhere to be processed correctly. Editing the library does not trigger reparse of the module that includes it. This will be done in a later commit, perhaps after we've done a release.