You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the RenameVariablePrefix function has the limitation as mentioned in the comment:
// The search and replacement traversals must be the same length, or this
// method will panic. Only attribute access operations can be matched and
// replaced. Index steps never match the prefix.
This means, following test cases on top of this test will not work:
{
Name:"attr traverse of a relative traversal expr sourced by a index expr",
Config: `resource "foo""b" {
count =3
name = foo.a[count.index].name
}`,
OldVar: []string{"foo", "a", "name"},
NewVar: []string{"foo", "a", "alias"},
Want: `resource "foo""b" {
count =3
name = foo.a[count.index].alias
}`,
},
This is quite a limitation for applications to refactor HCL files for use cases like a language server.
One reason that RenameVariablePrefix not work for above hcl is because the Expression.Variables() in hclsyntax returns partial traversal for cases like the latter case, that the internal walking logic for hclsyntax.RelativeTraversalExpr only tackles with its Source component, but ignore the Traversal component at all.
Whilst the JB HCL plugin somehow could manage this case. So I would like to see the official hclwrite package could also support this.
The text was updated successfully, but these errors were encountered:
Currently, the
RenameVariablePrefix
function has the limitation as mentioned in the comment:This means, following test cases on top of this test will not work:
This is quite a limitation for applications to refactor HCL files for use cases like a language server.
One reason that
RenameVariablePrefix
not work for above hcl is because theExpression.Variables()
inhclsyntax
returns partial traversal for cases like the latter case, that the internal walking logic forhclsyntax.RelativeTraversalExpr
only tackles with itsSource
component, but ignore theTraversal
component at all.Whilst the JB HCL plugin somehow could manage this case. So I would like to see the official
hclwrite
package could also support this.The text was updated successfully, but these errors were encountered: