From bc103ac1f65943d7348acece538294e59c143e64 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Sat, 4 Feb 2023 17:26:20 +0100 Subject: [PATCH 01/10] Show only jumps who belongs to the current view --- helix-term/src/commands.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d1dc92236cf0..aee0b6fbbf2a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2544,16 +2544,13 @@ fn jumplist_picker(cx: &mut Context) { } }; + let view = cx.editor.tree.get(cx.editor.tree.focus); + let jumps: Vec<_> = view.jumps.iter() + .map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone())) + .collect(); + let picker = FilePicker::new( - cx.editor - .tree - .views() - .flat_map(|(view, _)| { - view.jumps - .iter() - .map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone())) - }) - .collect(), + jumps, (), |cx, meta, action| { cx.editor.switch(meta.id, action); From 3792c397f555c0bee6b3400a368bb71fcab7591f Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Sat, 4 Feb 2023 17:26:49 +0100 Subject: [PATCH 02/10] Show jumplist in reverse order (inner to outer) --- helix-view/src/view.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 660cce6586af..5ebbf9aae046 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -75,7 +75,7 @@ impl JumpList { } pub fn iter(&self) -> impl Iterator { - self.jumps.iter() + self.jumps.iter().rev() } /// Applies a [`Transaction`] of changes to the jumplist. From 1a4869fca31391feb503c0b600f0278bc68f39eb Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Mon, 13 Feb 2023 11:20:29 +0100 Subject: [PATCH 03/10] Allow lsp to be stopped --- helix-lsp/src/lib.rs | 13 +++++++++++++ helix-term/src/commands/typed.rs | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 8418896cbb73..7325cdec9e2b 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -427,6 +427,19 @@ impl Registry { } } + pub fn stop( + &mut self, + language_config: &LanguageConfiguration, + ) { + let scope = language_config.scope.clone(); + + if let Some((_, client)) = self.inner.remove(&scope) { + tokio::spawn(async move { + let _ = client.force_shutdown().await; + }); + } + } + pub fn get( &mut self, language_config: &LanguageConfiguration, diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f2495d8ce63c..92a0fd2a1ba6 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1225,6 +1225,24 @@ fn lsp_restart( Ok(()) } +fn lsp_stop( + cx: &mut compositor::Context, + _args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + let (_view, doc) = current!(cx.editor); + let config = doc + .language_config() + .context("LSP not defined for the current document")?; + + cx.editor.language_servers.stop(config); + Ok(()) +} + fn tree_sitter_scopes( cx: &mut compositor::Context, _args: &[Cow], @@ -2166,6 +2184,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: lsp_restart, completer: None, }, + TypableCommand { + name: "lsp-stop", + aliases: &[], + doc: "Stops the Language Server that is in use by the current doc", + fun: lsp_stop, + completer: None, + }, TypableCommand { name: "tree-sitter-scopes", aliases: &[], From 1362e6416c50bf92f1cb9bd2ad6e9188dcf8d3eb Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Mon, 13 Feb 2023 11:39:28 +0100 Subject: [PATCH 04/10] Remove unrelated code --- helix-term/src/commands.rs | 15 +++++++++------ helix-view/src/view.rs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index aee0b6fbbf2a..d1dc92236cf0 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2544,13 +2544,16 @@ fn jumplist_picker(cx: &mut Context) { } }; - let view = cx.editor.tree.get(cx.editor.tree.focus); - let jumps: Vec<_> = view.jumps.iter() - .map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone())) - .collect(); - let picker = FilePicker::new( - jumps, + cx.editor + .tree + .views() + .flat_map(|(view, _)| { + view.jumps + .iter() + .map(|(doc_id, selection)| new_meta(view, *doc_id, selection.clone())) + }) + .collect(), (), |cx, meta, action| { cx.editor.switch(meta.id, action); diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 5ebbf9aae046..660cce6586af 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -75,7 +75,7 @@ impl JumpList { } pub fn iter(&self) -> impl Iterator { - self.jumps.iter().rev() + self.jumps.iter() } /// Applies a [`Transaction`] of changes to the jumplist. From 2fa5c9282fba90b74ad1df1b21ddd76201f75055 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Wed, 15 Feb 2023 15:35:28 +0100 Subject: [PATCH 05/10] Cleanup stopped language server references from other docs --- helix-lsp/src/lib.rs | 2 +- helix-term/src/commands/typed.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 7325cdec9e2b..0298c49bab0a 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -435,7 +435,7 @@ impl Registry { if let Some((_, client)) = self.inner.remove(&scope) { tokio::spawn(async move { - let _ = client.force_shutdown().await; + let _ = client.force_shutdown().await; }); } } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 92a0fd2a1ba6..1bbd82e6d3e8 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1235,11 +1235,23 @@ fn lsp_stop( } let (_view, doc) = current!(cx.editor); + + let ls_id = doc + .language_server().map(|ls| ls.id()) + .context("LSP not running for the current document")?; + let config = doc .language_config() .context("LSP not defined for the current document")?; + cx.editor.language_servers.stop(&config); + + cx.editor.documents_mut() + .filter(|doc| doc.language_server().map_or(false, |ls| ls.id() == ls_id)) + .for_each(|doc| { + doc.set_language_server(None); + log::warn!("XXX STOPPING for {:?}", doc.path()); + }); - cx.editor.language_servers.stop(config); Ok(()) } From b2735d1b6e7188871233c9676692f11bbcf43a20 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Wed, 15 Feb 2023 17:08:26 +0100 Subject: [PATCH 06/10] Format and docs --- book/src/generated/typable-cmd.md | 1 + helix-lsp/src/lib.rs | 5 +---- helix-term/src/commands/typed.rs | 11 +++++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 66e6ac039c26..b94b68676111 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -48,6 +48,7 @@ | `:update` | Write changes only if the file has been modified. | | `:lsp-workspace-command` | Open workspace command picker | | `:lsp-restart` | Restarts the Language Server that is in use by the current doc | +| `:lsp-stop` | Stops the Language Server that is in use by the current doc | | `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. | | `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. | | `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. | diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 0298c49bab0a..010c17d3c9ce 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -427,10 +427,7 @@ impl Registry { } } - pub fn stop( - &mut self, - language_config: &LanguageConfiguration, - ) { + pub fn stop(&mut self, language_config: &LanguageConfiguration) { let scope = language_config.scope.clone(); if let Some((_, client)) = self.inner.remove(&scope) { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 1bbd82e6d3e8..2aa907eed7dc 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1237,7 +1237,8 @@ fn lsp_stop( let (_view, doc) = current!(cx.editor); let ls_id = doc - .language_server().map(|ls| ls.id()) + .language_server() + .map(|ls| ls.id()) .context("LSP not running for the current document")?; let config = doc @@ -1245,12 +1246,10 @@ fn lsp_stop( .context("LSP not defined for the current document")?; cx.editor.language_servers.stop(&config); - cx.editor.documents_mut() + cx.editor + .documents_mut() .filter(|doc| doc.language_server().map_or(false, |ls| ls.id() == ls_id)) - .for_each(|doc| { - doc.set_language_server(None); - log::warn!("XXX STOPPING for {:?}", doc.path()); - }); + .for_each(|doc| doc.set_language_server(None)); Ok(()) } From 19371699738cf66770c4af4d8a7fe2af708a5279 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Thu, 23 Feb 2023 19:25:48 +0100 Subject: [PATCH 07/10] Cleanup diagnostics on lsp stop --- helix-term/src/commands/typed.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 2aa907eed7dc..01bf8f745261 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1246,10 +1246,12 @@ fn lsp_stop( .context("LSP not defined for the current document")?; cx.editor.language_servers.stop(&config); - cx.editor - .documents_mut() - .filter(|doc| doc.language_server().map_or(false, |ls| ls.id() == ls_id)) - .for_each(|doc| doc.set_language_server(None)); + for doc in cx.editor.documents_mut() { + if doc.language_server().map_or(false, |ls| ls.id() == ls_id) { + doc.set_language_server(None); + doc.set_diagnostics(Default::default()); + } + } Ok(()) } From d22173e0fd8fda2e7f672f2a7b238aa7ca07efcd Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Thu, 2 Mar 2023 18:32:26 +0100 Subject: [PATCH 08/10] Cargo fmt --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 01bf8f745261..d35db616d31a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1248,7 +1248,7 @@ fn lsp_stop( for doc in cx.editor.documents_mut() { if doc.language_server().map_or(false, |ls| ls.id() == ls_id) { - doc.set_language_server(None); + doc.set_language_server(None); doc.set_diagnostics(Default::default()); } } From 2b6a136f36671d23cb129137440d3a1e4ea2e6b8 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Sun, 5 Mar 2023 17:39:44 +0100 Subject: [PATCH 09/10] Apply review suggestion Co-authored-by: Michael Davis --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d35db616d31a..ebded0faedf5 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1244,7 +1244,7 @@ fn lsp_stop( let config = doc .language_config() .context("LSP not defined for the current document")?; - cx.editor.language_servers.stop(&config); + cx.editor.language_servers.stop(config); for doc in cx.editor.documents_mut() { if doc.language_server().map_or(false, |ls| ls.id() == ls_id) { From 6caa35da67d9382290707b5db04fa4b559d5dd55 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 7 Mar 2023 18:05:37 -0600 Subject: [PATCH 10/10] style: Use doc! macro instead of current! --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ebded0faedf5..39e214ddc38c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1234,7 +1234,7 @@ fn lsp_stop( return Ok(()); } - let (_view, doc) = current!(cx.editor); + let doc = doc!(cx.editor); let ls_id = doc .language_server()