microsoft / microsoft/TypeScript

Preferred refactorings

Ouverte
#29,587 1 commentaire 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

In Discussion Suggestion VS Code Priority
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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 https://github.com/Microsoft/vscode/issues/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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par examiner la réponse concernant la refactorisation du protocole TS Server et la proposition de quick-fix associée dans l’issue #29450. Suivez la manière dont les résultats de extract constant et extract function sont représentés, puis définissez le comportement de refactorisation préféré décrit ici et confirmez que la liste complète des refactorisations reste disponible.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.