Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Move To File Action appear less often #57080

Merged
merged 26 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b8ea147
wip
aiday-mar Dec 20, 2023
1adf357
Merge branch 'microsoft:main' into main
aiday-mar Jan 17, 2024
9e8359e
adding changes
aiday-mar Jan 17, 2024
0547a88
formatting the code correctly
aiday-mar Jan 17, 2024
2472259
adding a missing comma
aiday-mar Jan 17, 2024
afc1fd2
adding baseline change
aiday-mar Jan 17, 2024
f0b00aa
review changes
aiday-mar Jan 18, 2024
d7eedd8
adding code from review
aiday-mar Feb 13, 2024
7d21d2d
code review changes
aiday-mar Feb 13, 2024
766a690
Merge branch 'main' of github.com:aiday-mar/TypeScript into pr/aiday-…
aiday-mar Feb 13, 2024
32fce2a
add back template file
aiday-mar Feb 13, 2024
bbff752
fixing formatting and linting errors
aiday-mar Feb 13, 2024
dea141a
making the preferences object also parameter for the tests
aiday-mar Feb 13, 2024
3b78378
fixing formatting errors
aiday-mar Feb 13, 2024
1cad4fe
adding changes
aiday-mar Feb 13, 2024
be3e49c
polishing
aiday-mar Feb 13, 2024
4e60710
removing duplicate type
aiday-mar Feb 13, 2024
e59f006
polishing tsts
aiday-mar Feb 13, 2024
1e74fc3
adding baseline change
aiday-mar Feb 13, 2024
db1078e
adding review changes
aiday-mar Feb 14, 2024
fa0a7d6
removing the rest of the rootNode code
aiday-mar Feb 14, 2024
89d5a88
adding review changes
aiday-mar Feb 16, 2024
154fcc5
adding a reason also into the comment
aiday-mar Feb 16, 2024
c6b461c
adding a semi colon
aiday-mar Feb 16, 2024
22c8fb3
changing to fetching the token at the end position
aiday-mar Feb 16, 2024
dcf2ffb
correcting the test
aiday-mar Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ function isExtractableExpression(node: Node): boolean {
return true;
}

function isBlockLike(node: Node): node is BlockLike {
export function isBlockLike(node: Node): node is BlockLike {
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
switch (node.kind) {
case SyntaxKind.Block:
case SyntaxKind.SourceFile:
Expand Down
16 changes: 16 additions & 0 deletions src/services/refactors/moveToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
getRelativePathFromFile,
getSourceFileOfNode,
getSynthesizedDeepClone,
getTokenAtPosition,
getUniqueName,
hasJSFileExtension,
hasSyntacticModifier,
Expand Down Expand Up @@ -151,6 +152,9 @@ import {
import {
registerRefactor,
} from "../refactorProvider";
import {
isBlockLike,
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
} from "./extractSymbol";

const refactorNameForMoveToFile = "Move to file";
const description = getLocaleSpecificMessage(Diagnostics.Move_to_file);
Expand All @@ -167,6 +171,18 @@ registerRefactor(refactorNameForMoveToFile, {
if (!interactiveRefactorArguments) {
return emptyArray;
}
const endPosition = context.endPosition;
if (endPosition) {
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
const file = context.file;
const startNode = getTokenAtPosition(file, context.startPosition);
const endNode = getTokenAtPosition(file, endPosition);
if (
startNode.kind !== SyntaxKind.SourceFile && isBlockLike(startNode)
&& endNode.kind !== SyntaxKind.SourceFile && isBlockLike(endNode)
) {
return emptyArray;
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (context.preferences.allowTextChangesInNewFiles && statements) {
return [{ name: refactorNameForMoveToFile, description, actions: [moveToFileAction] }];
}
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10358,6 +10358,11 @@ declare namespace ts {
readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[] | undefined, depth?: number): string[];
}
}
namespace refactor {
namespace extractSymbol {
function isBlockLike(node: Node): node is BlockLike;
}
}
function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings;
/**
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,6 @@ Info seq [hh:mm:ss:mss] response:
}
]
},
{
"name": "Move to file",
"description": "Move to file",
"actions": [
{
"name": "Move to file",
"description": "Move to file",
"kind": "refactor.move.file"
}
]
},
{
"name": "Extract Symbol",
"description": "Extract function",
Expand All @@ -257,6 +246,17 @@ Info seq [hh:mm:ss:mss] response:
"kind": "refactor.extract.constant"
}
]
},
{
"name": "Move to file",
"description": "Move to file",
"actions": [
{
"name": "Move to file",
"description": "Move to file",
"kind": "refactor.move.file"
}
]
}
]
}
Expand Down
Loading