@@ -1124,6 +1124,28 @@ export interface TextDocumentClientCapabilities {
1124
1124
* Whether code action supports dynamic registration.
1125
1125
*/
1126
1126
dynamicRegistration? : boolean ;
1127
+ /**
1128
+ * The client support code action literals as a valid
1129
+ * response of the `textDocument/codeAction` request.
1130
+ *
1131
+ * Since 3.8.0
1132
+ */
1133
+ codeActionLiteralSupport? : {
1134
+ /**
1135
+ * The code action kind is support with the following value
1136
+ * set.
1137
+ */
1138
+ codeActionKind: {
1139
+
1140
+ /**
1141
+ * The code action kind values the client supports. When this
1142
+ * property exists the client also guarantees that it will
1143
+ * handle values outside its set gracefully and falls back
1144
+ * to a default value when unknown.
1145
+ */
1146
+ valueSet: CodeActionKind [];
1147
+ };
1148
+ };
1127
1149
};
1128
1150
1129
1151
/**
@@ -3115,6 +3137,13 @@ _Registration Options_: `TextDocumentRegistrationOptions`
3115
3137
3116
3138
The code action request is sent from the client to the server to compute commands for a given text document and range. These commands are typically code fixes to either fix problems or to beautify/refactor code. The result of a ` textDocument/codeAction ` request is an array of ` Command ` literals which are typically presented in the user interface. When the command is selected the server should be contacted again (via the ` workspace/executeCommand ` ) request to execute the command.
3117
3139
3140
+ > * Since version 3.8.0:* support for CodeAction litarals to enable the following scenarios:
3141
+
3142
+ - the ability to directly return a workspace edit from e code action request. This avoids having another server roundtrip to execute an actual code action. However server providers should be aware that if the code action is expensive to compute or the edits are huge it might still be beneficial if the result is imply a command and the actual edit is only computed when needed.
3143
+ - the ability to group code actions using a kind. Clients are allowed to ignore that information. However it allows them to better group code action for example into corresponding menus (e.g. all refactor code actions into a refactor menu).
3144
+
3145
+ Clients need to announce there support code action literals and code action kinds via the corresponding client capability ` textDocument.codeAction.codeActionLiteralSupport ` .
3146
+
3118
3147
_ Request_ :
3119
3148
* method: 'textDocument/codeAction'
3120
3149
* params: ` CodeActionParams ` defined as follows:
@@ -3140,6 +3169,82 @@ interface CodeActionParams {
3140
3169
context: CodeActionContext ;
3141
3170
}
3142
3171
3172
+ /**
3173
+ * The kind of a code action.
3174
+ *
3175
+ * Kinds are a hierarchical list of identifiers separated by `.`, e.g. `"refactor.extract.function"`.
3176
+ *
3177
+ * The set of kinds is open and client needs to announce the kinds it supports to the server during
3178
+ * initialization.
3179
+ */
3180
+ export type CodeActionKind = string ;
3181
+
3182
+ /**
3183
+ * A set of predefined code action kinds
3184
+ */
3185
+ export namespace CodeActionKind {
3186
+ /**
3187
+ * Base kind for quickfix actions: 'quickfix'
3188
+ */
3189
+ export const QuickFix: CodeActionKind = ' quickfix' ;
3190
+
3191
+ /**
3192
+ * Base kind for refactoring actions: 'refactor'
3193
+ */
3194
+ export const Refactor: CodeActionKind = ' refactor' ;
3195
+
3196
+ /**
3197
+ * Base kind for refactoring extraction actions: 'refactor.extract'
3198
+ *
3199
+ * Example extract actions:
3200
+ *
3201
+ * - Extract method
3202
+ * - Extract function
3203
+ * - Extract variable
3204
+ * - Extract interface from class
3205
+ * - ...
3206
+ */
3207
+ export const RefactorExtract: CodeActionKind = ' refactor.extract' ;
3208
+
3209
+ /**
3210
+ * Base kind for refactoring inline actions: 'refactor.inline'
3211
+ *
3212
+ * Example inline actions:
3213
+ *
3214
+ * - Inline function
3215
+ * - Inline variable
3216
+ * - Inline constant
3217
+ * - ...
3218
+ */
3219
+ export const RefactorInline: CodeActionKind = ' refactor.inline' ;
3220
+
3221
+ /**
3222
+ * Base kind for refactoring rewrite actions: 'refactor.rewrite'
3223
+ *
3224
+ * Example rewrite actions:
3225
+ *
3226
+ * - Convert JavaScript function to class
3227
+ * - Add or remove parameter
3228
+ * - Encapsulate field
3229
+ * - Make method static
3230
+ * - Move method to base class
3231
+ * - ...
3232
+ */
3233
+ export const RefactorRewrite: CodeActionKind = ' refactor.rewrite' ;
3234
+
3235
+ /**
3236
+ * Base kind for source actions: `source`
3237
+ *
3238
+ * Source code actions apply to the entire file.
3239
+ */
3240
+ export const Source: CodeActionKind = ' source' ;
3241
+
3242
+ /**
3243
+ * Base kind for an organize imports source action: `source.organizeImports`
3244
+ */
3245
+ export const SourceOrganizeImports: CodeActionKind = ' source.organizeImports' ;
3246
+ }
3247
+
3143
3248
/**
3144
3249
* Contains additional diagnostic information about the context in which
3145
3250
* a code action is run.
@@ -3149,11 +3254,60 @@ interface CodeActionContext {
3149
3254
* An array of diagnostics.
3150
3255
*/
3151
3256
diagnostics: Diagnostic [];
3257
+
3258
+ /**
3259
+ * Requested kind of actions to return.
3260
+ *
3261
+ * Actions not of this kind are filtered out by the client before being shown. So servers
3262
+ * can omit computing them.
3263
+ */
3264
+ only? : CodeActionKind [];
3152
3265
}
3153
3266
```
3154
3267
3155
3268
_ Response_ :
3156
- * result: [ ` Command[] ` ] ( #command ) \| ` null ` defined as follows:
3269
+ * result: ` (Command | CodeAction)[] ` \| ` null ` where ` CodeAction ` is defined as follows:
3270
+
3271
+ ``` typescript
3272
+ /**
3273
+ * A code action represents a change that can be performed in code, e.g. to fix a problem or
3274
+ * to refactor code.
3275
+ *
3276
+ * A CodeAction must set either `edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed.
3277
+ */
3278
+ export interface CodeAction {
3279
+
3280
+ /**
3281
+ * A short, human-readable, title for this code action.
3282
+ */
3283
+ title: string ;
3284
+
3285
+ /**
3286
+ * The kind of the code action.
3287
+ *
3288
+ * Used to filter code actions.
3289
+ */
3290
+ kind? : CodeActionKind ;
3291
+
3292
+ /**
3293
+ * The diagnostics that this code action resolves.
3294
+ */
3295
+ diagnostics? : Diagnostic [];
3296
+
3297
+ /**
3298
+ * The workspace edit this code action performs.
3299
+ */
3300
+ edit? : WorkspaceEdit ;
3301
+
3302
+ /**
3303
+ * A command this code action executes. If a code action
3304
+ * provides an edit and a command, first the edit is
3305
+ * executed and then the command.
3306
+ */
3307
+ command? : Command ;
3308
+ }
3309
+ ```
3310
+
3157
3311
* error: code and message set in case an exception happens during the code action request.
3158
3312
3159
3313
_ Registration Options_ : ` TextDocumentRegistrationOptions `
@@ -3591,7 +3745,9 @@ _Registration Options_: `TextDocumentRegistrationOptions`
3591
3745
3592
3746
### <a name =" changeLog " class =" anchor " ></a >Change Log
3593
3747
3594
- Below a change log of the last shipped version.
3748
+ #### <a name =" version_3_8_0 " class =" anchor " ></a >3.8.0 (6/11/2018)
3749
+
3750
+ * Added support for CodeAction literals to the ` textDocument/codeAction ` request.
3595
3751
* ColorServerCapabilities.colorProvider can also be a boolean
3596
3752
* Corrected ColorPresentationParams.colorInfo to color (as in the d.ts and in implementations)
3597
3753
0 commit comments