|
|
@ -226,6 +226,8 @@ impl MethodCall {
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
pub enum Notification {
|
|
|
|
pub enum Notification {
|
|
|
|
|
|
|
|
// we inject this notification to signal the LSP is ready
|
|
|
|
|
|
|
|
Initialized,
|
|
|
|
PublishDiagnostics(lsp::PublishDiagnosticsParams),
|
|
|
|
PublishDiagnostics(lsp::PublishDiagnosticsParams),
|
|
|
|
ShowMessage(lsp::ShowMessageParams),
|
|
|
|
ShowMessage(lsp::ShowMessageParams),
|
|
|
|
LogMessage(lsp::LogMessageParams),
|
|
|
|
LogMessage(lsp::LogMessageParams),
|
|
|
@ -237,6 +239,7 @@ impl Notification {
|
|
|
|
use lsp::notification::Notification as _;
|
|
|
|
use lsp::notification::Notification as _;
|
|
|
|
|
|
|
|
|
|
|
|
let notification = match method {
|
|
|
|
let notification = match method {
|
|
|
|
|
|
|
|
lsp::notification::Initialized::METHOD => Self::Initialized,
|
|
|
|
lsp::notification::PublishDiagnostics::METHOD => {
|
|
|
|
lsp::notification::PublishDiagnostics::METHOD => {
|
|
|
|
let params: lsp::PublishDiagnosticsParams = params
|
|
|
|
let params: lsp::PublishDiagnosticsParams = params
|
|
|
|
.parse()
|
|
|
|
.parse()
|
|
|
@ -294,7 +297,7 @@ impl Registry {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_by_id(&mut self, id: usize) -> Option<&Client> {
|
|
|
|
pub fn get_by_id(&self, id: usize) -> Option<&Client> {
|
|
|
|
self.inner
|
|
|
|
self.inner
|
|
|
|
.values()
|
|
|
|
.values()
|
|
|
|
.find(|(client_id, _)| client_id == &id)
|
|
|
|
.find(|(client_id, _)| client_id == &id)
|
|
|
@ -302,55 +305,52 @@ impl Registry {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
|
|
|
|
pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
|
|
|
|
if let Some(config) = &language_config.language_server {
|
|
|
|
let config = match &language_config.language_server {
|
|
|
|
// avoid borrow issues
|
|
|
|
Some(config) => config,
|
|
|
|
let inner = &mut self.inner;
|
|
|
|
None => return Err(Error::LspNotDefined),
|
|
|
|
let s_incoming = &mut self.incoming;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
match inner.entry(language_config.scope.clone()) {
|
|
|
|
match self.inner.entry(language_config.scope.clone()) {
|
|
|
|
Entry::Occupied(entry) => Ok(entry.get().1.clone()),
|
|
|
|
Entry::Occupied(entry) => Ok(entry.get().1.clone()),
|
|
|
|
Entry::Vacant(entry) => {
|
|
|
|
Entry::Vacant(entry) => {
|
|
|
|
// initialize a new client
|
|
|
|
// initialize a new client
|
|
|
|
let id = self.counter.fetch_add(1, Ordering::Relaxed);
|
|
|
|
let id = self.counter.fetch_add(1, Ordering::Relaxed);
|
|
|
|
let (client, incoming, initialize_notify) = Client::start(
|
|
|
|
let (client, incoming, initialize_notify) = Client::start(
|
|
|
|
&config.command,
|
|
|
|
&config.command,
|
|
|
|
&config.args,
|
|
|
|
&config.args,
|
|
|
|
serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
|
|
|
|
serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
)?;
|
|
|
|
)?;
|
|
|
|
s_incoming.push(UnboundedReceiverStream::new(incoming));
|
|
|
|
self.incoming.push(UnboundedReceiverStream::new(incoming));
|
|
|
|
let client = Arc::new(client);
|
|
|
|
let client = Arc::new(client);
|
|
|
|
|
|
|
|
|
|
|
|
let _client = client.clone();
|
|
|
|
// Initialize the client asynchronously
|
|
|
|
// Initialize the client asynchronously
|
|
|
|
let _client = client.clone();
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
use futures_util::TryFutureExt;
|
|
|
|
use futures_util::TryFutureExt;
|
|
|
|
let value = _client
|
|
|
|
let value = _client
|
|
|
|
.capabilities
|
|
|
|
.capabilities
|
|
|
|
.get_or_try_init(|| {
|
|
|
|
.get_or_try_init(|| {
|
|
|
|
_client
|
|
|
|
_client
|
|
|
|
.initialize()
|
|
|
|
.initialize()
|
|
|
|
.map_ok(|response| response.capabilities)
|
|
|
|
.map_ok(|response| response.capabilities)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
|
|
value.expect("failed to initialize capabilities");
|
|
|
|
value.expect("failed to initialize capabilities");
|
|
|
|
|
|
|
|
|
|
|
|
// next up, notify<initialized>
|
|
|
|
// next up, notify<initialized>
|
|
|
|
_client
|
|
|
|
_client
|
|
|
|
.notify::<lsp::notification::Initialized>(lsp::InitializedParams {})
|
|
|
|
.notify::<lsp::notification::Initialized>(lsp::InitializedParams {})
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
initialize_notify.notify_one();
|
|
|
|
initialize_notify.notify_one();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
entry.insert((id, client.clone()));
|
|
|
|
entry.insert((id, client.clone()));
|
|
|
|
Ok(client)
|
|
|
|
Ok(client)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(Error::LspNotDefined)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|