Skip to content

feat: Hover and go-to-definition for terragrunt.values.hcl - #130

Draft
diofeher wants to merge 9 commits into
feat/stack-file-hover-definitionfrom
feat/values-file-hover-definition
Draft

feat: Hover and go-to-definition for terragrunt.values.hcl#130
diofeher wants to merge 9 commits into
feat/stack-file-hover-definitionfrom
feat/values-file-hover-definition

Conversation

@diofeher

Copy link
Copy Markdown
Contributor

Summary

Adds hover popups and go-to-definition for terragrunt.values.hcl files, ported from #55 and adapted to main's unified Store + FileType architecture.

  • internal/tg/hover/values.go: hover info for plain variables and dependency.<name>.<output> references.
  • internal/tg/definition/values.go: navigate from dependency.<name> references to the matching terragrunt.hcl. ResolveValuesDependencyPath searches sibling/parent directory layouts.
  • internal/tg/state.go: extends the FileType switch in Hover and Definition with FileTypeValues dispatch. Adds hoverValues / definitionValues and two values-specific HoverResponse constructors.
  • Tests: rewrites TestState_Hover_ValuesFile for real popups and adds TestState_Definition_ValuesFile covering dependency navigation.

Stacked on #129.

Test plan

  • go build ./...
  • go test ./internal/...
  • golangci-lint run \u2014 0 issues
  • Manual: open a terragrunt.values.hcl, hover over variables and dependency references, F12 on a dependency reference to verify navigation.

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.
@diofeher
diofeher requested a review from yhakbar as a code owner April 17, 2026 10:30
@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: 8517bffe-ae63-43bd-93c3-e383168d856d

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/values-file-hover-definition

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.

yhakbar and others added 6 commits April 27, 2026 09:29
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
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.

Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
@diofeher
diofeher force-pushed the feat/values-file-hover-definition branch from ee31994 to 5a47672 Compare April 27, 2026 12:29
@diofeher
diofeher marked this pull request as ready for review April 27, 2026 12:33
@diofeher diofeher self-assigned this Apr 27, 2026
…' into feat/values-file-hover-definition

# Conflicts:
#	internal/tg/state.go
@diofeher

Copy link
Copy Markdown
Contributor Author

Tested and working fine.

@diofeher
diofeher force-pushed the feat/stack-file-hover-definition branch from ca2ece7 to dc9edaf Compare April 27, 2026 12:38
@diofeher
diofeher marked this pull request as draft May 5, 2026 21:52
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.

2 participants