Skip to content

Proposal for codefix commands #34787

@ghost

Description

This would enable microsoft/TypeScript#14423.
I am mostly describing changes to protocol.ts in the TypeScript repository here.
@mjbvz @egamma @mhegazy we discussed this today.

1

The returned CodeAction in a code action request may include a list of commands.

export interface CodeAction {
    description: string;
    changes: FileCodeEdits[];
    command?: {};
}

A code action may even have an empty changes list and consist of only a command.
We could choose specify that command must an of commands, although I'm not sure if that's worth bothering with.

2

If the code action is accepted, the editor must send the commands back to the language service to actually be carried out. This means needing a new request type, "applyCodeFixCommand". This looks like:

export interface ApplyCodeFixCommandRequest extends Request {
    command: CommandTypes.ApplyCodeFixCommand;
    arguments: ApplyCodeFixCommandRequestArgs;
}

export interface ApplyCodeFixCommandRequestArgs extends FileRequestArgs {
    command: {};
}

The contents of command will just be what was sent to the editor.
(Typically this will include a "type" field so the language service can dispatch on the type of action.)

3

The language service should send a response when the action is complete.

export interface ApplyCodeFixCommandResponse extends Response {
    body: {};
}

I'm thinking we can just reuse the message field for error reporting and for a successful response. (Currently the field is documented to only be used if success is false.) We could put that in the body, but then it seems redundant.

Metadata

Metadata

Assignees

Labels

apion-testplanplan-itemVS Code - planned item for upcomingunder-discussionIssue is under discussion for relevance, priority, approach

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions