Skip to content

feat: Add values-file completions and createCompletionItem helper - #131

Open
diofeher wants to merge 7 commits into
feat/values-file-hover-definitionfrom
feat/completion-enhancements
Open

feat: Add values-file completions and createCompletionItem helper#131
diofeher wants to merge 7 commits into
feat/values-file-hover-definitionfrom
feat/completion-enhancements

Conversation

@diofeher

Copy link
Copy Markdown
Contributor

Summary

Ports #55's completion enhancements while keeping main's store.FileType as the canonical enum (deliberately does not introduce PR #55's duplicate TerragruntFileType).

  • createCompletionItem helper reduces snippet-construction boilerplate across block completions (all Kind=Class).
  • newStackCompletions refactored to use the helper.
  • newValuesCompletions added with values and dependency block snippets; FileTypeValues now routes through it (previously returned an empty list).
  • Tests: positive cases for values-file routing (dep \u2192 dependency, val \u2192 values).

Stacked on #130. Final PR in the four-part cherry-pick of #55.

Test plan

  • go build ./...
  • go test ./internal/...
  • golangci-lint run \u2014 0 issues
  • Manual: in VS Code dev mode, type dep inside a terragrunt.values.hcl and confirm the dependency snippet appears.

Introduce three focused packages ported from PR #55 to support
stack/values-file features in subsequent PRs:
- internal/ast/config: ConfigAST interface with include/dependency
  label extraction and include-scope building.
- internal/ast/stack: StackAST interface with unit/stack block
  helpers (FindUnitAt, FindStackAt, source/path getters).
- internal/stackutils: LookupUnitPath and LookupStackPath against
  a parsed *config.StackConfig.
Relocate IsIncludeBlock, IsDependencyBlock, GetNodeIncludeLabel,
GetNodeDependencyLabel and the Includes scope out of internal/ast
and into internal/ast/config. Include/dependency are config-file
concerns and do not belong on the generic IndexedAST. Stack and
values files get their own AST packages in follow-ups.

- definition.GetDefinitionTargetWithContext now wraps store.AST in
  astconfig.NewConfigAST and calls GetIncludeLabel/GetDependencyLabel.
- Drop corresponding tests from internal/ast/ast_test.go; equivalent
  coverage lives in internal/ast/config/config_test.go.
Port PR #55's stack handlers, adapted to main's unified store.Store
(gated on FileType) and the ast/stack + stackutils foundation packages
from the prior commit.

- hover/stack.go: GetStackHoverTargetWithContext returns hover info
  for unit/stack blocks, source attributes, and path attributes.
  Contexts: HoverContextStackUnit/Source/Path/Block.
- definition/stack.go: GetStackDefinitionTargetWithContext navigates
  from unit/stack blocks to their source modules and resolved paths.
  ResolveUnitSourceLocation prefers main.tf, falls back to the first
  *.tf file, then the source directory itself. ResolveStackSourceLocation
  prefers terragrunt.stack.hcl, falls back to the directory.
- resolveBlockPath honors no_dot_terragrunt_stack when set on the
  matching unit/stack entry in the parsed StackConfig.
Replace the single-FileType early-return guard in State.Hover and
State.Definition with a switch on FileType, routing FileTypeUnit to
the existing unit logic and FileTypeStack to the new handlers added
in the prior commit.

- Hover: adds hoverStack dispatch and four stack-specific HoverResponse
  constructors (unit / source / path / block).
- Definition: adds definitionStack dispatch. Unit/stack source contexts
  resolve via ResolveUnitSourceLocation / ResolveStackSourceLocation;
  path contexts return the already-resolved target directly.
- state_test.go: extends TestState_Hover_StackFile and
  TestState_Definition_StackFile into real end-to-end assertions for
  unit source/path hover popups and unit-source navigation.
Port PR #55's values handlers, adapted to main's unified store.Store.

- hover/values.go: GetValuesHoverTargetWithContext detects
  dependency.<name>.<output> references and plain variable words.
  Contexts: HoverContextValuesVariable, HoverContextValuesDependency.
- definition/values.go: GetValuesDefinitionTargetWithContext detects
  dependency references. ResolveValuesDependencyPath searches common
  sibling/parent directory layouts for the dependency's terragrunt.hcl.
Extend the Hover and Definition switch to route FileTypeValues
through the new values handlers.

- hoverValues builds markdown popups for variables and dependency
  references (newValuesVariableHoverResponse / newValuesDependencyHoverResponse).
- definitionValues resolves dependency references to the matching
  terragrunt.hcl via ResolveValuesDependencyPath.
- Rewrite TestState_Hover_ValuesFile to assert real popups and add
  TestState_Definition_ValuesFile covering dependency navigation.
@diofeher
diofeher requested a review from yhakbar as a code owner April 17, 2026 10:35
@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eced01ba-d91a-4b70-abf1-06cfd40d6521

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/completion-enhancements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@diofeher
diofeher marked this pull request as draft April 17, 2026 10:42
Port PR #55's completion enhancements while keeping main's store.FileType
as the canonical file-type enum (no duplicate TerragruntFileType).

- Introduce createCompletionItem to reduce snippet-construction boilerplate
  in the stack and values block-completion lists (Kind=Class).
- Refactor newStackCompletions to use the helper.
- Add newValuesCompletions with 'values' and 'dependency' block snippets,
  and route FileTypeValues through it (previously returned an empty list).
- Add completion_test.go coverage for values-file routing.
@diofeher
diofeher force-pushed the feat/completion-enhancements branch from c131cf4 to df86add Compare April 17, 2026 10:44
@diofeher diofeher self-assigned this Apr 17, 2026
@diofeher
diofeher marked this pull request as ready for review April 17, 2026 10:48
@diofeher
diofeher force-pushed the feat/values-file-hover-definition branch from ee31994 to 5a47672 Compare April 27, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant