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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use snippets for extract refactorings #50166

Open
mjbvz opened this issue Aug 3, 2022 · 0 comments
Open

Use snippets for extract refactorings #50166

mjbvz opened this issue Aug 3, 2022 · 0 comments
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Aug 3, 2022

Feature request

馃攷 Search Terms

  • Refactor / refactorings
  • Code action

Problem

Today our extract refactorings run in two stages:

  1. Extract to a new constant / function using a placeholder symbol name (such as newFunction)
  2. Rename the placeholder using a normal rename operation.

This has a few problems:

  • If the user quickly types, they end up typing into the editor before the rename input box shows up. This breaks the rename
  • This requires two calls to TSServer
  • The rename UX can feel a bit jarring since it shows a new box to users

Proposal

VS Code now supports including snippets in the workspace edits that extensions provide on refactorings. My proposal is that TS Server uses snippet syntax in the edit returned for extract method/constant so that users immediately start renaming the new function/constant instead of using the two phase flow we have to day

Example

For the TS:

1 + 2;

If I select 1 + 2 and select the extract to function in global scope refactoring, I should get the following snippet (note that I'm using VS Code's snippet annotation here):

${1:newFunction}();$0

function ${1:newFunction}() {
    1 + 2;
}

Typing would update both places where newFunction is used:

Screen Shot 2022-08-03 at 12 00 34 PM

Screen Shot 2022-08-03 at 12 00 39 PM

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Experience Enhancement Noncontroversial enhancements labels Aug 5, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 5, 2022
@RyanCavanaugh RyanCavanaugh added the Domain: Refactorings e.g. extract to constant or function, rename symbol label Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants