-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Support a "getCombinedCodeFix" service #20338
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
Changes from 1 commit
5c70641
be19542
8a1865f
b89b7fe
a8b3afc
a38216c
c621e3f
d0af16a
2db8649
f2031be
79c0150
8a61761
41c5710
87d30c0
5f7ba73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,7 @@ namespace ts.server.protocol { | |
| GetCodeFixesFull = "getCodeFixes-full", | ||
| GetCombinedCodeFix = "getCombinedCodeFix", | ||
| /* @internal */ | ||
| GetCombinedCodeFixFull = "getCombinedCodeFix", | ||
| GetCombinedCodeFixFull = "getCombinedCodeFix-full", | ||
| ApplyCodeActionCommand = "applyCodeActionCommand", | ||
| GetSupportedCodeFixes = "getSupportedCodeFixes", | ||
|
|
||
|
|
@@ -541,6 +541,10 @@ namespace ts.server.protocol { | |
| arguments: GetCombinedCodeFixRequestArgs; | ||
| } | ||
|
|
||
| export interface GetCombinedCodeFixResponse extends Response { | ||
| body: CodeActionAll; | ||
| } | ||
|
|
||
| export interface ApplyCodeActionCommandRequest extends Request { | ||
| command: CommandTypes.ApplyCodeActionCommand; | ||
| arguments: ApplyCodeActionCommandRequestArgs; | ||
|
|
@@ -594,7 +598,7 @@ namespace ts.server.protocol { | |
| } | ||
|
|
||
| export interface GetCombinedCodeFixRequestArgs extends FileRequestArgs { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a |
||
| groupId: {}; | ||
| actionId: {}; | ||
| } | ||
|
|
||
| export interface ApplyCodeActionCommandRequestArgs { | ||
|
|
@@ -1594,12 +1598,12 @@ namespace ts.server.protocol { | |
|
|
||
| export interface CodeActionAll { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| changes: FileCodeEdits[]; | ||
| commands: {}[] | undefined; | ||
| commands?: {}[]; | ||
| } | ||
|
|
||
| export interface CodeFix extends CodeAction { | ||
| /** If present, one may call 'getAllCodeFixesInGroup' with this groupId. */ | ||
| groupId: {} | undefined; | ||
| /** If present, one may call 'getAllCodeFixesInGroup' with this actionId. */ | ||
| actionId?: {}; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ namespace ts { | |
| export interface CodeFixRegistration { | ||
| errorCodes: number[]; | ||
| getCodeActions(context: CodeFixContext): CodeFix[] | undefined; | ||
| groupIds: string[]; | ||
| fixAllInGroup(context: CodeFixAllContext): CodeActionAll; | ||
| actionIds: string[]; | ||
| getAllCodeActions(context: CodeFixAllContext): CodeActionAll; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should make this one optional
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or make CodeFixRegisraction a union type
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not all codeFixes need to provide a list of applicable actionIds, and not all of them need to provide a getAllCodeActions feature and not all of them need to return an |
||
| } | ||
|
|
||
| export interface CodeFixContextBase extends textChanges.TextChangesContext { | ||
|
|
@@ -15,7 +15,7 @@ namespace ts { | |
| } | ||
|
|
||
| export interface CodeFixAllContext extends CodeFixContextBase { | ||
| groupId: {}; | ||
| actionId: {}; | ||
| } | ||
|
|
||
| export interface CodeFixContext extends CodeFixContextBase { | ||
|
|
@@ -36,8 +36,8 @@ namespace ts { | |
| } | ||
| fixes.push(codeFix); | ||
| } | ||
| if (codeFix.groupIds) { | ||
| for (const gid of codeFix.groupIds) { | ||
| if (codeFix.actionIds) { | ||
| for (const gid of codeFix.actionIds) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Debug.assert(!groups.has(gid)); | ||
| groups.set(gid, codeFix); | ||
| } | ||
|
|
@@ -70,8 +70,8 @@ namespace ts { | |
| } | ||
|
|
||
| export function getAllFixes(context: CodeFixAllContext): CodeActionAll { | ||
| // Currently groupId is always a string. | ||
| return groups.get(cast(context.groupId, isString)).fixAllInGroup!(context); | ||
| // Currently actionId is always a string. | ||
| return groups.get(cast(context.actionId, isString)).getAllCodeActions!(context); | ||
| } | ||
|
|
||
| function createCodeActionAll(changes: FileTextChanges[], commands?: CodeActionCommand[]): CodeActionAll { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this always be currentFile. Api call returns TextChangeRange which has file name per change.. So wouldnt it need to verify all those files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an assertion that all changes are for the current file and a TODO for if we need to test changes affecting multiple files.