microsoft / microsoft/TypeScript

Preferred refactorings

Offen
#29,587 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion VS Code Priority
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit der Durchsicht der Antwort zur Umstrukturierung des TS Server-Protokolls und des zugehörigen Quick-Fix-Vorschlags in Issue #29450. Verfolgen Sie, wie die Ergebnisse von „extract constant“ und „extract function“ dargestellt werden, definieren Sie anschließend das hier beschriebene Verhalten für bevorzugte Umstrukturierungen und bestätigen Sie, dass die vollständige Liste der Umstrukturierungen weiterhin verfügbar ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.