Skip to content

Commit

Permalink
added impl for new code action service. fixes atom#239
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
  • Loading branch information
cdietrich committed Nov 5, 2018
1 parent 840478c commit 3ae4c4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
24 changes: 20 additions & 4 deletions lib/adapters/code-action-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import * as atomIde from 'atom-ide';
import LinterPushV2Adapter from './linter-push-v2-adapter';
import assert = require('assert');
import Convert from '../convert';
import ApplyEditAdapter from './apply-edit-adapter';
import {
LanguageClientConnection,
ServerCapabilities,
ApplyWorkspaceEditParams,
Command,
CodeAction
} from '../languageclient';
import {
TextEditor,
Expand Down Expand Up @@ -60,12 +64,24 @@ export default class CodeActionAdapter {
}),
},
});

return commands.map((command) => ({
async apply() {
await connection.executeCommand({
command: command.command,
arguments: command.arguments,
});
if (CodeAction.is(command)) {
if (command.edit != null) {
const e:ApplyWorkspaceEditParams = {
edit : command.edit
}
ApplyEditAdapter.onApplyEdit(e);
}

}
if (Command.is(command)) {
await connection.executeCommand({
command: command.command,
arguments: command.arguments,
});
}
},
getTitle() {
return Promise.resolve(command.title);
Expand Down
2 changes: 1 addition & 1 deletion lib/languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class LanguageClientConnection extends EventEmitter {
// * `params` The {CodeActionParams} identifying the document, range and context for the code action.
// Returns a {Promise} containing an {Array} of {Commands}s that can be performed against the given
// documents range.
public codeAction(params: lsp.CodeActionParams): Promise<lsp.Command[]> {
public codeAction(params: lsp.CodeActionParams): Promise<(lsp.Command | lsp.CodeAction)[]> {
return this._sendRequest('textDocument/codeAction', params);
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@types/atom": "^1.28.0",
"@types/node": "^8.0.41",
"fuzzaldrin-plus": "^0.6.0",
"vscode-jsonrpc": "3.7.0-next.1",
"vscode-languageserver-protocol": "3.11.0",
"vscode-languageserver-types": "3.11.0"
"vscode-jsonrpc": "4.0.0",
"vscode-languageserver-protocol": "3.12.0",
"vscode-languageserver-types": "3.12.0"
},
"atomTestRunner": "./build/test/runner",
"devDependencies": {
Expand Down

0 comments on commit 3ae4c4f

Please sign in to comment.