mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-02 02:17:44 +03:00
minor: Move 'execute_lsp_command' helper into helix-view
This is a minor move that will make future refactors of code actions simpler. We should be able to move nearly all code action functionality into `helix-view`, save UI stuff like the `menu::Item` implementation and dealings with the compositor.
This commit is contained in:
parent
6f463dbeb3
commit
33c17d48ff
3 changed files with 23 additions and 33 deletions
|
@ -772,7 +772,7 @@ pub fn code_action(cx: &mut Context) {
|
|||
match &action.lsp_item {
|
||||
lsp::CodeActionOrCommand::Command(command) => {
|
||||
log::debug!("code action command: {:?}", command);
|
||||
execute_lsp_command(editor, action.language_server_id, command.clone());
|
||||
editor.execute_lsp_command(command.clone(), action.language_server_id);
|
||||
}
|
||||
lsp::CodeActionOrCommand::CodeAction(code_action) => {
|
||||
log::debug!("code action: {:?}", code_action);
|
||||
|
@ -801,7 +801,7 @@ pub fn code_action(cx: &mut Context) {
|
|||
// if code action provides both edit and command first the edit
|
||||
// should be applied and then the command
|
||||
if let Some(command) = &code_action.command {
|
||||
execute_lsp_command(editor, action.language_server_id, command.clone());
|
||||
editor.execute_lsp_command(command.clone(), action.language_server_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -817,33 +817,6 @@ pub fn code_action(cx: &mut Context) {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn execute_lsp_command(
|
||||
editor: &mut Editor,
|
||||
language_server_id: LanguageServerId,
|
||||
cmd: lsp::Command,
|
||||
) {
|
||||
// the command is executed on the server and communicated back
|
||||
// to the client asynchronously using workspace edits
|
||||
let future = match editor
|
||||
.language_server_by_id(language_server_id)
|
||||
.and_then(|language_server| language_server.command(cmd))
|
||||
{
|
||||
Some(future) => future,
|
||||
None => {
|
||||
editor.set_error("Language server does not support executing commands");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
tokio::spawn(async move {
|
||||
let res = future.await;
|
||||
|
||||
if let Err(e) = res {
|
||||
log::error!("execute LSP command: {}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ApplyEditError {
|
||||
pub kind: ApplyEditErrorKind,
|
||||
|
|
|
@ -1456,7 +1456,7 @@ fn lsp_workspace_command(
|
|||
commands,
|
||||
(),
|
||||
move |cx, (ls_id, command), _action| {
|
||||
execute_lsp_command(cx.editor, *ls_id, command.clone());
|
||||
cx.editor.execute_lsp_command(command.clone(), *ls_id);
|
||||
},
|
||||
);
|
||||
compositor.push(Box::new(overlaid(picker)))
|
||||
|
@ -1484,14 +1484,13 @@ fn lsp_workspace_command(
|
|||
.transpose()?
|
||||
.filter(|args| !args.is_empty());
|
||||
|
||||
execute_lsp_command(
|
||||
cx.editor,
|
||||
*ls_id,
|
||||
cx.editor.execute_lsp_command(
|
||||
helix_lsp::lsp::Command {
|
||||
title: command.clone(),
|
||||
arguments,
|
||||
command,
|
||||
},
|
||||
*ls_id,
|
||||
);
|
||||
}
|
||||
[] => {
|
||||
|
|
|
@ -361,4 +361,22 @@ impl Editor {
|
|||
helix_event::dispatch(DiagnosticsDidChange { editor: self, doc });
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute_lsp_command(&mut self, command: lsp::Command, server_id: LanguageServerId) {
|
||||
// the command is executed on the server and communicated back
|
||||
// to the client asynchronously using workspace edits
|
||||
let Some(future) = self
|
||||
.language_server_by_id(server_id)
|
||||
.and_then(|server| server.command(command))
|
||||
else {
|
||||
self.set_error("Language server does not support executing commands");
|
||||
return;
|
||||
};
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = future.await {
|
||||
log::error!("Error executing LSP command: {err}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue