Skip to content

Commit

Permalink
Add error reply to server if document is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Jun 16, 2021
1 parent 5bc5816 commit ea2a78a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 10 additions & 3 deletions helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Notification {

#[derive(Debug)]
pub struct Registry {
inner: HashMap<LanguageId, Arc<Client>>,
inner: HashMap<LanguageId, (usize, Arc<Client>)>,

counter: AtomicUsize,
pub incoming: SelectAll<UnboundedReceiverStream<(usize, Call)>>,
Expand All @@ -267,14 +267,21 @@ impl Registry {
}
}

pub fn get_by_id(&mut self, id: usize) -> Option<&Client> {
self.inner
.values()
.find(|(client_id, _)| client_id == &id)
.map(|(_, client)| client.as_ref())
}

pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
if let Some(config) = &language_config.language_server {
// avoid borrow issues
let inner = &mut self.inner;
let s_incoming = &mut self.incoming;

match inner.entry(language_config.scope.clone()) {
Entry::Occupied(language_server) => Ok(language_server.get().clone()),
Entry::Occupied(entry) => Ok(entry.get().1.clone()),
Entry::Vacant(entry) => {
// initialize a new client
let id = self.counter.fetch_add(1, Ordering::Relaxed);
Expand All @@ -284,7 +291,7 @@ impl Registry {
s_incoming.push(UnboundedReceiverStream::new(incoming));
let client = Arc::new(client);

entry.insert(client.clone());
entry.insert((id, client.clone()));
Ok(client)
}
}
Expand Down
19 changes: 18 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,24 @@ impl Application {
helix_lsp::block_on(server.reply(id, Ok(serde_json::Value::Null)));
}
None => {
log::warn!("missing document with language server id {}", server_id)
if let Some(server) =
self.editor.language_servers.get_by_id(server_id)
{
log::warn!(
"missing document with language server id `{}`",
server_id
);
helix_lsp::block_on(server.reply(
id,
Err(helix_lsp::jsonrpc::Error {
code: helix_lsp::jsonrpc::ErrorCode::InternalError,
message: "document missing".to_string(),
data: None,
}),
));
} else {
log::warn!("can't find language server with id `{}`", server_id);
}
}
}
}
Expand Down

0 comments on commit ea2a78a

Please sign in to comment.