mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
add getAvailableActions
This commit is contained in:
@@ -14,27 +14,45 @@ namespace ts.refactor.convertArrowFunctionOrFunction {
|
||||
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
|
||||
|
||||
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
|
||||
|
||||
const { file, startPosition } = context;
|
||||
|
||||
const node = getTokenAtPosition(file, startPosition);
|
||||
const func = getContainingFunction(node);
|
||||
if (!func || !(isFunctionExpression(func) || isArrowFunction(func)) || rangeContainsRange(func.body, node)) return undefined;
|
||||
|
||||
const possibleActions: RefactorActionInfo[] = [];
|
||||
|
||||
if (isArrowFunction(func)) {
|
||||
if (isVariableDeclaration(func.parent)) {
|
||||
possibleActions.push({
|
||||
name: toNamedFunctionActionName,
|
||||
description: toNamedFunctionActionDescription
|
||||
});
|
||||
}
|
||||
|
||||
possibleActions.push({
|
||||
name: toAnonymousFunctionActionName,
|
||||
description: toAnonymousFunctionActionDescription
|
||||
});
|
||||
}
|
||||
else {
|
||||
possibleActions.push({
|
||||
name: toArrowFunctionActionName,
|
||||
description: toArrowFunctionActionDescription
|
||||
});
|
||||
}
|
||||
|
||||
return [{
|
||||
name: refactorName,
|
||||
description: refactorDescription,
|
||||
actions: [
|
||||
{
|
||||
name: toAnonymousFunctionActionName,
|
||||
description: toAnonymousFunctionActionDescription
|
||||
},
|
||||
{
|
||||
name: toNamedFunctionActionName,
|
||||
description: toNamedFunctionActionDescription
|
||||
},
|
||||
{
|
||||
name: toArrowFunctionActionName,
|
||||
description: toArrowFunctionActionDescription
|
||||
}
|
||||
]
|
||||
actions: possibleActions
|
||||
}];
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined {
|
||||
context;
|
||||
actionName;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user