diff --git a/Cargo.lock b/Cargo.lock index 0fa6ad14d55f..10a7f2d9e543 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -674,9 +674,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ "unicode-xid", ] @@ -849,9 +849,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "28c5e91e4240b46c4c19219d6cc84784444326131a4210f496f948d5cc827a29" dependencies = [ "itoa", "ryu", @@ -934,9 +934,9 @@ checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a" [[package]] name = "syn" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" dependencies = [ "proc-macro2", "quote", @@ -994,9 +994,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac2e1d4bd0f75279cfd5a076e0d578bbf02c22b7c39e766c437dd49b3ec43e0" +checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" dependencies = [ "tinyvec_macros", ] @@ -1163,11 +1163,12 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "which" -version = "4.1.0" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" +checksum = "7cc009ab82a2afc94b9e467ab4214aee9cad1356cd9191264203d7d72006e00d" dependencies = [ "either", + "lazy_static", "libc", ] diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f6df26bad11a..06e8779ef51a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1739,6 +1739,42 @@ mod cmd { doc.reload(view.id) } + fn lsp_restart( + cx: &mut compositor::Context, + _args: &[&str], + _event: PromptEvent, + ) -> anyhow::Result<()> { + let view = cx.editor.tree.get(cx.editor.tree.focus); + let doc_id = view.doc; + let doc = cx.editor.document(doc_id).unwrap(); + let language_server = match doc.language_server_arc() { + Some(language_server) => language_server, + None => return Err(anyhow!("running lsp server not found")), + }; + + log::debug!("got lspserver"); + let fut = async move { + log::debug!("trying shutdown"); + let shutdown_result = language_server.shutdown_and_exit().await; + if let Err(err) = shutdown_result { + log::debug!("shutdown & exit request returned error: {}", err); // we're not doing anything except logging, if LSP crashes then this error is expected + } + let callback: job::Callback = Box::new(move |editor: &mut Editor, _compositor| { + let doc = editor.document(doc_id).unwrap(); + let language_config = doc.language_config_arc().unwrap(); + let language_server = editor.language_servers.get(&language_config).unwrap(); + log::debug!("got new language server"); + let doc = editor.document_mut(doc_id).unwrap(); + doc.set_language_server(Some(language_server)); + log::debug!("set new language server"); + }); + Ok::(callback) + }; + cx.jobs.callback(fut); + + Ok(()) + } + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -1935,6 +1971,13 @@ mod cmd { doc: "Discard changes and reload from the source file.", fun: reload, completer: None, + }, + TypableCommand { + name: "lsp-restart", + alias: None, + doc: "Restart current LSP connection.", + fun: lsp_restart, + completer: None, } ]; diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index c2078060eeed..0130e49a7f68 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -973,6 +973,10 @@ impl Document { self.language.as_deref() } + pub fn language_config_arc(&self) -> Option> { + self.language.clone() + } + /// Current document version, incremented at each change. pub fn version(&self) -> i32 { self.version @@ -983,6 +987,11 @@ impl Document { self.language_server.as_deref() } + #[inline] + pub fn language_server_arc(&self) -> Option> { + self.language_server.clone() + } + #[inline] /// Tree-sitter AST tree pub fn syntax(&self) -> Option<&Syntax> {