mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
fix(54283): Provide better UX when an invalid file is selected for 'move to file' refactoring (#54300)
This commit is contained in:
@@ -53,7 +53,9 @@ import {
|
||||
getRelativePathFromFile,
|
||||
getSynthesizedDeepClone,
|
||||
getUniqueName,
|
||||
hasJSFileExtension,
|
||||
hasSyntacticModifier,
|
||||
hasTSFileExtension,
|
||||
hostGetCanonicalFileName,
|
||||
Identifier,
|
||||
ImportDeclaration,
|
||||
@@ -162,8 +164,12 @@ registerRefactor(refactorNameForMoveToFile, {
|
||||
Debug.assert(actionName === refactorNameForMoveToFile, "Wrong refactor invoked");
|
||||
const statements = Debug.checkDefined(getStatementsToMove(context));
|
||||
Debug.assert(interactiveRefactorArguments, "No interactive refactor arguments available");
|
||||
const edits = textChanges.ChangeTracker.with(context, t => doChange(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences));
|
||||
return { edits, renameFilename: undefined, renameLocation: undefined };
|
||||
const targetFile = interactiveRefactorArguments.targetFile;
|
||||
if (hasJSFileExtension(targetFile) || hasTSFileExtension(targetFile)) {
|
||||
const edits = textChanges.ChangeTracker.with(context, t => doChange(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences));
|
||||
return { edits, renameFilename: undefined, renameLocation: undefined };
|
||||
}
|
||||
return { edits: [], renameFilename: undefined, renameLocation: undefined, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Cannot_move_to_file_selected_file_is_invalid) };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1002,6 +1002,7 @@ export interface RefactorEditInfo {
|
||||
renameFilename?: string;
|
||||
renameLocation?: number;
|
||||
commands?: CodeActionCommand[];
|
||||
notApplicableReason?: string;
|
||||
}
|
||||
|
||||
export type RefactorTriggerReason = "implicit" | "invoked";
|
||||
|
||||
Reference in New Issue
Block a user