You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sort extract constant refactoring before extract function #29589
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.
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.
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.
Activity
markusjohnsson commentedon Dec 21, 2019
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.
andrewbranch commentedon Dec 22, 2019
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.
markusjohnsson commentedon Dec 23, 2019
Thanks Andrew Branch (@andrewbranch) , of course, I didn’t think of that.