WIP: Get everything compiling again and keep window open
This commit is contained in:
parent
605bdd62dd
commit
cfe3aae2de
10 changed files with 316 additions and 319 deletions
|
@ -68,9 +68,9 @@ pub trait UpdateView {
|
|||
pub struct App(Rc<RefCell<MutableAppContext>>);
|
||||
|
||||
impl App {
|
||||
pub fn test<T, F: Future<Output = T>>(
|
||||
asset_source: impl AssetSource,
|
||||
f: impl FnOnce(App) -> F,
|
||||
pub fn test<T, A: AssetSource, F: Future<Output = T>, G: FnOnce(App) -> F>(
|
||||
asset_source: A,
|
||||
f: G,
|
||||
) -> T {
|
||||
let platform = platform::current::app(); // TODO: Make a test platform app
|
||||
let foreground = Rc::new(executor::Foreground::test());
|
||||
|
@ -248,6 +248,14 @@ impl App {
|
|||
pub fn finish_pending_tasks(&self) -> impl Future<Output = ()> {
|
||||
self.0.borrow().finish_pending_tasks()
|
||||
}
|
||||
|
||||
pub fn fonts(&self) -> Arc<FontCache> {
|
||||
self.0.borrow().fonts.clone()
|
||||
}
|
||||
|
||||
pub fn platform(&self) -> Arc<dyn platform::App> {
|
||||
self.0.borrow().platform.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl UpdateModel for App {
|
||||
|
|
|
@ -99,7 +99,7 @@ impl Presenter {
|
|||
// }
|
||||
|
||||
// canvas.into_canvas().into_scene()
|
||||
todo!()
|
||||
Scene {}
|
||||
}
|
||||
|
||||
pub fn responder_chain(&self, app: &AppContext) -> Option<Vec<usize>> {
|
||||
|
|
|
@ -4,7 +4,7 @@ use rust_embed::RustEmbed;
|
|||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "assets"]
|
||||
struct Assets;
|
||||
pub struct Assets;
|
||||
|
||||
impl AssetSource for Assets {
|
||||
fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
|
||||
|
|
|
@ -1392,7 +1392,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_fold() -> Result<()> {
|
||||
let mut app = App::new().unwrap();
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| {
|
||||
Buffer::new(
|
||||
0,
|
||||
|
@ -1415,7 +1415,8 @@ mod tests {
|
|||
)
|
||||
});
|
||||
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
||||
let (_, view) = app.add_window(|ctx| BufferView::for_buffer(buffer.clone(), settings, ctx));
|
||||
let (_, view) =
|
||||
app.add_window(|ctx| BufferView::for_buffer(buffer.clone(), settings, ctx));
|
||||
|
||||
view.update(&mut app, |view, ctx| {
|
||||
view.select_ranges(Some(DisplayPoint::new(8, 0)..DisplayPoint::new(12, 0)), ctx)?;
|
||||
|
@ -1478,14 +1479,16 @@ mod tests {
|
|||
})?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_cursor() -> Result<()> {
|
||||
let mut app = App::new().unwrap();
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| Buffer::new(0, sample_text(6, 6)));
|
||||
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
||||
let (_, view) = app.add_window(|ctx| BufferView::for_buffer(buffer.clone(), settings, ctx));
|
||||
let (_, view) =
|
||||
app.add_window(|ctx| BufferView::for_buffer(buffer.clone(), settings, ctx));
|
||||
|
||||
buffer.update(&mut app, |buffer, ctx| {
|
||||
buffer.edit(
|
||||
|
@ -1513,6 +1516,7 @@ mod tests {
|
|||
})?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
impl BufferView {
|
||||
|
|
|
@ -460,7 +460,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_basic_folds() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
||||
|
||||
|
@ -510,11 +510,12 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlapping_folds() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||
app.read(|app| {
|
||||
let mut map = FoldMap::new(buffer.clone(), app);
|
||||
|
@ -530,11 +531,12 @@ mod tests {
|
|||
assert_eq!(map.text(app), "aa…eeeee");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_merging_folds_via_edit() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
||||
|
||||
|
@ -561,6 +563,7 @@ mod tests {
|
|||
assert_eq!(map.text(app), "aa…eeeee");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -573,7 +576,7 @@ mod tests {
|
|||
println!("{:?}", seed);
|
||||
let mut rng = StdRng::seed_from_u64(seed);
|
||||
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| {
|
||||
let len = rng.gen_range(0..10);
|
||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||
|
@ -629,6 +632,9 @@ mod tests {
|
|||
|
||||
Ok::<(), anyhow::Error>(())
|
||||
})?;
|
||||
|
||||
Ok::<(), anyhow::Error>(())
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -636,7 +642,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_buffer_rows() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let text = sample_text(6, 6) + "\n";
|
||||
let buffer = app.add_model(|_| Buffer::new(0, text));
|
||||
|
||||
|
@ -657,6 +663,7 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
impl FoldMap {
|
||||
|
|
|
@ -296,7 +296,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_chars_at() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let text = sample_text(6, 6);
|
||||
let buffer = app.add_model(|_| Buffer::new(0, text));
|
||||
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
||||
|
@ -336,6 +336,7 @@ mod tests {
|
|||
})?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -363,12 +364,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_max_point() -> Result<()> {
|
||||
let mut app = App::new()?;
|
||||
App::test((), |mut app| async move {
|
||||
let buffer = app.add_model(|_| Buffer::new(0, "aaa\n\t\tbbb"));
|
||||
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
||||
map.read(&app, |map, app| {
|
||||
assert_eq!(map.max_point(app), DisplayPoint::new(1, 11))
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,31 @@
|
|||
use fs::OpenOptions;
|
||||
use gpui::{
|
||||
executor,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
platform::{current as platform, App as _, Runner as _, WindowOptions},
|
||||
FontCache,
|
||||
};
|
||||
use gpui::platform::{current as platform, Runner as _};
|
||||
use log::LevelFilter;
|
||||
use simplelog::SimpleLogger;
|
||||
use std::{fs, mem, rc::Rc, sync::Arc};
|
||||
use std::{fs, mem, path::PathBuf};
|
||||
use zed::{
|
||||
editor, settings,
|
||||
assets, editor, settings,
|
||||
workspace::{self, OpenParams},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
init_logger();
|
||||
|
||||
let platform = Arc::new(platform::app());
|
||||
|
||||
let foreground = Rc::new(
|
||||
executor::Foreground::platform(platform.dispatcher())
|
||||
.expect("could not foreground create executor"),
|
||||
);
|
||||
|
||||
let font_cache = FontCache::new();
|
||||
|
||||
let (settings_tx, settings_rx) = settings::channel(&font_cache).unwrap();
|
||||
|
||||
let mut app = gpui::App::new(As).unwrap();
|
||||
let app = gpui::App::new(assets::Assets).unwrap();
|
||||
let (_, settings_rx) = settings::channel(&app.fonts()).unwrap();
|
||||
|
||||
{
|
||||
let mut app = app.clone();
|
||||
platform::runner()
|
||||
.on_finish_launching(move || {
|
||||
log::info!("finish launching");
|
||||
|
||||
workspace::init(&mut app);
|
||||
editor::init(&mut app);
|
||||
|
||||
if stdout_is_a_pty() {
|
||||
platform.activate(true);
|
||||
app.platform().activate(true);
|
||||
}
|
||||
|
||||
let paths = std::env::args()
|
||||
.skip(1)
|
||||
.filter_map(|arg| match fs::canonicalize(arg) {
|
||||
Ok(path) => Some(path),
|
||||
Err(error) => {
|
||||
log::error!("error parsing path argument: {}", error);
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let paths = collect_path_args();
|
||||
if !paths.is_empty() {
|
||||
app.dispatch_global_action(
|
||||
"workspace:open_paths",
|
||||
|
@ -59,22 +34,10 @@ fn main() {
|
|||
settings: settings_rx,
|
||||
},
|
||||
);
|
||||
mem::forget(app); // This is here until we hold on to the app for some reason
|
||||
}
|
||||
|
||||
// let window = platform
|
||||
// .open_window(
|
||||
// WindowOptions {
|
||||
// bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)),
|
||||
// title: Some("Zed"),
|
||||
// },
|
||||
// foreground,
|
||||
// )
|
||||
// .expect("error opening window");
|
||||
|
||||
// mem::forget(window); // Leak window for now so it doesn't close
|
||||
})
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logger() {
|
||||
|
@ -101,3 +64,16 @@ fn init_logger() {
|
|||
fn stdout_is_a_pty() -> bool {
|
||||
unsafe { libc::isatty(libc::STDOUT_FILENO as i32) != 0 }
|
||||
}
|
||||
|
||||
fn collect_path_args() -> Vec<PathBuf> {
|
||||
std::env::args()
|
||||
.skip(1)
|
||||
.filter_map(|arg| match fs::canonicalize(arg) {
|
||||
Ok(path) => Some(path),
|
||||
Err(error) => {
|
||||
log::error!("error parsing path argument: {}", error);
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_open_paths_action() {
|
||||
App::test(|mut app| async move {
|
||||
App::test((), |mut app| async move {
|
||||
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
||||
|
||||
init(&mut app);
|
||||
|
|
|
@ -228,7 +228,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_open_entry() -> Result<(), Arc<anyhow::Error>> {
|
||||
App::test(|mut app| async move {
|
||||
App::test((), |mut app| async move {
|
||||
let dir = temp_tree(json!({
|
||||
"a": {
|
||||
"aa": "aa contents",
|
||||
|
|
|
@ -331,7 +331,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_open_entry() -> Result<()> {
|
||||
App::test(|mut app| async move {
|
||||
App::test((), |mut app| async move {
|
||||
let dir = temp_tree(json!({
|
||||
"a": {
|
||||
"aa": "aa contents",
|
||||
|
@ -399,7 +399,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_pane_actions() -> Result<()> {
|
||||
App::test(|mut app| async move {
|
||||
App::test((), |mut app| async move {
|
||||
pane::init(&mut app);
|
||||
|
||||
let dir = temp_tree(json!({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue