1/* @internal */ 2namespace ts.refactor { 3 // A map with the refactor code as key, the refactor itself as value 4 // e.g. nonSuggestableRefactors[refactorCode] -> the refactor you want 5 const refactors = new Map<string, Refactor>(); 6 7 /** @param name An unique code associated with each refactor. Does not have to be human-readable. */ 8 export function registerRefactor(name: string, refactor: Refactor) { 9 refactors.set(name, refactor); 10 } 11 12 export function getApplicableRefactors(context: RefactorContext): ApplicableRefactorInfo[] { 13 return arrayFrom(flatMapIterator(refactors.values(), refactor => 14 context.cancellationToken && context.cancellationToken.isCancellationRequested() || 15 !refactor.kinds?.some(kind => refactorKindBeginsWith(kind, context.kind)) ? undefined : 16 refactor.getAvailableActions(context))); 17 } 18 19 export function getEditsForRefactor(context: RefactorContext, refactorName: string, actionName: string): RefactorEditInfo | undefined { 20 const refactor = refactors.get(refactorName); 21 return refactor && refactor.getEditsForAction(context, actionName); 22 } 23} 24