Uncomment copilot2 tests

This commit is contained in:
Piotr Osiewicz 2023-12-01 22:04:43 +01:00
parent be509a5ce0
commit d81fb3680e
3 changed files with 209 additions and 207 deletions

2
Cargo.lock generated
View file

@ -2098,7 +2098,7 @@ dependencies = [
"lsp2", "lsp2",
"node_runtime", "node_runtime",
"parking_lot 0.11.2", "parking_lot 0.11.2",
"rpc", "rpc2",
"serde", "serde",
"serde_derive", "serde_derive",
"settings2", "settings2",

View file

@ -45,6 +45,6 @@ fs = { path = "../fs", features = ["test-support"] }
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] } gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
language = { package = "language2", path = "../language2", features = ["test-support"] } language = { package = "language2", path = "../language2", features = ["test-support"] }
lsp = { package = "lsp2", path = "../lsp2", features = ["test-support"] } lsp = { package = "lsp2", path = "../lsp2", features = ["test-support"] }
rpc = { path = "../rpc", features = ["test-support"] } rpc = { package = "rpc2", path = "../rpc2", features = ["test-support"] }
settings = { package = "settings2", path = "../settings2", features = ["test-support"] } settings = { package = "settings2", path = "../settings2", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] } util = { path = "../util", features = ["test-support"] }

View file

@ -1002,229 +1002,231 @@ async fn get_copilot_lsp(http: Arc<dyn HttpClient>) -> anyhow::Result<PathBuf> {
} }
} }
// #[cfg(test)] #[cfg(test)]
// mod tests { mod tests {
// use super::*; use super::*;
// use gpui::{executor::Deterministic, TestAppContext}; use gpui::TestAppContext;
// #[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
// async fn test_buffer_management(deterministic: Arc<Deterministic>, cx: &mut TestAppContext) { async fn test_buffer_management(cx: &mut TestAppContext) {
// deterministic.forbid_parking(); let (copilot, mut lsp) = Copilot::fake(cx);
// let (copilot, mut lsp) = Copilot::fake(cx);
// let buffer_1 = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, "Hello")); let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Hello"));
// let buffer_1_uri: lsp::Url = format!("buffer://{}", buffer_1.id()).parse().unwrap(); let buffer_1_uri: lsp::Url = format!("buffer://{}", buffer_1.entity_id().as_u64())
// copilot.update(cx, |copilot, cx| copilot.register_buffer(&buffer_1, cx)); .parse()
// assert_eq!( .unwrap();
// lsp.receive_notification::<lsp::notification::DidOpenTextDocument>() copilot.update(cx, |copilot, cx| copilot.register_buffer(&buffer_1, cx));
// .await, assert_eq!(
// lsp::DidOpenTextDocumentParams { lsp.receive_notification::<lsp::notification::DidOpenTextDocument>()
// text_document: lsp::TextDocumentItem::new( .await,
// buffer_1_uri.clone(), lsp::DidOpenTextDocumentParams {
// "plaintext".into(), text_document: lsp::TextDocumentItem::new(
// 0, buffer_1_uri.clone(),
// "Hello".into() "plaintext".into(),
// ), 0,
// } "Hello".into()
// ); ),
}
);
// let buffer_2 = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, "Goodbye")); let buffer_2 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Goodbye"));
// let buffer_2_uri: lsp::Url = format!("buffer://{}", buffer_2.id()).parse().unwrap(); let buffer_2_uri: lsp::Url = format!("buffer://{}", buffer_2.entity_id().as_u64())
// copilot.update(cx, |copilot, cx| copilot.register_buffer(&buffer_2, cx)); .parse()
// assert_eq!( .unwrap();
// lsp.receive_notification::<lsp::notification::DidOpenTextDocument>() copilot.update(cx, |copilot, cx| copilot.register_buffer(&buffer_2, cx));
// .await, assert_eq!(
// lsp::DidOpenTextDocumentParams { lsp.receive_notification::<lsp::notification::DidOpenTextDocument>()
// text_document: lsp::TextDocumentItem::new( .await,
// buffer_2_uri.clone(), lsp::DidOpenTextDocumentParams {
// "plaintext".into(), text_document: lsp::TextDocumentItem::new(
// 0, buffer_2_uri.clone(),
// "Goodbye".into() "plaintext".into(),
// ), 0,
// } "Goodbye".into()
// ); ),
}
);
// buffer_1.update(cx, |buffer, cx| buffer.edit([(5..5, " world")], None, cx)); buffer_1.update(cx, |buffer, cx| buffer.edit([(5..5, " world")], None, cx));
// assert_eq!( assert_eq!(
// lsp.receive_notification::<lsp::notification::DidChangeTextDocument>() lsp.receive_notification::<lsp::notification::DidChangeTextDocument>()
// .await, .await,
// lsp::DidChangeTextDocumentParams { lsp::DidChangeTextDocumentParams {
// text_document: lsp::VersionedTextDocumentIdentifier::new(buffer_1_uri.clone(), 1), text_document: lsp::VersionedTextDocumentIdentifier::new(buffer_1_uri.clone(), 1),
// content_changes: vec![lsp::TextDocumentContentChangeEvent { content_changes: vec![lsp::TextDocumentContentChangeEvent {
// range: Some(lsp::Range::new( range: Some(lsp::Range::new(
// lsp::Position::new(0, 5), lsp::Position::new(0, 5),
// lsp::Position::new(0, 5) lsp::Position::new(0, 5)
// )), )),
// range_length: None, range_length: None,
// text: " world".into(), text: " world".into(),
// }], }],
// } }
// ); );
// // Ensure updates to the file are reflected in the LSP. // Ensure updates to the file are reflected in the LSP.
// buffer_1 buffer_1.update(cx, |buffer, cx| {
// .update(cx, |buffer, cx| { buffer.file_updated(
// buffer.file_updated( Arc::new(File {
// Arc::new(File { abs_path: "/root/child/buffer-1".into(),
// abs_path: "/root/child/buffer-1".into(), path: Path::new("child/buffer-1").into(),
// path: Path::new("child/buffer-1").into(), }),
// }), cx,
// cx, )
// ) });
// }) assert_eq!(
// .await; lsp.receive_notification::<lsp::notification::DidCloseTextDocument>()
// assert_eq!( .await,
// lsp.receive_notification::<lsp::notification::DidCloseTextDocument>() lsp::DidCloseTextDocumentParams {
// .await, text_document: lsp::TextDocumentIdentifier::new(buffer_1_uri),
// lsp::DidCloseTextDocumentParams { }
// text_document: lsp::TextDocumentIdentifier::new(buffer_1_uri), );
// } let buffer_1_uri = lsp::Url::from_file_path("/root/child/buffer-1").unwrap();
// ); assert_eq!(
// let buffer_1_uri = lsp::Url::from_file_path("/root/child/buffer-1").unwrap(); lsp.receive_notification::<lsp::notification::DidOpenTextDocument>()
// assert_eq!( .await,
// lsp.receive_notification::<lsp::notification::DidOpenTextDocument>() lsp::DidOpenTextDocumentParams {
// .await, text_document: lsp::TextDocumentItem::new(
// lsp::DidOpenTextDocumentParams { buffer_1_uri.clone(),
// text_document: lsp::TextDocumentItem::new( "plaintext".into(),
// buffer_1_uri.clone(), 1,
// "plaintext".into(), "Hello world".into()
// 1, ),
// "Hello world".into() }
// ), );
// }
// );
// // Ensure all previously-registered buffers are closed when signing out. // Ensure all previously-registered buffers are closed when signing out.
// lsp.handle_request::<request::SignOut, _, _>(|_, _| async { lsp.handle_request::<request::SignOut, _, _>(|_, _| async {
// Ok(request::SignOutResult {}) Ok(request::SignOutResult {})
// }); });
// copilot copilot
// .update(cx, |copilot, cx| copilot.sign_out(cx)) .update(cx, |copilot, cx| copilot.sign_out(cx))
// .await .await
// .unwrap(); .unwrap();
// assert_eq!( // todo!() po: these notifications now happen in reverse order?
// lsp.receive_notification::<lsp::notification::DidCloseTextDocument>() assert_eq!(
// .await, lsp.receive_notification::<lsp::notification::DidCloseTextDocument>()
// lsp::DidCloseTextDocumentParams { .await,
// text_document: lsp::TextDocumentIdentifier::new(buffer_2_uri.clone()), lsp::DidCloseTextDocumentParams {
// } text_document: lsp::TextDocumentIdentifier::new(buffer_2_uri.clone()),
// ); }
// assert_eq!( );
// lsp.receive_notification::<lsp::notification::DidCloseTextDocument>() assert_eq!(
// .await, lsp.receive_notification::<lsp::notification::DidCloseTextDocument>()
// lsp::DidCloseTextDocumentParams { .await,
// text_document: lsp::TextDocumentIdentifier::new(buffer_1_uri.clone()), lsp::DidCloseTextDocumentParams {
// } text_document: lsp::TextDocumentIdentifier::new(buffer_1_uri.clone()),
// ); }
);
// // Ensure all previously-registered buffers are re-opened when signing in. // Ensure all previously-registered buffers are re-opened when signing in.
// lsp.handle_request::<request::SignInInitiate, _, _>(|_, _| async { lsp.handle_request::<request::SignInInitiate, _, _>(|_, _| async {
// Ok(request::SignInInitiateResult::AlreadySignedIn { Ok(request::SignInInitiateResult::AlreadySignedIn {
// user: "user-1".into(), user: "user-1".into(),
// }) })
// }); });
// copilot copilot
// .update(cx, |copilot, cx| copilot.sign_in(cx)) .update(cx, |copilot, cx| copilot.sign_in(cx))
// .await .await
// .unwrap(); .unwrap();
// assert_eq!( assert_eq!(
// lsp.receive_notification::<lsp::notification::DidOpenTextDocument>() lsp.receive_notification::<lsp::notification::DidOpenTextDocument>()
// .await, .await,
// lsp::DidOpenTextDocumentParams { lsp::DidOpenTextDocumentParams {
// text_document: lsp::TextDocumentItem::new( text_document: lsp::TextDocumentItem::new(
// buffer_2_uri.clone(), buffer_2_uri.clone(),
// "plaintext".into(), "plaintext".into(),
// 0, 0,
// "Goodbye".into() "Goodbye".into()
// ), ),
// } }
// ); );
// assert_eq!( assert_eq!(
// lsp.receive_notification::<lsp::notification::DidOpenTextDocument>() lsp.receive_notification::<lsp::notification::DidOpenTextDocument>()
// .await, .await,
// lsp::DidOpenTextDocumentParams { lsp::DidOpenTextDocumentParams {
// text_document: lsp::TextDocumentItem::new( text_document: lsp::TextDocumentItem::new(
// buffer_1_uri.clone(), buffer_1_uri.clone(),
// "plaintext".into(), "plaintext".into(),
// 0, 0,
// "Hello world".into() "Hello world".into()
// ), ),
// } }
// ); );
// // Dropping a buffer causes it to be closed on the LSP side as well. // Dropping a buffer causes it to be closed on the LSP side as well.
// cx.update(|_| drop(buffer_2)); cx.update(|_| drop(buffer_2));
// assert_eq!( assert_eq!(
// lsp.receive_notification::<lsp::notification::DidCloseTextDocument>() lsp.receive_notification::<lsp::notification::DidCloseTextDocument>()
// .await, .await,
// lsp::DidCloseTextDocumentParams { lsp::DidCloseTextDocumentParams {
// text_document: lsp::TextDocumentIdentifier::new(buffer_2_uri), text_document: lsp::TextDocumentIdentifier::new(buffer_2_uri),
// } }
// ); );
// } }
// struct File { struct File {
// abs_path: PathBuf, abs_path: PathBuf,
// path: Arc<Path>, path: Arc<Path>,
// } }
// impl language2::File for File { impl language::File for File {
// fn as_local(&self) -> Option<&dyn language2::LocalFile> { fn as_local(&self) -> Option<&dyn language::LocalFile> {
// Some(self) Some(self)
// } }
// fn mtime(&self) -> std::time::SystemTime { fn mtime(&self) -> std::time::SystemTime {
// unimplemented!() unimplemented!()
// } }
// fn path(&self) -> &Arc<Path> { fn path(&self) -> &Arc<Path> {
// &self.path &self.path
// } }
// fn full_path(&self, _: &AppContext) -> PathBuf { fn full_path(&self, _: &AppContext) -> PathBuf {
// unimplemented!() unimplemented!()
// } }
// fn file_name<'a>(&'a self, _: &'a AppContext) -> &'a std::ffi::OsStr { fn file_name<'a>(&'a self, _: &'a AppContext) -> &'a std::ffi::OsStr {
// unimplemented!() unimplemented!()
// } }
// fn is_deleted(&self) -> bool { fn is_deleted(&self) -> bool {
// unimplemented!() unimplemented!()
// } }
// fn as_any(&self) -> &dyn std::any::Any { fn as_any(&self) -> &dyn std::any::Any {
// unimplemented!() unimplemented!()
// } }
// fn to_proto(&self) -> rpc::proto::File { fn to_proto(&self) -> rpc::proto::File {
// unimplemented!() unimplemented!()
// } }
// fn worktree_id(&self) -> usize { fn worktree_id(&self) -> usize {
// 0 0
// } }
// } }
// impl language::LocalFile for File { impl language::LocalFile for File {
// fn abs_path(&self, _: &AppContext) -> PathBuf { fn abs_path(&self, _: &AppContext) -> PathBuf {
// self.abs_path.clone() self.abs_path.clone()
// } }
// fn load(&self, _: &AppContext) -> Task<Result<String>> { fn load(&self, _: &AppContext) -> Task<Result<String>> {
// unimplemented!() unimplemented!()
// } }
// fn buffer_reloaded( fn buffer_reloaded(
// &self, &self,
// _: u64, _: u64,
// _: &clock::Global, _: &clock::Global,
// _: language::RopeFingerprint, _: language::RopeFingerprint,
// _: language::LineEnding, _: language::LineEnding,
// _: std::time::SystemTime, _: std::time::SystemTime,
// _: &mut AppContext, _: &mut AppContext,
// ) { ) {
// unimplemented!() unimplemented!()
// } }
// } }
// } }