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

Preferred refactorings #29587

Open
mjbvz opened this issue Jan 25, 2019 · 1 comment
Open

Preferred refactorings #29587

mjbvz opened this issue Jan 25, 2019 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jan 25, 2019

Problems

  • Refactorings such as extract function and extract constant may return multiple possible locations where the code could be extracted to. In many cases however, the user would just like to quick extract something to a reliable location and continue on.

  • extract function is always returned alongside extract constant. However it is often desirable to extract to a constant instead of a function when possible.

Proposal
In the TS Server protocol, mark some refactoring as a preferred refactorings. Editors could use this information to automatically select the preferred refactoring in the list or even quick apply it without any user input (see microsoft/vscode#62110 for VS Code's proposal on this)

Preferred refactorings would let users set up actions such as extract constant that reliably extract to the nearest scope with a single action or keyboard shortcut. The UX behavior for this type of action:

  • If only a single isPreferred refactoring is returned, apply it automatically.

  • If multiple preferred refactorings are returned, show a list of the preferred refactorings that the user can select from

The normal refactor context menu with full list of refactorings would continue to display the full list of refactorings.

We can start conservative with which refactorings are preferred:

  • For extract constant, extract to local const
  • For extract function, extract to function at the scope of the parent function
  • For extract function in a method, extract to a method

Related to a similar proposal for quick fixes #29450

mjbvz added a commit to microsoft/vscode that referenced this issue Jan 28, 2019
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 4, 2019
@mjbvz mjbvz added the VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone label Oct 13, 2021
@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 13, 2021

Marking as a priority since this is a smaller feature that would better align TS with the LSP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Projects
None yet
Development

No branches or pull requests

2 participants