diff options
author | Blaž Hrastnik | 2022-09-07 07:42:33 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-09-07 07:42:33 +0000 |
commit | a123fb60572720a5fd0817b194f4d34534f87b4e (patch) | |
tree | c5aef0de1f64bc399206e2a5ee0f2fdebd427b4d | |
parent | fe37a66046b16eaf7829606f7b90c18bd73fae3e (diff) |
Remove LspNotDefined, instead return an Option<>
-rw-r--r-- | helix-lsp/src/lib.rs | 16 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 1 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 1 |
3 files changed, 7 insertions, 11 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 516c93ca..a39325fa 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -38,8 +38,6 @@ pub enum Error { Timeout, #[error("server closed the stream")] StreamClosed, - #[error("LSP not defined")] - LspNotDefined, #[error("Unhandled")] Unhandled, #[error(transparent)] @@ -320,14 +318,14 @@ impl Registry { .map(|(_, client)| client.as_ref()) } - pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> { + pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Option<Arc<Client>>> { let config = match &language_config.language_server { Some(config) => config, - None => return Err(Error::LspNotDefined), + None => return Ok(None), }; match self.inner.entry(language_config.scope.clone()) { - Entry::Occupied(entry) => Ok(entry.get().1.clone()), + Entry::Occupied(entry) => Ok(Some(entry.get().1.clone())), Entry::Vacant(entry) => { // initialize a new client let id = self.counter.fetch_add(1, Ordering::Relaxed); @@ -356,11 +354,7 @@ impl Registry { .await; if let Err(e) = value { - if let Error::LspNotDefined = e { - // Skip logging "lsp not defined" - } else { - log::error!("failed to initialize language server: {}", e); - } + log::error!("failed to initialize language server: {}", e); return; } @@ -374,7 +368,7 @@ impl Registry { }); entry.insert((id, client.clone())); - Ok(client) + Ok(Some(client)) } } } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 64e95e33..7cb29c3b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1316,6 +1316,7 @@ impl Component for EditorView { if cx.editor.should_close() { return EventResult::Ignored(None); } + // if the focused view still exists and wasn't closed if cx.editor.tree.contains(focus) { let config = cx.editor.config(); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index b6947e44..5eff9983 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -853,6 +853,7 @@ impl Editor { ) }) .ok() + .flatten() }); if let Some(language_server) = language_server { // only spawn a new lang server if the servers aren't the same |