mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-02 14:48:32 -05:00
move to code actions update and tests (#58548)
This commit is contained in:
@@ -176,7 +176,7 @@ registerRefactor(refactorNameForMoveToFile, {
|
||||
}
|
||||
/** If the start/end nodes of the selection are inside a block like node do not show the `Move to file` code action
|
||||
* This condition is used in order to show less often the `Move to file` code action */
|
||||
if (context.endPosition !== undefined) {
|
||||
if (context.triggerReason === "implicit" && context.endPosition !== undefined) {
|
||||
const startNodeAncestor = findAncestor(getTokenAtPosition(file, context.startPosition), isBlockLike);
|
||||
const endNodeAncestor = findAncestor(getTokenAtPosition(file, context.endPosition), isBlockLike);
|
||||
if (startNodeAncestor && !isSourceFile(startNodeAncestor) && endNodeAncestor && !isSourceFile(endNodeAncestor)) {
|
||||
|
||||
@@ -5,9 +5,13 @@ import {
|
||||
Debug,
|
||||
Diagnostics,
|
||||
emptyArray,
|
||||
findAncestor,
|
||||
getLineAndCharacterOfPosition,
|
||||
getLocaleSpecificMessage,
|
||||
getTokenAtPosition,
|
||||
hostGetCanonicalFileName,
|
||||
isBlockLike,
|
||||
isSourceFile,
|
||||
LanguageServiceHost,
|
||||
last,
|
||||
ModuleKind,
|
||||
@@ -40,6 +44,16 @@ registerRefactor(refactorName, {
|
||||
kinds: [moveToNewFileAction.kind],
|
||||
getAvailableActions: function getRefactorActionsToMoveToNewFile(context): readonly ApplicableRefactorInfo[] {
|
||||
const statements = getStatementsToMove(context);
|
||||
|
||||
const file = context.file;
|
||||
if (context.triggerReason === "implicit" && context.endPosition !== undefined) {
|
||||
const startNodeAncestor = findAncestor(getTokenAtPosition(file, context.startPosition), isBlockLike);
|
||||
const endNodeAncestor = findAncestor(getTokenAtPosition(file, context.endPosition), isBlockLike);
|
||||
if (startNodeAncestor && !isSourceFile(startNodeAncestor) && endNodeAncestor && !isSourceFile(endNodeAncestor)) {
|
||||
return emptyArray;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.preferences.allowTextChangesInNewFiles && statements) {
|
||||
const file = context.file;
|
||||
const affectedTextRange = {
|
||||
|
||||
Reference in New Issue
Block a user