From b7efab8a55cf4037ee6aee95f9754fb7fb720e97 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 2 Nov 2023 11:42:48 -0400 Subject: [PATCH] Uncomment lsp2 tests --- crates/lsp2/src/lsp2.rs | 128 ++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/crates/lsp2/src/lsp2.rs b/crates/lsp2/src/lsp2.rs index ed67a5c9c2..8871c8eaef 100644 --- a/crates/lsp2/src/lsp2.rs +++ b/crates/lsp2/src/lsp2.rs @@ -1107,74 +1107,74 @@ impl FakeLanguageServer { } } -// #[cfg(test)] -// mod tests { -// use super::*; -// use gpui::TestAppContext; +#[cfg(test)] +mod tests { + use super::*; + use gpui2::TestAppContext; -// #[ctor::ctor] -// fn init_logger() { -// if std::env::var("RUST_LOG").is_ok() { -// env_logger::init(); -// } -// } + #[ctor::ctor] + fn init_logger() { + if std::env::var("RUST_LOG").is_ok() { + env_logger::init(); + } + } -// #[gpui::test] -// async fn test_fake(cx: &mut TestAppContext) { -// let (server, mut fake) = -// LanguageServer::fake("the-lsp".to_string(), Default::default(), cx.to_async()); + #[gpui2::test] + async fn test_fake(cx: &mut TestAppContext) { + let (server, mut fake) = + LanguageServer::fake("the-lsp".to_string(), Default::default(), cx.to_async()); -// let (message_tx, message_rx) = channel::unbounded(); -// let (diagnostics_tx, diagnostics_rx) = channel::unbounded(); -// server -// .on_notification::(move |params, _| { -// message_tx.try_send(params).unwrap() -// }) -// .detach(); -// server -// .on_notification::(move |params, _| { -// diagnostics_tx.try_send(params).unwrap() -// }) -// .detach(); + let (message_tx, message_rx) = channel::unbounded(); + let (diagnostics_tx, diagnostics_rx) = channel::unbounded(); + server + .on_notification::(move |params, _| { + message_tx.try_send(params).unwrap() + }) + .detach(); + server + .on_notification::(move |params, _| { + diagnostics_tx.try_send(params).unwrap() + }) + .detach(); -// let server = server.initialize(None).await.unwrap(); -// server -// .notify::(DidOpenTextDocumentParams { -// text_document: TextDocumentItem::new( -// Url::from_str("file://a/b").unwrap(), -// "rust".to_string(), -// 0, -// "".to_string(), -// ), -// }) -// .unwrap(); -// assert_eq!( -// fake.receive_notification::() -// .await -// .text_document -// .uri -// .as_str(), -// "file://a/b" -// ); + let server = server.initialize(None).await.unwrap(); + server + .notify::(DidOpenTextDocumentParams { + text_document: TextDocumentItem::new( + Url::from_str("file://a/b").unwrap(), + "rust".to_string(), + 0, + "".to_string(), + ), + }) + .unwrap(); + assert_eq!( + fake.receive_notification::() + .await + .text_document + .uri + .as_str(), + "file://a/b" + ); -// fake.notify::(ShowMessageParams { -// typ: MessageType::ERROR, -// message: "ok".to_string(), -// }); -// fake.notify::(PublishDiagnosticsParams { -// uri: Url::from_str("file://b/c").unwrap(), -// version: Some(5), -// diagnostics: vec![], -// }); -// assert_eq!(message_rx.recv().await.unwrap().message, "ok"); -// assert_eq!( -// diagnostics_rx.recv().await.unwrap().uri.as_str(), -// "file://b/c" -// ); + fake.notify::(ShowMessageParams { + typ: MessageType::ERROR, + message: "ok".to_string(), + }); + fake.notify::(PublishDiagnosticsParams { + uri: Url::from_str("file://b/c").unwrap(), + version: Some(5), + diagnostics: vec![], + }); + assert_eq!(message_rx.recv().await.unwrap().message, "ok"); + assert_eq!( + diagnostics_rx.recv().await.unwrap().uri.as_str(), + "file://b/c" + ); -// fake.handle_request::(|_, _| async move { Ok(()) }); + fake.handle_request::(|_, _| async move { Ok(()) }); -// drop(server); -// fake.receive_notification::().await; -// } -// } + drop(server); + fake.receive_notification::().await; + } +}