mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Remove LspNotDefined, instead return an Option<>
This commit is contained in:
parent
fe37a66046
commit
a123fb6057
@ -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 @@ pub fn get_by_id(&self, id: usize) -> Option<&Client> {
|
||||
.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 @@ pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Cli
|
||||
.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 @@ pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Cli
|
||||
});
|
||||
|
||||
entry.insert((id, client.clone()));
|
||||
Ok(client)
|
||||
Ok(Some(client))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1316,6 +1316,7 @@ fn handle_event(
|
||||
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();
|
||||
|
@ -853,6 +853,7 @@ fn launch_language_server(ls: &mut helix_lsp::Registry, doc: &mut Document) -> O
|
||||
)
|
||||
})
|
||||
.ok()
|
||||
.flatten()
|
||||
});
|
||||
if let Some(language_server) = language_server {
|
||||
// only spawn a new lang server if the servers aren't the same
|
||||
|
Loading…
Reference in New Issue
Block a user