-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Inline variable from identifier should inline its reference #210
Comments
Thanks for the suggestion. It's a very reasonable expectation indeed. The behavior depicted here isn't much the result of a conscious decision, but a fallback. Today, the refactoring doesn't work from the variable identifier ( This would be a nice improvement. I anticipate we'll need to handle some questions:
|
Q1: I'm not sure about the mechanics of what happens (tokenization, etc.), but... purely from the standpoint of how a human parses it, you select the identifier, and expect that identifier to be replaced with whatever it points to. The questions seem a bit too tied to implementation details for me to offer anything substantial, but I can say this: This is not reinventing the wheel. Other IDEs exist out there with similar functionality. You can examine how the feature works there and copy it. So the answers have already been determined, should you decide to seek them out. And copying behaviour from other places has the added benefit of avoiding mismatched expectations. One place where I know this already works is in Jetbrains IDEs. |
Regarding the question of scope, I think it's simpler than that; I would not expect it to do anything unless the cursor is touching a variable name. Trying to infer which variable to associate with every random cursor position in the document would be chaos, and nested scopes would make it a coin toss. I've forgotten practically everything about Jetbrains' Intellij except this feature and how the diff editor had copy left/right. It did this one really well, though. It still gets complicated if there is more than one usage. Theirs pops up a dialog that asks if you want to inline just that one, all of them and remove the declaration. Theirs goes further with methods, but I wouldn't even attempt to cover the cases of object properties or methods in JS, as that opens the can of worms for when those objects are passed out of the scope of the current file. Theirs does search the whole project and do the refactor, but at least years ago when I used it, it did so horribly for languages that weren't compiled. |
Describe what's missing
The extension seems to inline the top-most variable, instead of the selected variable.
(Initially I thought this was a bug, but it turned out to be a difference of expectations.)
How to reproduce
Try to inline doink by selecting it's usage in waffles.
Expected behavior
Current behavior
Additional information
And it doesn't indent things properly.
🧙 Add any other context about the problem here.
I first considered this a bug, but looking at it more, it seems to be a difference of expectation. When I select the usage of a variable, I expect to inline that, and all other usages.
The text was updated successfully, but these errors were encountered: