Renaming a variable changes all instances except those made on `read`
LeonardoMor opened this issue ยท 7 comments
Code editor
Neovim
Platform
Linux
Version
5.4.0
What steps will reproduce the bug?
Any code where a variable is set and then potentially reset by the read command. For example, on this snippet:
CASE="$2"
# Check for arguments, if we didn't receive them, ask for them
if [[ -z $CASE ]]; then
read -rp "Enter case number (must be 8-10 numerals): " CASE
fi
TARGETDIR="/srdata/$CASE"Renaming CASE will change it everywhere except for the instance on read -rp "Enter case number (must be 8-10 numerals): " CASE.
How often does it reproduce? Is there a required condition?
Can be reproduced all the time.
What is the expected behavior?
The variable should be renamed everywhere.
What do you see instead?
Rename skips instances of the variable used with the read command.
Additional information
There are other instances of variables being used without the usual $. For example, you can omit the $ inside arithmetic $((...)). I have not tested if these instances are also skipped by the rename.
Hi, I'm the one who implemented the rename symbol capability. This is a known limitation as the parser we use (tree-sitter-bash) doesn't type CASE as variable_name but as word. You can try out your example in their playground to check for yourself.
As for arithmetic expansions, renaming should work as expected since it was raised in #1134 and fixed in #1148.
Got it thanks.
Should I open an issue with tree-sitter?
You can try, but I'm not sure if they'd be willing to change the current behavior since a fix would require treating read differently from other commands and making the parser aware of flags. For example, the following would be simple enough:
read answerEverything after read can be typed as variable_name, but what about:
read -p prompt answerNow the parser needs to be aware that -p means that prompt is a word and answer is a variable_name.
We might be able to handle this as a special case from the language server since it's a common enough use case, but I'm not sure if I'll have the time to look into it any time soon.
The way you explain it, it makes more sense to handle it at the LSP level.
Hi, so I made a PR (#1221) to address this. I'd appreciate it if you can give the changes a try and see if they work for your use case.
Thanks.
Will test soon and let you know.
Sorry I took so long.
I confirmed this works as intended. Thanks for taking the time for this.