mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Interactive refactor actions (#53915)
This commit is contained in:
@@ -586,6 +586,14 @@ export interface GetApplicableRefactorsRequest extends Request {
|
||||
export type GetApplicableRefactorsRequestArgs = FileLocationOrRangeRequestArgs & {
|
||||
triggerReason?: RefactorTriggerReason;
|
||||
kind?: string;
|
||||
/**
|
||||
* Include refactor actions that require additional arguments to be passed when
|
||||
* calling 'GetEditsForRefactor'. When true, clients should inspect the
|
||||
* `isInteractive` property of each returned `RefactorActionInfo`
|
||||
* and ensure they are able to collect the appropriate arguments for any
|
||||
* interactive refactor before offering it.
|
||||
*/
|
||||
includeInteractiveActions?: boolean;
|
||||
};
|
||||
|
||||
export type RefactorTriggerReason = "implicit" | "invoked";
|
||||
@@ -650,6 +658,12 @@ export interface RefactorActionInfo {
|
||||
* The hierarchical dotted name of the refactor action.
|
||||
*/
|
||||
kind?: string;
|
||||
|
||||
/**
|
||||
* Indicates that the action requires additional arguments to be passed
|
||||
* when calling 'GetEditsForRefactor'.
|
||||
*/
|
||||
isInteractive?: boolean;
|
||||
}
|
||||
|
||||
export interface GetEditsForRefactorRequest extends Request {
|
||||
|
||||
@@ -22,11 +22,11 @@ export function registerRefactor(name: string, refactor: Refactor) {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getApplicableRefactors(context: RefactorContext): ApplicableRefactorInfo[] {
|
||||
export function getApplicableRefactors(context: RefactorContext, includeInteractiveActions?: boolean): ApplicableRefactorInfo[] {
|
||||
return arrayFrom(flatMapIterator(refactors.values(), refactor =>
|
||||
context.cancellationToken && context.cancellationToken.isCancellationRequested() ||
|
||||
!refactor.kinds?.some(kind => refactorKindBeginsWith(kind, context.kind)) ? undefined :
|
||||
refactor.getAvailableActions(context)));
|
||||
refactor.getAvailableActions(context, includeInteractiveActions)));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -2971,10 +2971,10 @@ export function createLanguageService(
|
||||
return SmartSelectionRange.getSmartSelectionRange(position, syntaxTreeCache.getCurrentSourceFile(fileName));
|
||||
}
|
||||
|
||||
function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences = emptyOptions, triggerReason: RefactorTriggerReason, kind: string): ApplicableRefactorInfo[] {
|
||||
function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences = emptyOptions, triggerReason: RefactorTriggerReason, kind: string, includeInteractiveActions?: boolean): ApplicableRefactorInfo[] {
|
||||
synchronizeHostData();
|
||||
const file = getValidSourceFile(fileName);
|
||||
return refactor.getApplicableRefactors(getRefactorContext(file, positionOrRange, preferences, emptyOptions, triggerReason, kind));
|
||||
return refactor.getApplicableRefactors(getRefactorContext(file, positionOrRange, preferences, emptyOptions, triggerReason, kind), includeInteractiveActions);
|
||||
}
|
||||
|
||||
function getEditsForRefactor(
|
||||
|
||||
@@ -630,7 +630,13 @@ export interface LanguageService {
|
||||
/** @deprecated `fileName` will be ignored */
|
||||
applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
|
||||
|
||||
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): ApplicableRefactorInfo[];
|
||||
/**
|
||||
* @param includeInteractiveActions Include refactor actions that require additional arguments to be
|
||||
* passed when calling `getEditsForRefactor`. When true, clients should inspect the `isInteractive`
|
||||
* property of each returned `RefactorActionInfo` and ensure they are able to collect the appropriate
|
||||
* arguments for any interactive action before offering it.
|
||||
*/
|
||||
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string, includeInteractiveActions?: boolean): ApplicableRefactorInfo[];
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined;
|
||||
organizeImports(args: OrganizeImportsArgs, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
@@ -963,6 +969,12 @@ export interface RefactorActionInfo {
|
||||
* The hierarchical dotted name of the refactor action.
|
||||
*/
|
||||
kind?: string;
|
||||
|
||||
/**
|
||||
* Indicates that the action requires additional arguments to be passed
|
||||
* when calling `getEditsForRefactor`.
|
||||
*/
|
||||
isInteractive?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1761,7 +1773,7 @@ export interface Refactor {
|
||||
getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined;
|
||||
|
||||
/** Compute (quickly) which actions are available here */
|
||||
getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[];
|
||||
getAvailableActions(context: RefactorContext, includeInteractive?: boolean): readonly ApplicableRefactorInfo[];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
Reference in New Issue
Block a user