From 39b9a4bba2a026844348886c9d9f2026a3d6f658 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Wed, 5 Apr 2023 18:50:05 +0200 Subject: Add function `Editor::language_server_by_id` and refactor/simplify related code, also don't 'crash' in completion menu if language_server somehow disappeared --- helix-term/src/commands/lsp.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'helix-term/src/commands') diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 38ba98d4..f7d35873 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -301,7 +301,7 @@ fn diag_picker( flat_diag.reserve(diags.len()); for (diag, ls) in diags { - if let Some(ls) = cx.editor.language_servers.get_by_id(ls) { + if let Some(ls) = cx.editor.language_server_by_id(ls) { flat_diag.push(PickerDiagnostic { url: url.clone(), diag, @@ -725,7 +725,7 @@ pub fn code_action(cx: &mut Context) { // always present here let action = action.unwrap(); - let Some(language_server) = editor.language_servers.get_by_id(action.language_server_id) else { + let Some(language_server) = editor.language_server_by_id(action.language_server_id) else { editor.set_error("Language Server disappeared"); return; }; @@ -772,8 +772,7 @@ pub fn execute_lsp_command(editor: &mut Editor, language_server_id: usize, cmd: // the command is executed on the server and communicated back // to the client asynchronously using workspace edits let future = match editor - .language_servers - .get_by_id(language_server_id) + .language_server_by_id(language_server_id) .and_then(|language_server| language_server.command(cmd)) { Some(future) => future, -- cgit v1.2.3-70-g09d2