From 2d6d10f920d95d7e8a61c4521522bdede37a4ef9 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 25 Oct 2021 19:46:33 +0200 Subject: [PATCH] Log unhandled notifications in `LanguageServer` Co-Authored-By: Nathan Sobo Co-Authored-By: Max Brunsfeld --- crates/lsp/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index 104ab2677e..e80ad55947 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -3,7 +3,7 @@ use gpui::{executor, AppContext, Task}; use parking_lot::{Mutex, RwLock}; use postage::{barrier, oneshot, prelude::Stream, sink::Sink}; use serde::{Deserialize, Serialize}; -use serde_json::{json, value::RawValue}; +use serde_json::{json, value::RawValue, Value}; use smol::{ channel, io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}, @@ -13,6 +13,7 @@ use std::{ collections::HashMap, future::Future, io::Write, + str::FromStr, sync::{ atomic::{AtomicUsize, Ordering::SeqCst}, Arc, @@ -135,6 +136,15 @@ impl LanguageServer { { if let Some(handler) = notification_handlers.read().get(method) { handler(params.get()); + } else { + log::info!( + "unhandled notification {}:\n{}", + method, + serde_json::to_string_pretty( + &Value::from_str(params.get()).unwrap() + ) + .unwrap() + ); } } else if let Ok(Response { id, error, result }) = serde_json::from_slice(&buffer) @@ -347,6 +357,12 @@ mod tests { #[gpui::test] async fn test_basic(cx: TestAppContext) { + let lib_source = r#" + fn fun() { + let hello = "world"; + } + "# + .unindent(); let root_dir = temp_tree(json!({ "Cargo.toml": r#" [package] @@ -355,23 +371,33 @@ mod tests { edition = "2018" "#.unindent(), "src": { - "lib.rs": r#" - fn fun() { - let hello = "world"; - } - "#.unindent() + "lib.rs": &lib_source } })); + let lib_file_uri = + lsp_types::Url::from_file_path(root_dir.path().join("src/lib.rs")).unwrap(); let server = cx.read(|cx| LanguageServer::rust(root_dir.path(), cx).unwrap()); server.next_idle_notification().await; + server + .notify::( + lsp_types::DidOpenTextDocumentParams { + text_document: lsp_types::TextDocumentItem::new( + lib_file_uri.clone(), + "rust".to_string(), + 0, + lib_source, + ), + }, + ) + .await + .unwrap(); + let hover = server .request::(lsp_types::HoverParams { text_document_position_params: lsp_types::TextDocumentPositionParams { - text_document: lsp_types::TextDocumentIdentifier::new( - lsp_types::Url::from_file_path(root_dir.path().join("src/lib.rs")).unwrap(), - ), + text_document: lsp_types::TextDocumentIdentifier::new(lib_file_uri), position: lsp_types::Position::new(1, 21), }, work_done_progress_params: Default::default(),