eclipse-jdt / eclipse-jdt/eclipse.jdt.ui
Names entered for extracted variables are occasionally replaced with suggestions
- Dominant language
- Java
- Stars
- 59
- Forks
- 127
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 35
Description
I see some inconsistent behaviour with naming extracted variables. Consider the following code:
```java
StringBuilder sb = new StringBuilder();
sb.append("foo").append("bar");
```
If I highlight `sb.append("foo")` and start a Quick Fix to extract a variable, the UI will present me with the option to name the new variable and offer some suggestions (eg `builder`, `stringBuilder`, `apply`). If I hit "B" the text editor will show the following:
If I now hit enter, the _suggestion_ is inserted rather than the text I entered.
However, if I instead tab to a usage of the new variable (not the declaration) and hit 'B' there, the suggestions disappear. If I then hit enter, I get exactly the text I entered.
### Some observations and thoughts:
In my opinion, it doesn't make much sense that the same interaction in these two variable name editing contexts would behave differently.
In my usage I notice this while extracting short-lived variables which I often give very terse names (one or two characters); these names will often, but not always, match the first letter of a suggestion. This behaviour left me feeling as though the editor is randomly ignoring my input.
I believe users entering longer names are less likely to have any issues.
A standard "rename variable" action is much less eager to insert a suggestion. This is the behaviour I would prefer in all cases of the "extract variable" action.
Contributor guide
Research direction
Reproduce the extract-variable Quick Fix with the shown StringBuilder example. Compare entering a name at the declaration with entering it at a usage, then verify that pressing Enter preserves the typed name in both contexts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100