Skip to content

Sort extract constant refactoring before extract function #29589

Closed

Description

@mjbvz

Search terms

  • Refactor, refactorings
  • extract

Feature request
When both extract const and extract function refactorings are available for a piece of code, show the extract const before extract function

VS Code shows the refactorings in the order that TS returns them to us in.

Related to #29587

Activity

  1. markusjohnsson commented on Dec 21, 2019

    @markusjohnsson
    Contributor

    Woah, is this at all based on analytics, or just a hunch from a couple of reporters? I’m not sure, as I use both, but I think I “extract to function” a more often.

  2. andrewbranch commented on Dec 22, 2019

    @andrewbranch
    Member

    I can’t speak for Matt Bierner (@mjbvz) or VS Code, but keep in mind that “extract to function” is available far more often than “extract to constant.” Only single expressions can be extracted to constants, while anything from a single expression to multiple consecutive statements can be extracted to a function. I suspect the reasoning is that it would be rare for the entire body of a function to be a return statement of a single expression (e.g. function getDuration() { return 60 * 1000; }), “extract to constant” probably makes more sense whenever it’s available (e.g. const duration = 60 * 1000).

    Hopefully there were analytics backing this, but I simply mean to caution that using “extract to function” more often than “extract to constant” isn’t a good proxy measure, since they’re not always coincident.

  3. markusjohnsson commented on Dec 23, 2019

    @markusjohnsson
    Contributor

    Thanks Andrew Branch (@andrewbranch) , of course, I didn’t think of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Domain: LS: Refactoringse.g. extract to constant or function, rename symbolDomain: LS: TSServerIssues related to the TSServerFixedA PR has been merged for this issueIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions