Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming a variable changes all instances except those made on read #1183

Open
LeonardoMor opened this issue Sep 13, 2024 · 6 comments · May be fixed by #1221
Open

Renaming a variable changes all instances except those made on read #1183

LeonardoMor opened this issue Sep 13, 2024 · 6 comments · May be fixed by #1221

Comments

@LeonardoMor
Copy link

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.

@mcecode
Copy link
Contributor

mcecode commented Sep 13, 2024

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.

@LeonardoMor
Copy link
Author

Got it thanks.

Should I open an issue with tree-sitter?

@mcecode
Copy link
Contributor

mcecode commented Sep 14, 2024

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 answer

Everything after read can be typed as variable_name, but what about:

read -p prompt answer

Now 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.

@LeonardoMor
Copy link
Author

The way you explain it, it makes more sense to handle it at the LSP level.

@mcecode mcecode linked a pull request Nov 10, 2024 that will close this issue
@mcecode
Copy link
Contributor

mcecode commented Nov 10, 2024

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.

@LeonardoMor
Copy link
Author

Thanks.

Will test soon and let you know.

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 a pull request may close this issue.

2 participants