@@ -3277,12 +3277,19 @@ pub fn code_action(cx: &mut Context) {
3277 move |editor, code_action, _action| match code_action {
3277 move |editor, code_action, _action| match code_action {
3278 lsp::CodeActionOrCommand::Command(command) => {
3278 lsp::CodeActionOrCommand::Command(command) => {
3279 log::debug!("code action command: {:?}", command);
3279 log::debug!("code action command: {:?}", command);
3280− editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
3280+ execute_lsp_command(editor, command.clone());
3282 lsp::CodeActionOrCommand::CodeAction(code_action) => {
3282 lsp::CodeActionOrCommand::CodeAction(code_action) => {
3283 log::debug!("code action: {:?}", code_action);
3283 log::debug!("code action: {:?}", code_action);
3284 if let Some(ref workspace_edit) = code_action.edit {
3284 if let Some(ref workspace_edit) = code_action.edit {
3285+ log::debug!("edit: {:?}", workspace_edit);
3285− apply_workspace_edit(editor, offset_encoding, workspace_edit)
3286+ apply_workspace_edit(editor, offset_encoding, workspace_edit);
3289+ // if code action provides both edit and command first the edit
3290+ // should be applied and then the command
3291+ if let Some(command) = &code_action.command {
3292+ execute_lsp_command(editor, command.clone());
@@ -3293,6 +3300,26 @@ pub fn code_action(cx: &mut Context) {
3303+pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
3304+ let (_view, doc) = current!(editor);
3306+ let language_server = match doc.language_server() {
3307+ Some(language_server) => language_server,
3311+ // the command is executed on the server and communicated back
3312+ // to the client asynchronously using workspace edits
3313+ let command_future = language_server.command(cmd);
3314+ tokio::spawn(async move {
3315+ let res = command_future.await;
3317+ if let Err(e) = res {
3318+ log::error!("execute LSP command: {}", e);
3296pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
3323pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
3297 use lsp::ResourceOp;
3324 use lsp::ResourceOp;
3298 use std::fs;
3325 use std::fs;
@@ -3346,7 +3373,7 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
3349−fn apply_workspace_edit(
3376+pub fn apply_workspace_edit(
3350 editor: &mut Editor,
3377 editor: &mut Editor,
3351 offset_encoding: OffsetEncoding,
3378 offset_encoding: OffsetEncoding,
3352 workspace_edit: &lsp::WorkspaceEdit,
3379 workspace_edit: &lsp::WorkspaceEdit,