-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RefactorTriggerReason #38378
Add RefactorTriggerReason #38378
Changes from 35 commits
bac0465
02fa39a
c3828ed
1efcffc
0296254
55880ee
602ee99
f1127e6
c5343f1
53e8ed0
23f4dc9
57e856b
665e434
23e0064
f3751fb
96f210c
fbf6737
dc363f1
85e0d8b
df8ff65
3825d19
673a868
86122c4
d37f4c3
e565931
a07a79b
3e1e614
4971c7d
a7c07d6
c20908a
06d2461
f479279
2db0054
a86a2fa
ca58c0e
d88ea4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction { | |
} | ||
|
||
function getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[] { | ||
const { file, startPosition } = context; | ||
const info = getConvertibleArrowFunctionAtPosition(file, startPosition); | ||
const { file, startPosition, triggerReason } = context; | ||
const info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, JS doesn't have named arguments. Instead, when we're passing a boolean, we tend to give the parameter name as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't my intention to pass a named argument, but to pass whatever |
||
if (!info) return emptyArray; | ||
|
||
return [{ | ||
|
@@ -70,10 +70,12 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction { | |
return { renameFilename: undefined, renameLocation: undefined, edits }; | ||
} | ||
|
||
function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition: number): Info | undefined { | ||
function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition: number, userRequested = true): Info | undefined { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see the convenience of having this be called |
||
const node = getTokenAtPosition(file, startPosition); | ||
const func = getContainingFunction(node); | ||
if (!func || !isArrowFunction(func) || (!rangeContainsRange(func, node) || rangeContainsRange(func.body, node))) return undefined; | ||
// Only offer a refactor in the function body on explicit refactor requests. | ||
if (!func || !isArrowFunction(func) || (!rangeContainsRange(func, node) | ||
|| (rangeContainsRange(func.body, node) && !userRequested))) return undefined; | ||
|
||
if (isExpression(func.body)) { | ||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this a little confusing since the default elsewhere is implicit.