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>>);
|
pub struct App(Rc<RefCell<MutableAppContext>>);
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn test<T, F: Future<Output = T>>(
|
pub fn test<T, A: AssetSource, F: Future<Output = T>, G: FnOnce(App) -> F>(
|
||||||
asset_source: impl AssetSource,
|
asset_source: A,
|
||||||
f: impl FnOnce(App) -> F,
|
f: G,
|
||||||
) -> T {
|
) -> T {
|
||||||
let platform = platform::current::app(); // TODO: Make a test platform app
|
let platform = platform::current::app(); // TODO: Make a test platform app
|
||||||
let foreground = Rc::new(executor::Foreground::test());
|
let foreground = Rc::new(executor::Foreground::test());
|
||||||
|
@ -248,6 +248,14 @@ impl App {
|
||||||
pub fn finish_pending_tasks(&self) -> impl Future<Output = ()> {
|
pub fn finish_pending_tasks(&self) -> impl Future<Output = ()> {
|
||||||
self.0.borrow().finish_pending_tasks()
|
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 {
|
impl UpdateModel for App {
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl Presenter {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// canvas.into_canvas().into_scene()
|
// canvas.into_canvas().into_scene()
|
||||||
todo!()
|
Scene {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn responder_chain(&self, app: &AppContext) -> Option<Vec<usize>> {
|
pub fn responder_chain(&self, app: &AppContext) -> Option<Vec<usize>> {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rust_embed::RustEmbed;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "assets"]
|
#[folder = "assets"]
|
||||||
struct Assets;
|
pub struct Assets;
|
||||||
|
|
||||||
impl AssetSource for Assets {
|
impl AssetSource for Assets {
|
||||||
fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
|
fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
|
||||||
|
|
|
@ -1392,7 +1392,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fold() -> Result<()> {
|
fn test_fold() -> Result<()> {
|
||||||
let mut app = App::new().unwrap();
|
App::test((), |mut app| async move {
|
||||||
let buffer = app.add_model(|_| {
|
let buffer = app.add_model(|_| {
|
||||||
Buffer::new(
|
Buffer::new(
|
||||||
0,
|
0,
|
||||||
|
@ -1415,7 +1415,8 @@ mod tests {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
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.update(&mut app, |view, ctx| {
|
||||||
view.select_ranges(Some(DisplayPoint::new(8, 0)..DisplayPoint::new(12, 0)), ctx)?;
|
view.select_ranges(Some(DisplayPoint::new(8, 0)..DisplayPoint::new(12, 0)), ctx)?;
|
||||||
|
@ -1478,14 +1479,16 @@ mod tests {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_cursor() -> Result<()> {
|
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 buffer = app.add_model(|_| Buffer::new(0, sample_text(6, 6)));
|
||||||
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
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.update(&mut app, |buffer, ctx| {
|
||||||
buffer.edit(
|
buffer.edit(
|
||||||
|
@ -1513,6 +1516,7 @@ mod tests {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BufferView {
|
impl BufferView {
|
||||||
|
|
|
@ -460,7 +460,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_folds() -> Result<()> {
|
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 buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||||
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
||||||
|
|
||||||
|
@ -510,11 +510,12 @@ mod tests {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_overlapping_folds() -> Result<()> {
|
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)));
|
let buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||||
app.read(|app| {
|
app.read(|app| {
|
||||||
let mut map = FoldMap::new(buffer.clone(), app);
|
let mut map = FoldMap::new(buffer.clone(), app);
|
||||||
|
@ -530,11 +531,12 @@ mod tests {
|
||||||
assert_eq!(map.text(app), "aa…eeeee");
|
assert_eq!(map.text(app), "aa…eeeee");
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_merging_folds_via_edit() -> Result<()> {
|
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 buffer = app.add_model(|_| Buffer::new(0, sample_text(5, 6)));
|
||||||
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
let mut map = app.read(|app| FoldMap::new(buffer.clone(), app));
|
||||||
|
|
||||||
|
@ -561,6 +563,7 @@ mod tests {
|
||||||
assert_eq!(map.text(app), "aa…eeeee");
|
assert_eq!(map.text(app), "aa…eeeee");
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -573,7 +576,7 @@ mod tests {
|
||||||
println!("{:?}", seed);
|
println!("{:?}", seed);
|
||||||
let mut rng = StdRng::seed_from_u64(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 buffer = app.add_model(|_| {
|
||||||
let len = rng.gen_range(0..10);
|
let len = rng.gen_range(0..10);
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||||
|
@ -629,6 +632,9 @@ mod tests {
|
||||||
|
|
||||||
Ok::<(), anyhow::Error>(())
|
Ok::<(), anyhow::Error>(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
Ok::<(), anyhow::Error>(())
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -636,7 +642,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_buffer_rows() -> Result<()> {
|
fn test_buffer_rows() -> Result<()> {
|
||||||
let mut app = App::new()?;
|
App::test((), |mut app| async move {
|
||||||
let text = sample_text(6, 6) + "\n";
|
let text = sample_text(6, 6) + "\n";
|
||||||
let buffer = app.add_model(|_| Buffer::new(0, text));
|
let buffer = app.add_model(|_| Buffer::new(0, text));
|
||||||
|
|
||||||
|
@ -657,6 +663,7 @@ mod tests {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FoldMap {
|
impl FoldMap {
|
||||||
|
|
|
@ -296,7 +296,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chars_at() -> Result<()> {
|
fn test_chars_at() -> Result<()> {
|
||||||
let mut app = App::new()?;
|
App::test((), |mut app| async move {
|
||||||
let text = sample_text(6, 6);
|
let text = sample_text(6, 6);
|
||||||
let buffer = app.add_model(|_| Buffer::new(0, text));
|
let buffer = app.add_model(|_| Buffer::new(0, text));
|
||||||
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
||||||
|
@ -336,6 +336,7 @@ mod tests {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -363,12 +364,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_max_point() -> Result<()> {
|
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 buffer = app.add_model(|_| Buffer::new(0, "aaa\n\t\tbbb"));
|
||||||
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
let map = app.add_model(|ctx| DisplayMap::new(buffer.clone(), 4, ctx));
|
||||||
map.read(&app, |map, app| {
|
map.read(&app, |map, app| {
|
||||||
assert_eq!(map.max_point(app), DisplayPoint::new(1, 11))
|
assert_eq!(map.max_point(app), DisplayPoint::new(1, 11))
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +1,31 @@
|
||||||
use fs::OpenOptions;
|
use fs::OpenOptions;
|
||||||
use gpui::{
|
use gpui::platform::{current as platform, Runner as _};
|
||||||
executor,
|
|
||||||
geometry::{rect::RectF, vector::vec2f},
|
|
||||||
platform::{current as platform, App as _, Runner as _, WindowOptions},
|
|
||||||
FontCache,
|
|
||||||
};
|
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
use std::{fs, mem, rc::Rc, sync::Arc};
|
use std::{fs, mem, path::PathBuf};
|
||||||
use zed::{
|
use zed::{
|
||||||
editor, settings,
|
assets, editor, settings,
|
||||||
workspace::{self, OpenParams},
|
workspace::{self, OpenParams},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
let platform = Arc::new(platform::app());
|
let app = gpui::App::new(assets::Assets).unwrap();
|
||||||
|
let (_, settings_rx) = settings::channel(&app.fonts()).unwrap();
|
||||||
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 mut app = app.clone();
|
||||||
platform::runner()
|
platform::runner()
|
||||||
.on_finish_launching(move || {
|
.on_finish_launching(move || {
|
||||||
log::info!("finish launching");
|
|
||||||
|
|
||||||
workspace::init(&mut app);
|
workspace::init(&mut app);
|
||||||
editor::init(&mut app);
|
editor::init(&mut app);
|
||||||
|
|
||||||
if stdout_is_a_pty() {
|
if stdout_is_a_pty() {
|
||||||
platform.activate(true);
|
app.platform().activate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let paths = std::env::args()
|
let paths = collect_path_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<_>>();
|
|
||||||
|
|
||||||
if !paths.is_empty() {
|
if !paths.is_empty() {
|
||||||
app.dispatch_global_action(
|
app.dispatch_global_action(
|
||||||
"workspace:open_paths",
|
"workspace:open_paths",
|
||||||
|
@ -59,23 +34,11 @@ fn main() {
|
||||||
settings: settings_rx,
|
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();
|
.run();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn init_logger() {
|
fn init_logger() {
|
||||||
let level = LevelFilter::Info;
|
let level = LevelFilter::Info;
|
||||||
|
@ -101,3 +64,16 @@ fn init_logger() {
|
||||||
fn stdout_is_a_pty() -> bool {
|
fn stdout_is_a_pty() -> bool {
|
||||||
unsafe { libc::isatty(libc::STDOUT_FILENO as i32) != 0 }
|
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]
|
#[test]
|
||||||
fn test_open_paths_action() {
|
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;
|
let settings = settings::channel(&FontCache::new()).unwrap().1;
|
||||||
|
|
||||||
init(&mut app);
|
init(&mut app);
|
||||||
|
|
|
@ -228,7 +228,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_open_entry() -> Result<(), Arc<anyhow::Error>> {
|
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!({
|
let dir = temp_tree(json!({
|
||||||
"a": {
|
"a": {
|
||||||
"aa": "aa contents",
|
"aa": "aa contents",
|
||||||
|
|
|
@ -331,7 +331,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_open_entry() -> Result<()> {
|
fn test_open_entry() -> Result<()> {
|
||||||
App::test(|mut app| async move {
|
App::test((), |mut app| async move {
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
"a": {
|
"a": {
|
||||||
"aa": "aa contents",
|
"aa": "aa contents",
|
||||||
|
@ -399,7 +399,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pane_actions() -> Result<()> {
|
fn test_pane_actions() -> Result<()> {
|
||||||
App::test(|mut app| async move {
|
App::test((), |mut app| async move {
|
||||||
pane::init(&mut app);
|
pane::init(&mut app);
|
||||||
|
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue