mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Fix acquiring format options for getEditsForRefactor (#18848)
* Fix acquiring format options for getEditsForRefactor * Add test * Fix test description * Use `executeCommandSeq`
This commit is contained in:
@@ -4245,4 +4245,60 @@ namespace ts.projectSystem {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("refactors", () => {
|
||||
it("use formatting options", () => {
|
||||
const file = {
|
||||
path: "/a.ts",
|
||||
content: "function f() {\n 1;\n}",
|
||||
};
|
||||
const host = createServerHost([file]);
|
||||
const session = createSession(host);
|
||||
openFilesForSession([file], session);
|
||||
|
||||
const response0 = session.executeCommandSeq<server.protocol.ConfigureRequest>({
|
||||
command: server.protocol.CommandTypes.Configure,
|
||||
arguments: {
|
||||
formatOptions: {
|
||||
indentSize: 2,
|
||||
},
|
||||
},
|
||||
}).response;
|
||||
assert.deepEqual(response0, /*expected*/ undefined);
|
||||
|
||||
const response1 = session.executeCommandSeq<server.protocol.GetEditsForRefactorRequest>({
|
||||
command: server.protocol.CommandTypes.GetEditsForRefactor,
|
||||
arguments: {
|
||||
refactor: "Extract Symbol",
|
||||
action: "function_scope_1",
|
||||
file: "/a.ts",
|
||||
startLine: 2,
|
||||
startOffset: 3,
|
||||
endLine: 2,
|
||||
endOffset: 4,
|
||||
},
|
||||
}).response;
|
||||
assert.deepEqual(response1, {
|
||||
edits: [
|
||||
{
|
||||
fileName: "/a.ts",
|
||||
textChanges: [
|
||||
{
|
||||
start: { line: 2, offset: 1 },
|
||||
end: { line: 3, offset: 1 },
|
||||
newText: " newFunction();\n",
|
||||
},
|
||||
{
|
||||
start: { line: 3, offset: 2 },
|
||||
end: { line: 3, offset: 2 },
|
||||
newText: "\nfunction newFunction() {\n 1;\n}\n",
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
renameFilename: "/a.ts",
|
||||
renameLocation: { line: 2, offset: 3 },
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -573,7 +573,7 @@ namespace ts.server {
|
||||
|
||||
getEditsForRefactor(
|
||||
fileName: string,
|
||||
formatOptions: FormatCodeSettings,
|
||||
_formatOptions: FormatCodeSettings,
|
||||
positionOrRange: number | TextRange,
|
||||
refactorName: string,
|
||||
actionName: string): RefactorEditInfo {
|
||||
@@ -581,7 +581,6 @@ namespace ts.server {
|
||||
const args = this.createFileLocationOrRangeRequestArgs(positionOrRange, fileName) as protocol.GetEditsForRefactorRequestArgs;
|
||||
args.refactor = refactorName;
|
||||
args.action = actionName;
|
||||
args.formatOptions = formatOptions;
|
||||
|
||||
const request = this.processRequest<protocol.GetEditsForRefactorRequest>(CommandNames.GetEditsForRefactor, args);
|
||||
const response = this.processResponse<protocol.GetEditsForRefactorResponse>(request);
|
||||
|
||||
@@ -494,7 +494,6 @@ namespace ts.server.protocol {
|
||||
refactor: string;
|
||||
/* The 'name' property from the refactoring action */
|
||||
action: string;
|
||||
formatOptions?: FormatCodeSettings,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1488,7 +1488,7 @@ namespace ts.server {
|
||||
|
||||
const result = project.getLanguageService().getEditsForRefactor(
|
||||
file,
|
||||
args.formatOptions ? convertFormatOptions(args.formatOptions) : this.projectService.getFormatCodeOptions(),
|
||||
this.projectService.getFormatCodeOptions(file),
|
||||
position || textRange,
|
||||
args.refactor,
|
||||
args.action
|
||||
|
||||
Reference in New Issue
Block a user