Renaming variable changes all instances except on `readarray`
Opened this issue · 1 comments
Code editor
Neovim
Platform
macOS Sequoia 15.5
Version
5.6.0
What steps will reproduce the bug?
Take this function:
tmpl::add() {
[[ $1 && $2 ]] || {
die e "add: source or targets is an empty string"
help >&2
exit 1
}
local tmplstr targets=()
$EDITOR "$PREFIX/$1"
readarray -td: targets <<<"$2"
tmplstr="{{ template \"${PREFIX#*.chezmoitemplates/}/$1\" . }}"
for f in "${targets[@]}"; do
echo "$tmplstr" >"$f"
done
}How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
All instances all the variable should be renamed.
What do you see instead?
With the cursor over any instance of targets except for the one on readarray, if you rename it, all instances are renamed correctly, except for the one on readarray.
If the cursor is over the targets on readarray and you try to rename it, you'd be told that there's nothing to rename.
Additional information
This might be somewhat similar to #1183
Hi, yes, you're right, this is similar/the same to #1183 in that targets is typed as word instead of variable_name by tree-sitter-bash and that's why it isn't being renamed. The solution is also the same, check if the word within the readarray command should be considered a variable and rename it if yes. Implementing it might be easier this time around since I might have laid some groundwork for this type of checking in #1221, though I'm not sure if I'll have any time soon to fix this issue. Would be happy to answer questions if anyone else is willing to give it a go.
As an aside, there's probably other similar/same cases as this where tree-sitter-bash considers a variable as a word instead of as a variable_name and that's why it won't be renamed. Maybe we can collate those cases in the future so we can address them in a more generic fashion.