Here I'm exploring a new approach to the project-wide diagnostics view that can exactly mirror the contents of cargo check. The `FragmentList` composes an arbitrary list of fragments from other buffers and presents them as if they were a single buffer.
34 lines
801 B
Rust
34 lines
801 B
Rust
use gpui::{Entity, ModelHandle};
|
|
use smol::channel;
|
|
use std::marker::PhantomData;
|
|
|
|
#[cfg(test)]
|
|
#[ctor::ctor]
|
|
fn init_logger() {
|
|
// std::env::set_var("RUST_LOG", "info");
|
|
env_logger::init();
|
|
}
|
|
|
|
pub struct Observer<T>(PhantomData<T>);
|
|
|
|
impl<T: 'static> Entity for Observer<T> {
|
|
type Event = ();
|
|
}
|
|
|
|
impl<T: Entity> Observer<T> {
|
|
pub fn new(
|
|
handle: &ModelHandle<T>,
|
|
cx: &mut gpui::TestAppContext,
|
|
) -> (ModelHandle<Self>, channel::Receiver<()>) {
|
|
let (notify_tx, notify_rx) = channel::unbounded();
|
|
let observer = cx.add_model(|cx| {
|
|
cx.observe(handle, move |_, _, _| {
|
|
let _ = notify_tx.try_send(());
|
|
})
|
|
.detach();
|
|
Observer(PhantomData)
|
|
});
|
|
(observer, notify_rx)
|
|
}
|
|
}
|