From c3ff489fee393e4d9a0cd82a6971101e19db14ee Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 25 Oct 2021 18:04:27 -0700 Subject: [PATCH] Handle initialize request internally in fake lsp server Co-Authored-By: Nathan Sobo --- crates/lsp/src/lib.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index ea770c7422..60e5ba9065 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -14,7 +14,6 @@ use std::{ collections::HashMap, future::Future, io::Write, - marker::PhantomData, str::FromStr, sync::{ atomic::{AtomicUsize, Ordering::SeqCst}, @@ -403,14 +402,20 @@ impl LanguageServer { pub async fn fake(executor: &executor::Background) -> (Arc, FakeLanguageServer) { let stdin = async_pipe::pipe(); let stdout = async_pipe::pipe(); - ( - Self::new_internal(Path::new("/"), stdin.0, stdout.1, executor).unwrap(), - FakeLanguageServer { - stdin: smol::io::BufReader::new(stdin.1), - stdout: smol::io::BufWriter::new(stdout.0), - buffer: Vec::new(), - }, - ) + let mut fake = FakeLanguageServer { + stdin: smol::io::BufReader::new(stdin.1), + stdout: smol::io::BufWriter::new(stdout.0), + buffer: Vec::new(), + }; + + let server = Self::new_internal(Path::new("/"), stdin.0, stdout.1, executor).unwrap(); + + let (init_id, _) = fake.receive_request::().await; + fake.respond(init_id, InitializeResult::default()).await; + fake.receive_notification::() + .await; + + (server, fake) } } @@ -449,7 +454,7 @@ impl FakeLanguageServer { ( RequestId { id: request.id, - _type: PhantomData, + _type: std::marker::PhantomData, }, request.params, ) @@ -584,11 +589,6 @@ mod tests { }) .detach(); - let (init_id, _) = fake.receive_request::().await; - fake.respond(init_id, InitializeResult::default()).await; - fake.receive_notification::() - .await; - server .notify::(DidOpenTextDocumentParams { text_document: TextDocumentItem::new(