Skip to content

Make getCombinedCodeFix API public #21234

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

Merged
1 commit merged into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ namespace ts.server {
const request = this.processRequest<protocol.CodeFixRequest>(CommandNames.GetCodeFixes, args);
const response = this.processResponse<protocol.CodeFixResponse>(request);

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

getCombinedCodeFix = notImplemented;
Expand Down
16 changes: 1 addition & 15 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ namespace ts.server.protocol {
GetCodeFixes = "getCodeFixes",
/* @internal */
GetCodeFixesFull = "getCodeFixes-full",
// TODO: GH#20538
/* @internal */
GetCombinedCodeFix = "getCombinedCodeFix",
/* @internal */
GetCombinedCodeFixFull = "getCombinedCodeFix-full",
Expand Down Expand Up @@ -557,15 +555,11 @@ namespace ts.server.protocol {
arguments: CodeFixRequestArgs;
}

// TODO: GH#20538
/* @internal */
export interface GetCombinedCodeFixRequest extends Request {
command: CommandTypes.GetCombinedCodeFix;
arguments: GetCombinedCodeFixRequestArgs;
}

// TODO: GH#20538
/* @internal */
export interface GetCombinedCodeFixResponse extends Response {
body: CombinedCodeActions;
}
Expand Down Expand Up @@ -622,15 +616,11 @@ namespace ts.server.protocol {
errorCodes?: ReadonlyArray<number>;
}

// TODO: GH#20538
/* @internal */
export interface GetCombinedCodeFixRequestArgs {
scope: GetCombinedCodeFixScope;
fixId: {};
}

// TODO: GH#20538
/* @internal */
export interface GetCombinedCodeFixScope {
type: "file";
args: FileRequestArgs;
Expand Down Expand Up @@ -1619,7 +1609,7 @@ namespace ts.server.protocol {

export interface CodeFixResponse extends Response {
/** The code actions that are available */
body?: CodeAction[]; // TODO: GH#20538 CodeFixAction[]
body?: CodeFixAction[];
}

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

// TODO: GH#20538
/* @internal */
export interface CombinedCodeActions {
changes: ReadonlyArray<FileCodeEdits>;
commands?: ReadonlyArray<{}>;
}

// TODO: GH#20538
/* @internal */
export interface CodeFixAction extends CodeAction {
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
Expand Down
11 changes: 1 addition & 10 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ namespace ts {

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

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

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

export interface GetCompletionsAtPositionOptions {
Expand Down Expand Up @@ -419,8 +414,6 @@ namespace ts {
commands?: CodeActionCommand[];
}

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

// TODO: GH#20538
/* @internal */
export interface CombinedCodeActions {
changes: ReadonlyArray<FileTextChanges>;
commands: ReadonlyArray<CodeActionCommand> | undefined;
Expand Down
47 changes: 45 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4091,7 +4091,8 @@ declare namespace ts {
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction>;
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
Expand All @@ -4107,6 +4108,10 @@ declare namespace ts {
getProgram(): Program;
dispose(): void;
}
interface CombinedCodeFixScope {
type: "file";
fileName: string;
}
interface GetCompletionsAtPositionOptions {
includeExternalModuleExports: boolean;
includeInsertTextCompletions: boolean;
Expand Down Expand Up @@ -4184,6 +4189,17 @@ declare namespace ts {
*/
commands?: CodeActionCommand[];
}
interface CodeFixAction extends CodeAction {
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
* This may be omitted to indicate that the code fix can't be applied in a group.
*/
fixId?: {};
}
interface CombinedCodeActions {
changes: ReadonlyArray<FileTextChanges>;
commands: ReadonlyArray<CodeActionCommand> | undefined;
}
type CodeActionCommand = InstallPackageAction;
interface InstallPackageAction {
}
Expand Down Expand Up @@ -5027,6 +5043,7 @@ declare namespace ts.server.protocol {
DocCommentTemplate = "docCommentTemplate",
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
GetCodeFixes = "getCodeFixes",
GetCombinedCodeFix = "getCombinedCodeFix",
ApplyCodeActionCommand = "applyCodeActionCommand",
GetSupportedCodeFixes = "getSupportedCodeFixes",
GetApplicableRefactors = "getApplicableRefactors",
Expand Down Expand Up @@ -5389,6 +5406,13 @@ declare namespace ts.server.protocol {
command: CommandTypes.GetCodeFixes;
arguments: CodeFixRequestArgs;
}
interface GetCombinedCodeFixRequest extends Request {
command: CommandTypes.GetCombinedCodeFix;
arguments: GetCombinedCodeFixRequestArgs;
}
interface GetCombinedCodeFixResponse extends Response {
body: CombinedCodeActions;
}
interface ApplyCodeActionCommandRequest extends Request {
command: CommandTypes.ApplyCodeActionCommand;
arguments: ApplyCodeActionCommandRequestArgs;
Expand Down Expand Up @@ -5422,6 +5446,14 @@ declare namespace ts.server.protocol {
*/
errorCodes?: ReadonlyArray<number>;
}
interface GetCombinedCodeFixRequestArgs {
scope: GetCombinedCodeFixScope;
fixId: {};
}
interface GetCombinedCodeFixScope {
type: "file";
args: FileRequestArgs;
}
interface ApplyCodeActionCommandRequestArgs {
/** May also be an array of commands. */
command: {};
Expand Down Expand Up @@ -6164,7 +6196,7 @@ declare namespace ts.server.protocol {
}
interface CodeFixResponse extends Response {
/** The code actions that are available */
body?: CodeAction[];
body?: CodeFixAction[];
}
interface CodeAction {
/** Description of the code action to display in the UI of the editor */
Expand All @@ -6174,6 +6206,17 @@ declare namespace ts.server.protocol {
/** A command is an opaque object that should be passed to `ApplyCodeActionCommandRequestArgs` without modification. */
commands?: {}[];
}
interface CombinedCodeActions {
changes: ReadonlyArray<FileCodeEdits>;
commands?: ReadonlyArray<{}>;
}
interface CodeFixAction extends CodeAction {
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
* This may be omitted to indicate that the code fix can't be applied in a group.
*/
fixId?: {};
}
/**
* Format and format on key response message.
*/
Expand Down
18 changes: 17 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4091,7 +4091,8 @@ declare namespace ts {
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction>;
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
Expand All @@ -4107,6 +4108,10 @@ declare namespace ts {
getProgram(): Program;
dispose(): void;
}
interface CombinedCodeFixScope {
type: "file";
fileName: string;
}
interface GetCompletionsAtPositionOptions {
includeExternalModuleExports: boolean;
includeInsertTextCompletions: boolean;
Expand Down Expand Up @@ -4184,6 +4189,17 @@ declare namespace ts {
*/
commands?: CodeActionCommand[];
}
interface CodeFixAction extends CodeAction {
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
* This may be omitted to indicate that the code fix can't be applied in a group.
*/
fixId?: {};
}
interface CombinedCodeActions {
changes: ReadonlyArray<FileTextChanges>;
commands: ReadonlyArray<CodeActionCommand> | undefined;
}
type CodeActionCommand = InstallPackageAction;
interface InstallPackageAction {
}
Expand Down