Add channel to notify project when languages are added

This commit is contained in:
Isaac Clayton 2022-07-08 14:37:27 +02:00
parent 5cb59dfdab
commit 73620dad06
4 changed files with 80 additions and 4 deletions

View file

@ -122,11 +122,46 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
.await;
let project = Project::test(fs.clone(), ["/the-root".as_ref()], cx).await;
project.update(cx, |project, _| {
project.languages.add(Arc::new(rust_language));
// Open a buffer before languages have been added
let json_buffer = project
.update(cx, |project, cx| {
project.open_local_buffer("/the-root/package.json", cx)
})
.await
.unwrap();
// Assert that this buffer does not have a language
assert!(json_buffer.read_with(cx, |buffer, _| { buffer.language().is_none() }));
// Now we add the languages to the project, and subscribe to the watcher
project.update(cx, |project, cx| {
// Get a handle to the channel and clear out default item
let mut recv = project.languages.subscribe();
recv.blocking_recv();
// Add, then wait to be notified that JSON has been added
project.languages.add(Arc::new(json_language));
recv.blocking_recv();
// Add, then wait to be notified that Rust has been added
project.languages.add(Arc::new(rust_language));
recv.blocking_recv();
// Uncommenting this would cause the thread to block indefinitely:
// recv.blocking_recv();
// Force the assignment, we know the watcher has been notified
// but have no way to wait for the watcher to assign to the project
project.assign_language_to_buffer(&json_buffer, cx);
});
// Assert that the opened buffer does have a language, and that it is JSON
let name = json_buffer.read_with(cx, |buffer, _| buffer.language().map(|l| l.name()));
assert_eq!(name, Some("JSON".into()));
// Close the JSON buffer we opened
cx.update(|_| drop(json_buffer));
// Open a buffer without an associated language server.
let toml_buffer = project
.update(cx, |project, cx| {