Skip to content

Commit f96dc84

Browse files
author
Andy
authored
Make getCombinedCodeFix API public (microsoft#21234)
1 parent 8f6c516 commit f96dc84

5 files changed

Lines changed: 65 additions & 30 deletions

File tree

src/server/client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ namespace ts.server {
558558
const request = this.processRequest<protocol.CodeFixRequest>(CommandNames.GetCodeFixes, args);
559559
const response = this.processResponse<protocol.CodeFixResponse>(request);
560560

561-
// TODO: GH#20538 shouldn't need cast
562-
return (response.body as ReadonlyArray<protocol.CodeFixAction>).map(({ description, changes, fixId }) => ({ description, changes: this.convertChanges(changes, file), fixId }));
561+
return response.body.map(({ description, changes, fixId }) => ({ description, changes: this.convertChanges(changes, file), fixId }));
563562
}
564563

565564
getCombinedCodeFix = notImplemented;

src/server/protocol.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ namespace ts.server.protocol {
102102
GetCodeFixes = "getCodeFixes",
103103
/* @internal */
104104
GetCodeFixesFull = "getCodeFixes-full",
105-
// TODO: GH#20538
106-
/* @internal */
107105
GetCombinedCodeFix = "getCombinedCodeFix",
108106
/* @internal */
109107
GetCombinedCodeFixFull = "getCombinedCodeFix-full",
@@ -557,15 +555,11 @@ namespace ts.server.protocol {
557555
arguments: CodeFixRequestArgs;
558556
}
559557

560-
// TODO: GH#20538
561-
/* @internal */
562558
export interface GetCombinedCodeFixRequest extends Request {
563559
command: CommandTypes.GetCombinedCodeFix;
564560
arguments: GetCombinedCodeFixRequestArgs;
565561
}
566562

567-
// TODO: GH#20538
568-
/* @internal */
569563
export interface GetCombinedCodeFixResponse extends Response {
570564
body: CombinedCodeActions;
571565
}
@@ -622,15 +616,11 @@ namespace ts.server.protocol {
622616
errorCodes?: ReadonlyArray<number>;
623617
}
624618

625-
// TODO: GH#20538
626-
/* @internal */
627619
export interface GetCombinedCodeFixRequestArgs {
628620
scope: GetCombinedCodeFixScope;
629621
fixId: {};
630622
}
631623

632-
// TODO: GH#20538
633-
/* @internal */
634624
export interface GetCombinedCodeFixScope {
635625
type: "file";
636626
args: FileRequestArgs;
@@ -1619,7 +1609,7 @@ namespace ts.server.protocol {
16191609

16201610
export interface CodeFixResponse extends Response {
16211611
/** The code actions that are available */
1622-
body?: CodeAction[]; // TODO: GH#20538 CodeFixAction[]
1612+
body?: CodeFixAction[];
16231613
}
16241614

16251615
export interface CodeAction {
@@ -1631,15 +1621,11 @@ namespace ts.server.protocol {
16311621
commands?: {}[];
16321622
}
16331623

1634-
// TODO: GH#20538
1635-
/* @internal */
16361624
export interface CombinedCodeActions {
16371625
changes: ReadonlyArray<FileCodeEdits>;
16381626
commands?: ReadonlyArray<{}>;
16391627
}
16401628

1641-
// TODO: GH#20538
1642-
/* @internal */
16431629
export interface CodeFixAction extends CodeAction {
16441630
/**
16451631
* If present, one may call 'getCombinedCodeFix' with this fixId.

src/services/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,7 @@ namespace ts {
295295

296296
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
297297

298-
// TODO: GH#20538 return `ReadonlyArray<CodeFixAction>`
299-
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
300-
// TODO: GH#20538
301-
/* @internal */
298+
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction>;
302299
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
303300
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
304301
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
@@ -327,8 +324,6 @@ namespace ts {
327324
dispose(): void;
328325
}
329326

330-
// TODO: GH#20538
331-
/* @internal */
332327
export interface CombinedCodeFixScope { type: "file"; fileName: string; }
333328

334329
export interface GetCompletionsAtPositionOptions {
@@ -419,8 +414,6 @@ namespace ts {
419414
commands?: CodeActionCommand[];
420415
}
421416

422-
// TODO: GH#20538
423-
/* @internal */
424417
export interface CodeFixAction extends CodeAction {
425418
/**
426419
* If present, one may call 'getCombinedCodeFix' with this fixId.
@@ -429,8 +422,6 @@ namespace ts {
429422
fixId?: {};
430423
}
431424

432-
// TODO: GH#20538
433-
/* @internal */
434425
export interface CombinedCodeActions {
435426
changes: ReadonlyArray<FileTextChanges>;
436427
commands: ReadonlyArray<CodeActionCommand> | undefined;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,7 +4091,8 @@ declare namespace ts {
40914091
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
40924092
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
40934093
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
4094-
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
4094+
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction>;
4095+
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
40954096
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
40964097
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
40974098
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
@@ -4107,6 +4108,10 @@ declare namespace ts {
41074108
getProgram(): Program;
41084109
dispose(): void;
41094110
}
4111+
interface CombinedCodeFixScope {
4112+
type: "file";
4113+
fileName: string;
4114+
}
41104115
interface GetCompletionsAtPositionOptions {
41114116
includeExternalModuleExports: boolean;
41124117
includeInsertTextCompletions: boolean;
@@ -4184,6 +4189,17 @@ declare namespace ts {
41844189
*/
41854190
commands?: CodeActionCommand[];
41864191
}
4192+
interface CodeFixAction extends CodeAction {
4193+
/**
4194+
* If present, one may call 'getCombinedCodeFix' with this fixId.
4195+
* This may be omitted to indicate that the code fix can't be applied in a group.
4196+
*/
4197+
fixId?: {};
4198+
}
4199+
interface CombinedCodeActions {
4200+
changes: ReadonlyArray<FileTextChanges>;
4201+
commands: ReadonlyArray<CodeActionCommand> | undefined;
4202+
}
41874203
type CodeActionCommand = InstallPackageAction;
41884204
interface InstallPackageAction {
41894205
}
@@ -5027,6 +5043,7 @@ declare namespace ts.server.protocol {
50275043
DocCommentTemplate = "docCommentTemplate",
50285044
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
50295045
GetCodeFixes = "getCodeFixes",
5046+
GetCombinedCodeFix = "getCombinedCodeFix",
50305047
ApplyCodeActionCommand = "applyCodeActionCommand",
50315048
GetSupportedCodeFixes = "getSupportedCodeFixes",
50325049
GetApplicableRefactors = "getApplicableRefactors",
@@ -5389,6 +5406,13 @@ declare namespace ts.server.protocol {
53895406
command: CommandTypes.GetCodeFixes;
53905407
arguments: CodeFixRequestArgs;
53915408
}
5409+
interface GetCombinedCodeFixRequest extends Request {
5410+
command: CommandTypes.GetCombinedCodeFix;
5411+
arguments: GetCombinedCodeFixRequestArgs;
5412+
}
5413+
interface GetCombinedCodeFixResponse extends Response {
5414+
body: CombinedCodeActions;
5415+
}
53925416
interface ApplyCodeActionCommandRequest extends Request {
53935417
command: CommandTypes.ApplyCodeActionCommand;
53945418
arguments: ApplyCodeActionCommandRequestArgs;
@@ -5422,6 +5446,14 @@ declare namespace ts.server.protocol {
54225446
*/
54235447
errorCodes?: ReadonlyArray<number>;
54245448
}
5449+
interface GetCombinedCodeFixRequestArgs {
5450+
scope: GetCombinedCodeFixScope;
5451+
fixId: {};
5452+
}
5453+
interface GetCombinedCodeFixScope {
5454+
type: "file";
5455+
args: FileRequestArgs;
5456+
}
54255457
interface ApplyCodeActionCommandRequestArgs {
54265458
/** May also be an array of commands. */
54275459
command: {};
@@ -6164,7 +6196,7 @@ declare namespace ts.server.protocol {
61646196
}
61656197
interface CodeFixResponse extends Response {
61666198
/** The code actions that are available */
6167-
body?: CodeAction[];
6199+
body?: CodeFixAction[];
61686200
}
61696201
interface CodeAction {
61706202
/** Description of the code action to display in the UI of the editor */
@@ -6174,6 +6206,17 @@ declare namespace ts.server.protocol {
61746206
/** A command is an opaque object that should be passed to `ApplyCodeActionCommandRequestArgs` without modification. */
61756207
commands?: {}[];
61766208
}
6209+
interface CombinedCodeActions {
6210+
changes: ReadonlyArray<FileCodeEdits>;
6211+
commands?: ReadonlyArray<{}>;
6212+
}
6213+
interface CodeFixAction extends CodeAction {
6214+
/**
6215+
* If present, one may call 'getCombinedCodeFix' with this fixId.
6216+
* This may be omitted to indicate that the code fix can't be applied in a group.
6217+
*/
6218+
fixId?: {};
6219+
}
61776220
/**
61786221
* Format and format on key response message.
61796222
*/

tests/baselines/reference/api/typescript.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4091,7 +4091,8 @@ declare namespace ts {
40914091
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
40924092
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
40934093
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
4094-
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
4094+
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction>;
4095+
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
40954096
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
40964097
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
40974098
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
@@ -4107,6 +4108,10 @@ declare namespace ts {
41074108
getProgram(): Program;
41084109
dispose(): void;
41094110
}
4111+
interface CombinedCodeFixScope {
4112+
type: "file";
4113+
fileName: string;
4114+
}
41104115
interface GetCompletionsAtPositionOptions {
41114116
includeExternalModuleExports: boolean;
41124117
includeInsertTextCompletions: boolean;
@@ -4184,6 +4189,17 @@ declare namespace ts {
41844189
*/
41854190
commands?: CodeActionCommand[];
41864191
}
4192+
interface CodeFixAction extends CodeAction {
4193+
/**
4194+
* If present, one may call 'getCombinedCodeFix' with this fixId.
4195+
* This may be omitted to indicate that the code fix can't be applied in a group.
4196+
*/
4197+
fixId?: {};
4198+
}
4199+
interface CombinedCodeActions {
4200+
changes: ReadonlyArray<FileTextChanges>;
4201+
commands: ReadonlyArray<CodeActionCommand> | undefined;
4202+
}
41874203
type CodeActionCommand = InstallPackageAction;
41884204
interface InstallPackageAction {
41894205
}

0 commit comments

Comments
 (0)