Handle initialize request internally in fake lsp server

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-10-25 18:04:27 -07:00
parent 6384950d56
commit c3ff489fee

View File

@ -14,7 +14,6 @@ use std::{
collections::HashMap, collections::HashMap,
future::Future, future::Future,
io::Write, io::Write,
marker::PhantomData,
str::FromStr, str::FromStr,
sync::{ sync::{
atomic::{AtomicUsize, Ordering::SeqCst}, atomic::{AtomicUsize, Ordering::SeqCst},
@ -403,14 +402,20 @@ impl LanguageServer {
pub async fn fake(executor: &executor::Background) -> (Arc<Self>, FakeLanguageServer) { pub async fn fake(executor: &executor::Background) -> (Arc<Self>, FakeLanguageServer) {
let stdin = async_pipe::pipe(); let stdin = async_pipe::pipe();
let stdout = async_pipe::pipe(); let stdout = async_pipe::pipe();
( let mut fake = FakeLanguageServer {
Self::new_internal(Path::new("/"), stdin.0, stdout.1, executor).unwrap(), stdin: smol::io::BufReader::new(stdin.1),
FakeLanguageServer { stdout: smol::io::BufWriter::new(stdout.0),
stdin: smol::io::BufReader::new(stdin.1), buffer: Vec::new(),
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::<request::Initialize>().await;
fake.respond(init_id, InitializeResult::default()).await;
fake.receive_notification::<notification::Initialized>()
.await;
(server, fake)
} }
} }
@ -449,7 +454,7 @@ impl FakeLanguageServer {
( (
RequestId { RequestId {
id: request.id, id: request.id,
_type: PhantomData, _type: std::marker::PhantomData,
}, },
request.params, request.params,
) )
@ -584,11 +589,6 @@ mod tests {
}) })
.detach(); .detach();
let (init_id, _) = fake.receive_request::<request::Initialize>().await;
fake.respond(init_id, InitializeResult::default()).await;
fake.receive_notification::<notification::Initialized>()
.await;
server server
.notify::<notification::DidOpenTextDocument>(DidOpenTextDocumentParams { .notify::<notification::DidOpenTextDocument>(DidOpenTextDocumentParams {
text_document: TextDocumentItem::new( text_document: TextDocumentItem::new(