-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[WIP] Rework ordering of refactorings & fixes with/out selection #38271
base: main
Are you sure you want to change the base?
Conversation
selection. Previously having empty selection caused refactorings to have low-priority in codeactions menu. It was introduced in time when only very few refactorings accepted selection and when there were very little non-selection based refactorings. Nowadays the distinction between some codefixes and refactorings is blurry and as such should both be treated the same way, regardless of selection.
Related: #35525 |
i think we need more examples. Because my gut is telling me this is a bad idea. Specifically, codefixes can have UI affordances (squiggles, fading, dots, etc.), while refactorings don't. I'm def very wary of potentially prioritizing something that is effectively invisible on the line versus something visible and nearby. Note: this applies to fixes that are visible. If a codefix has no UI affordance (i.e. is 'refactoring-only') then it should be bucketed together. |
I agree with that. But if we want to prioritize "visible" codefixes then we should prioritize codefixes as whole. And not when there's selection / isn't, IMO (and also, as you say, we should do that only for non-invisible ones). I can see how the "when user selects he want's to refactor" made sense back when there were only few (and obviously) selection based refactorings. But it simply doesn't hold true anymore. Especially given most of refactorings previously didn't work with selection. |
I.e. simply bumping priority for Codefixes that fix "Warning" (High), or visible info "?high?" would be a way more consistent solution IMO. |
Yes. I'd prefer a larger rethinking here. I personally agree that refactoring vs fix isn't the relevant axis. However the code we have now serves an important purpose. I don't think we should get rid of it until we have implemented other rules (like what I mentioned above) to handle those sorts of cases |
Glossary:
Problem scope:Explicitly suggested CodeActions should be ordered higher than all other CodeActions, regardless if they're CodeFixes or CodeRefactorings. The rationale is that there might be a number of CodeActions and if we suggested one explicitely there's a high chance a user might really want to perform it. Generally, we only explicitly suggest things a user set (editorconfig, ...) or that really should be done (fixes for warnings, ...). Current situation:All CodeActions are ordered by their priority first, and by the distance of the span they change to current caret/selection second. If there's no selection all Refactorings get changed to low priority, essentially causing CodeFixes being top, Refactorings bottom. Due to the fact that most refactorings have not historically been offered for selection (fixing that as part of: #35525) it can be assumed that users didn't/don't use it except for situations when they wanted to invoke the few ones that worked with selection explicitly, such as That in combination with the fact that all explicitly suggested CodeActions are Codefixes means that the current behavior is (given current user behaviour) not all that far from potentially desired state. Since users don't use selection, the priority of refactorings gets set to low, and codefixes (some/?most of which ore explicitly suggested) get ordered to be on top. Issues with current situation:With recent fix of "not offering refactorings on selection" and adding more and more hidden diagnostics + codefix (essentially a refactoring), however, the UX is starting to be more problematic (as shown in first comment's screenshots). Firstly, users will now be able to use selection for all refactorings which will lead to inconsistent experience where e.g. selection of a keyword leads to substantially different ordering to e.g. having caret in the keyword. Secondly, adding more hidden diagnostics + codefix combos (like add discard on 2nd before screenshot above) leads to it being on top for caret location (because it's Codefix) even though it's not a explicitly suggested (i.e. there's no reason to believe it should be offered more prominently than any of refactorings) one and is "quite far from current caret location". |
Proposed solution:First, remove any current priority changes based on selection/refactoring.vs.codefix due to abovementioned problems. Then, extend CodeFixService so that it modifies priority of CodeActions for CodeFixes based on their diagnostic's severity. Currently most A CodeActions are Medium priority, only few (add missing usings, inline rename) are high, and few are low (wrap arguments, ...). The EDIT: The priority field gets translated to Option1:Plainly change priority based on their diagnostic's severity (1.1):
Or maybe (1.2):
Issues:
Benefits:
Option2:Extend
Issues:
Benefits:
|
Further observations:
|
Additional notes:
Going between 1.1 and 1.2 should be very simple, it's just a difference in mapping. |
cc @CyrusNajmabadi, thoughts? Will have design meeting next week and would love your input beforehand. |
My main thoughts are that I would drive this through specific problems we are solving. I.e.: this list of fixes is suboptimal. Figure out why, then tweak as necessary. I would not really want full scale changes without clear examples of how it improve things. |
Ok, I'll try to produce more examples. That said, I don't thing there're small tweaks possible. The current experience gets really surprising once selection is allowed more broadly and with more and more invisible diagnostics+codefix (add _) it gets super-weird. |
Current usage of priorities:
|
Instead of explicitely changing priority in the service we might want to just go with the change in this PR + change the way CodeFixes report their priority (?add helper that takes In that case we need to deal with the fact that all 3rd party (including refactorings) is
|
Changing CodeFixes so that they report priority based on Diagnostics: Issues:
Benefits:
|
Results from design meeting:
Implementation:
Notes:
|
Initial implementation done:
Remarks:
TODO (this PR):
TODO (future):
Current issue: |
Alternative approach to: 243d101 Since VS Platform needs to do reordering due to potentially other sources of LightBulb actions we need to translate PriorityBoost directly to Therefore to enable feature proposed in this PR we'd need to extend Such extension would, however, need to make sure that current/legacy High priority remains the Note: in addition to doing that updating VS's SuggestedActionSetComparer so that it takes into account current user selection instead of just caret position would also be beneficial. I.e. to make it consistent with changes in Roslyn done in here: https://github.com/dotnet/roslyn/pull/37941/files#diff-c115e9b22618dafba7dd3f8d6e2c4621 |
Previously having empty selection caused refactorings to have
low-priority in codeactions menu. It was introduced in time when only
very few refactorings accepted selection and when there were very little
non-selection based refactorings. Nowadays the distinction between some
codefixes and refactorings is blurry and as such should both be treated
the same way, regardless of selection.