feat: rename, references, and go-to-definition for dependency block labels - #143
Draft
diofeher wants to merge 8 commits into
Draft
feat: rename, references, and go-to-definition for dependency block labels#143diofeher wants to merge 8 commits into
diofeher wants to merge 8 commits into
Conversation
…abels
Add LSP textDocument/rename and textDocument/prepareRename for three kinds
of identifiers in Terragrunt configs:
- Local variables (`locals { name = ... }` and `local.name` references)
- Dependency block labels (`dependency "name" {}` and `dependency.name.outputs.X`)
- Include block labels (`include "name" {}` and `include.name.X`)
Rename is module-aware: edits propagate across all `.hcl` files in the
same folder, honoring unsaved editor buffers via `s.Configs`. Stack and
values files are excluded.
Implementation is AST-based via `hclsyntax.VisitAll` over `ScopeTraversalExpr`
and `IndexedAST.Locals`/`Body.Blocks` for definitions. Prepare-rename returns
a range covering only the bare identifier (placeholder excludes `local.`
prefix and label quotes). New names are validated against the HCL identifier
grammar.
…include labels Reuse the AST walker and target-resolution introduced for rename to power find-all-references on the same three identifier kinds. Honors the LSP `includeDeclaration` flag. The `rename.Occurrence` type gains an `IsDefinition` flag so references can filter out the declaration site when the client requests references only.
…rsal references
`textDocument/definition` previously only fired when the cursor was on an
`include "X" {}` label or a `dependency "X" { config_path = ... }` attribute.
Extend it to also fire on traversal references:
- `local.X` jumps to the `X = ...` declaration in the locals block (same
file or any sibling .hcl file in the module folder).
- `include.X.Y` jumps to the file referenced by `include "X" { path = ... }`
(existing path-resolution behavior, now reachable from references too).
- `dependency.X.outputs.Y` jumps to the dependent unit's `terragrunt.hcl`
(existing path-resolution behavior, now reachable from references too).
Implementation reuses `ast.MinReferenceTraversalLen` and the rename package's
`FindAllOccurrences` for the local-declaration lookup. The Unit-only file-type
guard is replaced with `canRename` so go-to-definition also works on auxiliary
HCL files (e.g., `common.hcl`).
Remove rename, references, and go-to-definition support for include block labels and `include.X.Y` traversal references. Keeping this PR focused on locals and dependency labels. Include support has additional complexity worth landing in a dedicated PR: - The Terragrunt parser emits "Unsupported attribute" / "Unknown variable" diagnostics for `include.X` traversals at LS time, which need a separate diagnostic-filter change in `internal/tg/parse.go`. - `find_in_parent_folders` failures cascade into multiple diagnostic kinds, expanding the filter scope. - Include label rename also requires updating the `path` attribute that references the parent file, which is out of scope for the symmetric identifier-rename pattern this PR ships.
Remove rename, references, and go-to-definition support for
`dependency "X" {}` block labels and `dependency.X.outputs.Y`
traversal references. Keeping this PR focused on locals.
Existing dependency support (cursor on `dependency` block label or on
`config_path` attribute jumping to the dependent unit) is unaffected
and continues to work via `ast.GetNodeDependencyLabel`.
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
8 tasks
diofeher
force-pushed
the
feat/rename-dependency-blocks
branch
from
May 5, 2026 11:13
0ffcf6e to
82e055b
Compare
- traversalDefinitionTarget now only handles `local`; comment updated. - Switch test code from context.Background() to t.Context() so the context is automatically canceled when the test ends.
This reverts commit cecfe0e.
diofeher
force-pushed
the
feat/rename-dependency-blocks
branch
from
May 5, 2026 15:17
82e055b to
a064794
Compare
diofeher
marked this pull request as draft
May 5, 2026 19:16
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builds on top of #141. Adds the same three LSP features to terragrunt-ls for
dependencyblock labels:textDocument/prepareRename+textDocument/renametextDocument/referencestextDocument/definitionextended todependency.X.outputs.Ytraversal referencesdependency "vpc" {}dependency.vpc.outputs.XWhat changed
RenameContextDependencyand the dependency case intraversalDefinitionTargetthat were factored out of feat: rename, references, and go-to-definition for locals #141 to keep that PR scoped to locals.blockLabelTargetso cursor on adependency "X"block label resolves to a renameable target.definitionOccurrencesnow also collects the dependency block label as a definition site so renames update both the label declaration and everydependency.X.outputs.Yreference.Existing pre-PR behavior (cursor on
dependency "X"label orconfig_pathattr jumping to the dependent unit'sterragrunt.hcl) is unchanged and continues to work viaast.GetNodeDependencyLabel.Test plan
go build ./...go test ./...— 163 passinggolangci-lint run ./...— 0 issuesdependency "vpc" {}label updates the label and everydependency.vpc.outputs.*reference in the same file.dependency "vpc"highlights the label declaration plus everydependency.vpc.outputs.*reference.dependency.vpc.outputs.idjumps to the dependent unit'sterragrunt.hcl.