mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
fix(54283): Provide better UX when an invalid file is selected for 'move to file' refactoring (#54300)
This commit is contained in:
@@ -96,28 +96,61 @@ describe("unittests:: tsserver:: refactors", () => {
|
||||
});
|
||||
|
||||
it("handles moving statement to an existing file", () => {
|
||||
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
|
||||
const bTs: File = {
|
||||
path: "/Foo/b.ts", content: `import {} from "./bar";
|
||||
const a = 1;`};
|
||||
const tsconfig: File = { path: "/Foo/tsconfig.json", content: `{ "files": ["./a.ts", "./b.ts"] }` };
|
||||
const host = createServerHost([aTs, bTs, tsconfig]);
|
||||
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
|
||||
openFilesForSession([aTs], session);
|
||||
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
|
||||
const bTs: File = {
|
||||
path: "/Foo/b.ts", content: `import {} from "./bar";
|
||||
const a = 1;`};
|
||||
const tsconfig: File = { path: "/Foo/tsconfig.json", content: `{ "files": ["./a.ts", "./b.ts"] }` };
|
||||
const host = createServerHost([aTs, bTs, tsconfig]);
|
||||
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
|
||||
openFilesForSession([aTs], session);
|
||||
|
||||
session.executeCommandSeq<ts.server.protocol.GetEditsForRefactorRequest>({
|
||||
command: ts.server.protocol.CommandTypes.GetEditsForRefactor,
|
||||
arguments: {
|
||||
file: aTs.path,
|
||||
startLine: 1,
|
||||
startOffset: 1,
|
||||
endLine: 2,
|
||||
endOffset: aTs.content.length,
|
||||
refactor: "Move to file",
|
||||
action: "Move to file",
|
||||
interactiveRefactorArguments: { targetFile: "/Foo/b.ts" },
|
||||
}
|
||||
session.executeCommandSeq<ts.server.protocol.GetEditsForRefactorRequest>({
|
||||
command: ts.server.protocol.CommandTypes.GetEditsForRefactor,
|
||||
arguments: {
|
||||
file: aTs.path,
|
||||
startLine: 1,
|
||||
startOffset: 1,
|
||||
endLine: 2,
|
||||
endOffset: aTs.content.length,
|
||||
refactor: "Move to file",
|
||||
action: "Move to file",
|
||||
interactiveRefactorArguments: { targetFile: "/Foo/b.ts" },
|
||||
}
|
||||
});
|
||||
baselineTsserverLogs("refactors", "handles moving statement to an existing file", session);
|
||||
});
|
||||
baselineTsserverLogs("refactors", "handles moving statement to an existing file", session);
|
||||
|
||||
it("handles moving statements to a non-TS file", () => {
|
||||
const aTs: File = {
|
||||
path: "/Foo/a.ts",
|
||||
content: "const x = 0;"
|
||||
};
|
||||
const bTxt: File = {
|
||||
path: "/Foo/b.txt",
|
||||
content: ""
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: "/Foo/tsconfig.json",
|
||||
content: `{ "files": ["./a.ts"] }`
|
||||
};
|
||||
const host = createServerHost([aTs, bTxt, tsconfig]);
|
||||
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
|
||||
openFilesForSession([aTs], session);
|
||||
|
||||
session.executeCommandSeq<ts.server.protocol.GetEditsForRefactorRequest>({
|
||||
command: ts.server.protocol.CommandTypes.GetEditsForRefactor,
|
||||
arguments: {
|
||||
file: aTs.path,
|
||||
startLine: 1,
|
||||
startOffset: 1,
|
||||
endLine: 2,
|
||||
endOffset: aTs.content.length,
|
||||
refactor: "Move to file",
|
||||
action: "Move to file",
|
||||
interactiveRefactorArguments: { targetFile: "/Foo/b.txt" },
|
||||
}
|
||||
});
|
||||
baselineTsserverLogs("refactors", "handles moving statements to a non-TS file", session);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user