@@ -226,6 +226,8 @@ impl MethodCall {
227#[derive(Debug, PartialEq, Clone)]
227#[derive(Debug, PartialEq, Clone)]
228pub enum Notification {
228pub enum Notification {
229+ // we inject this notification to signal the LSP is ready
229 PublishDiagnostics(lsp::PublishDiagnosticsParams),
231 PublishDiagnostics(lsp::PublishDiagnosticsParams),
230 ShowMessage(lsp::ShowMessageParams),
232 ShowMessage(lsp::ShowMessageParams),
231 LogMessage(lsp::LogMessageParams),
233 LogMessage(lsp::LogMessageParams),
@@ -237,6 +239,7 @@ impl Notification {
237 use lsp::notification::Notification as _;
239 use lsp::notification::Notification as _;
239 let notification = match method {
241 let notification = match method {
242+ lsp::notification::Initialized::METHOD => Self::Initialized,
240 lsp::notification::PublishDiagnostics::METHOD => {
243 lsp::notification::PublishDiagnostics::METHOD => {
241 let params: lsp::PublishDiagnosticsParams = params
244 let params: lsp::PublishDiagnosticsParams = params
@@ -294,7 +297,7 @@ impl Registry {
297− pub fn get_by_id(&mut self, id: usize) -> Option<&Client> {
300+ pub fn get_by_id(&self, id: usize) -> Option<&Client> {
298 self.inner
301 self.inner
299 .values()
302 .values()
300 .find(|(client_id, _)| client_id == &id)
303 .find(|(client_id, _)| client_id == &id)
@@ -302,55 +305,52 @@ impl Registry {
304 pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
307 pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
305− if let Some(config) = &language_config.language_server {
308+ let config = match &language_config.language_server {
306− // avoid borrow issues
309+ Some(config) => config,
307− let inner = &mut self.inner;
310+ None => return Err(Error::LspNotDefined),
308− let s_incoming = &mut self.incoming;
311+ };
310− match inner.entry(language_config.scope.clone()) {
313+ match self.inner.entry(language_config.scope.clone()) {
311− Entry::Occupied(entry) => Ok(entry.get().1.clone()),
314+ Entry::Occupied(entry) => Ok(entry.get().1.clone()),
312− Entry::Vacant(entry) => {
315+ Entry::Vacant(entry) => {
313− // initialize a new client
316+ // initialize a new client
314− let id = self.counter.fetch_add(1, Ordering::Relaxed);
317+ let id = self.counter.fetch_add(1, Ordering::Relaxed);
315− let (client, incoming, initialize_notify) = Client::start(
318+ let (client, incoming, initialize_notify) = Client::start(
316− &config.command,
319+ &config.command,
317− &config.args,
320+ &config.args,
318− serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
321+ serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
321− s_incoming.push(UnboundedReceiverStream::new(incoming));
324+ self.incoming.push(UnboundedReceiverStream::new(incoming));
322− let client = Arc::new(client);
325+ let client = Arc::new(client);
324− let _client = client.clone();
325− // Initialize the client asynchronously
327+ // Initialize the client asynchronously
328+ let _client = client.clone();
326− tokio::spawn(async move {
329+ tokio::spawn(async move {
327− use futures_util::TryFutureExt;
330+ use futures_util::TryFutureExt;
328− let value = _client
331+ let value = _client
329− .capabilities
332+ .capabilities
330− .get_or_try_init(|| {
333+ .get_or_try_init(|| {
332− .initialize()
335+ .initialize()
333− .map_ok(|response| response.capabilities)
336+ .map_ok(|response| response.capabilities)
337− value.expect("failed to initialize capabilities");
340+ value.expect("failed to initialize capabilities");
339− // next up, notify<initialized>
342+ // next up, notify<initialized>
341− .notify::<lsp::notification::Initialized>(lsp::InitializedParams {})
344+ .notify::<lsp::notification::Initialized>(lsp::InitializedParams {})
343− .unwrap();
346+ .unwrap();
345− initialize_notify.notify_one();
348+ initialize_notify.notify_one();
348− entry.insert((id, client.clone()));
351+ entry.insert((id, client.clone()));
349− Ok(client)
352+ Ok(client)
353− Err(Error::LspNotDefined)