Not working yet file-finder2 (#3321)

Porting file_finder

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2023-11-14 15:22:59 -08:00 committed by GitHub
commit df64a3c701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 2193 additions and 98 deletions

26
Cargo.lock generated
View file

@ -3061,6 +3061,31 @@ dependencies = [
"workspace",
]
[[package]]
name = "file_finder2"
version = "0.1.0"
dependencies = [
"collections",
"ctor",
"editor2",
"env_logger 0.9.3",
"fuzzy2",
"gpui2",
"language2",
"menu2",
"picker2",
"postage",
"project2",
"serde",
"serde_json",
"settings2",
"text2",
"theme2",
"ui2",
"util",
"workspace2",
]
[[package]]
name = "filetime"
version = "0.2.22"
@ -11424,6 +11449,7 @@ dependencies = [
"editor2",
"env_logger 0.9.3",
"feature_flags2",
"file_finder2",
"fs2",
"fsevent",
"futures 0.3.28",

View file

@ -9383,8 +9383,8 @@ impl Render for Editor {
EditorMode::SingleLine => {
TextStyle {
color: cx.theme().colors().text,
font_family: "Zed Sans".into(), // todo!()
font_features: FontFeatures::default(),
font_family: settings.ui_font.family.clone(), // todo!()
font_features: settings.ui_font.features,
font_size: rems(0.875).into(),
font_weight: FontWeight::NORMAL,
font_style: FontStyle::Normal,

View file

@ -1448,6 +1448,7 @@ impl EditorElement {
let snapshot = editor.snapshot(cx);
let style = self.style.clone();
let font_id = cx.text_system().font_id(&style.text.font()).unwrap();
let font_size = style.text.font_size.to_pixels(cx.rem_size());
let line_height = style.text.line_height_in_pixels(cx.rem_size());

View file

@ -0,0 +1,37 @@
[package]
name = "file_finder2"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/file_finder.rs"
doctest = false
[dependencies]
editor = { package = "editor2", path = "../editor2" }
collections = { path = "../collections" }
fuzzy = { package = "fuzzy2", path = "../fuzzy2" }
gpui = { package = "gpui2", path = "../gpui2" }
menu = { package = "menu2", path = "../menu2" }
picker = { package = "picker2", path = "../picker2" }
project = { package = "project2", path = "../project2" }
settings = { package = "settings2", path = "../settings2" }
text = { package = "text2", path = "../text2" }
util = { path = "../util" }
theme = { package = "theme2", path = "../theme2" }
ui = { package = "ui2", path = "../ui2" }
workspace = { package = "workspace2", path = "../workspace2" }
postage.workspace = true
serde.workspace = true
[dev-dependencies]
editor = { package = "editor2", path = "../editor2", features = ["test-support"] }
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
language = { package = "language2", path = "../language2", features = ["test-support"] }
workspace = { package = "workspace2", path = "../workspace2", features = ["test-support"] }
theme = { package = "theme2", path = "../theme2", features = ["test-support"] }
serde_json.workspace = true
ctor.workspace = true
env_logger.workspace = true

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
use crate::{
div, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext, BackgroundExecutor,
Context, Div, EventEmitter, ForegroundExecutor, InputEvent, KeyDownEvent, Keystroke, Model,
ModelContext, Render, Result, Task, TestDispatcher, TestPlatform, View, ViewContext,
VisualContext, WindowContext, WindowHandle, WindowOptions,
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
BackgroundExecutor, Context, Div, EventEmitter, ForegroundExecutor, InputEvent, KeyDownEvent,
Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher, TestPlatform, View,
ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
};
use anyhow::{anyhow, bail};
use futures::{Stream, StreamExt};
@ -81,6 +81,7 @@ impl TestAppContext {
let platform = TestPlatform::new(background_executor.clone(), foreground_executor.clone());
let asset_source = Arc::new(());
let http_client = util::http::FakeHttpClient::with_404_response();
Self {
app: AppContext::new(platform.clone(), asset_source, http_client),
background_executor,
@ -213,6 +214,15 @@ impl TestAppContext {
}
}
pub fn dispatch_action<A>(&mut self, window: AnyWindowHandle, action: A)
where
A: Action,
{
window
.update(self, |_, cx| cx.dispatch_action(action.boxed_clone()))
.unwrap()
}
pub fn dispatch_keystroke(
&mut self,
window: AnyWindowHandle,
@ -390,6 +400,13 @@ impl<'a> VisualTestContext<'a> {
pub fn from_window(window: AnyWindowHandle, cx: &'a mut TestAppContext) -> Self {
Self { cx, window }
}
pub fn dispatch_action<A>(&mut self, action: A)
where
A: Action,
{
self.cx.dispatch_action(self.window, action)
}
}
impl<'a> Context for VisualTestContext<'a> {

View file

@ -15,7 +15,7 @@ use taffy::style::Overflow;
pub fn uniform_list<Id, V, C>(
id: Id,
item_count: usize,
f: impl 'static + Fn(&mut V, Range<usize>, &mut ViewContext<V>) -> SmallVec<[C; 64]>,
f: impl 'static + Fn(&mut V, Range<usize>, &mut ViewContext<V>) -> Vec<C>,
) -> UniformList<V>
where
Id: Into<ElementId>,

View file

@ -422,8 +422,11 @@ impl<'a> WindowContext<'a> {
}
pub fn dispatch_action(&mut self, action: Box<dyn Action>) {
dbg!("BEFORE FOCUS");
if let Some(focus_handle) = self.focused() {
dbg!("BEFORE DEFER", focus_handle.id);
self.defer(move |cx| {
dbg!("AFTER DEFER");
if let Some(node_id) = cx
.window
.current_frame

View file

@ -58,7 +58,7 @@ impl<D: PickerDelegate> Picker<D> {
self.editor.update(cx, |editor, cx| editor.focus(cx));
}
fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
pub fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
let count = self.delegate.match_count();
if count > 0 {
let index = self.delegate.selected_index();
@ -98,6 +98,15 @@ impl<D: PickerDelegate> Picker<D> {
}
}
pub fn cycle_selection(&mut self, cx: &mut ViewContext<Self>) {
let count = self.delegate.match_count();
let index = self.delegate.selected_index();
let new_index = if index + 1 == count { 0 } else { index + 1 };
self.delegate.set_selected_index(new_index, cx);
self.scroll_handle.scroll_to_item(new_index);
cx.notify();
}
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
self.delegate.dismissed(cx);
}
@ -137,6 +146,11 @@ impl<D: PickerDelegate> Picker<D> {
}
}
pub fn refresh(&mut self, cx: &mut ViewContext<Self>) {
let query = self.editor.read(cx).text(cx);
self.update_matches(query, cx);
}
pub fn update_matches(&mut self, query: String, cx: &mut ViewContext<Self>) {
let update = self.delegate.update_matches(query, cx);
self.matches_updated(cx);

View file

@ -21,7 +21,6 @@ use project::{
};
use project_panel_settings::{ProjectPanelDockPosition, ProjectPanelSettings};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::{
cmp::Ordering,
collections::{hash_map, HashMap},
@ -1458,7 +1457,7 @@ impl Render for ProjectPanel {
.map(|(_, worktree_entries)| worktree_entries.len())
.sum(),
|this: &mut Self, range, cx| {
let mut items = SmallVec::new();
let mut items = Vec::new();
this.for_each_visible_entry(range, cx, |id, details, cx| {
items.push(this.render_entry(id, details, cx));
});

View file

@ -35,6 +35,7 @@ pub(crate) fn one_dark() -> Theme {
id: "one_dark".to_string(),
name: "One Dark".into(),
appearance: Appearance::Dark,
styles: ThemeStyles {
system: SystemColors::default(),
colors: ThemeColors {

View file

@ -19,6 +19,7 @@ const MIN_LINE_HEIGHT: f32 = 1.0;
#[derive(Clone)]
pub struct ThemeSettings {
pub ui_font_size: Pixels,
pub ui_font: Font,
pub buffer_font: Font,
pub buffer_font_size: Pixels,
pub buffer_line_height: BufferLineHeight,
@ -120,6 +121,12 @@ impl settings::Settings for ThemeSettings {
let mut this = Self {
ui_font_size: defaults.ui_font_size.unwrap_or(16.).into(),
ui_font: Font {
family: "Helvetica".into(),
features: Default::default(),
weight: Default::default(),
style: Default::default(),
},
buffer_font: Font {
family: defaults.buffer_font_family.clone().unwrap().into(),
features: defaults.buffer_font_features.clone().unwrap(),

View file

@ -1,5 +1,6 @@
use gpui::{Div, Render};
use theme2::ActiveTheme;
use settings2::Settings;
use theme2::{ActiveTheme, ThemeSettings};
use crate::prelude::*;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor};
@ -34,9 +35,10 @@ impl Render for TextTooltip {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
v_stack()
.elevation_2(cx)
.font("Zed Sans")
.font(ui_font)
.text_ui_sm()
.text_color(cx.theme().colors().text)
.py_1()

View file

@ -206,13 +206,14 @@ impl Render for Workspace {
.child(self.editor_1.clone())],
SplitDirection::Horizontal,
);
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
div()
.relative()
.size_full()
.flex()
.flex_col()
.font("Zed Sans")
.font(ui_font)
.gap_0()
.justify_start()
.items_start()

View file

@ -71,6 +71,14 @@ impl ModalLayer {
cx.notify();
}
pub fn current_modal<V>(&self) -> Option<View<V>>
where
V: 'static,
{
let active_modal = self.active_modal.as_ref()?;
active_modal.modal.clone().downcast::<V>().ok()
}
}
impl Render for ModalLayer {

View file

@ -67,7 +67,7 @@ use std::{
sync::{atomic::AtomicUsize, Arc},
time::Duration,
};
use theme2::ActiveTheme;
use theme2::{ActiveTheme, ThemeSettings};
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
use ui::TextColor;
use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextTooltip};
@ -1774,50 +1774,50 @@ impl Workspace {
})
}
// pub fn open_abs_path(
// &mut self,
// abs_path: PathBuf,
// visible: bool,
// cx: &mut ViewContext<Self>,
// ) -> Task<anyhow::Result<Box<dyn ItemHandle>>> {
// cx.spawn(|workspace, mut cx| async move {
// let open_paths_task_result = workspace
// .update(&mut cx, |workspace, cx| {
// workspace.open_paths(vec![abs_path.clone()], visible, cx)
// })
// .with_context(|| format!("open abs path {abs_path:?} task spawn"))?
// .await;
// anyhow::ensure!(
// open_paths_task_result.len() == 1,
// "open abs path {abs_path:?} task returned incorrect number of results"
// );
// match open_paths_task_result
// .into_iter()
// .next()
// .expect("ensured single task result")
// {
// Some(open_result) => {
// open_result.with_context(|| format!("open abs path {abs_path:?} task join"))
// }
// None => anyhow::bail!("open abs path {abs_path:?} task returned None"),
// }
// })
// }
pub fn open_abs_path(
&mut self,
abs_path: PathBuf,
visible: bool,
cx: &mut ViewContext<Self>,
) -> Task<anyhow::Result<Box<dyn ItemHandle>>> {
cx.spawn(|workspace, mut cx| async move {
let open_paths_task_result = workspace
.update(&mut cx, |workspace, cx| {
workspace.open_paths(vec![abs_path.clone()], visible, cx)
})
.with_context(|| format!("open abs path {abs_path:?} task spawn"))?
.await;
anyhow::ensure!(
open_paths_task_result.len() == 1,
"open abs path {abs_path:?} task returned incorrect number of results"
);
match open_paths_task_result
.into_iter()
.next()
.expect("ensured single task result")
{
Some(open_result) => {
open_result.with_context(|| format!("open abs path {abs_path:?} task join"))
}
None => anyhow::bail!("open abs path {abs_path:?} task returned None"),
}
})
}
// pub fn split_abs_path(
// &mut self,
// abs_path: PathBuf,
// visible: bool,
// cx: &mut ViewContext<Self>,
// ) -> Task<anyhow::Result<Box<dyn ItemHandle>>> {
// let project_path_task =
// Workspace::project_path_for_path(self.project.clone(), &abs_path, visible, cx);
// cx.spawn(|this, mut cx| async move {
// let (_, path) = project_path_task.await?;
// this.update(&mut cx, |this, cx| this.split_path(path, cx))?
// .await
// })
// }
pub fn split_abs_path(
&mut self,
abs_path: PathBuf,
visible: bool,
cx: &mut ViewContext<Self>,
) -> Task<anyhow::Result<Box<dyn ItemHandle>>> {
let project_path_task =
Workspace::project_path_for_path(self.project.clone(), &abs_path, visible, cx);
cx.spawn(|this, mut cx| async move {
let (_, path) = project_path_task.await?;
this.update(&mut cx, |this, cx| this.split_path(path, cx))?
.await
})
}
pub fn open_path(
&mut self,
@ -1844,37 +1844,37 @@ impl Workspace {
})
}
// pub fn split_path(
// &mut self,
// path: impl Into<ProjectPath>,
// cx: &mut ViewContext<Self>,
// ) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
// let pane = self.last_active_center_pane.clone().unwrap_or_else(|| {
// self.panes
// .first()
// .expect("There must be an active pane")
// .downgrade()
// });
pub fn split_path(
&mut self,
path: impl Into<ProjectPath>,
cx: &mut ViewContext<Self>,
) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
let pane = self.last_active_center_pane.clone().unwrap_or_else(|| {
self.panes
.first()
.expect("There must be an active pane")
.downgrade()
});
// if let Member::Pane(center_pane) = &self.center.root {
// if center_pane.read(cx).items_len() == 0 {
// return self.open_path(path, Some(pane), true, cx);
// }
// }
if let Member::Pane(center_pane) = &self.center.root {
if center_pane.read(cx).items_len() == 0 {
return self.open_path(path, Some(pane), true, cx);
}
}
// let task = self.load_path(path.into(), cx);
// cx.spawn(|this, mut cx| async move {
// let (project_entry_id, build_item) = task.await?;
// this.update(&mut cx, move |this, cx| -> Option<_> {
// let pane = pane.upgrade(cx)?;
// let new_pane = this.split_pane(pane, SplitDirection::Right, cx);
// new_pane.update(cx, |new_pane, cx| {
// Some(new_pane.open_item(project_entry_id, true, cx, build_item))
// })
// })
// .map(|option| option.ok_or_else(|| anyhow!("pane was dropped")))?
// })
// }
let task = self.load_path(path.into(), cx);
cx.spawn(|this, mut cx| async move {
let (project_entry_id, build_item) = task.await?;
this.update(&mut cx, move |this, cx| -> Option<_> {
let pane = pane.upgrade()?;
let new_pane = this.split_pane(pane, SplitDirection::Right, cx);
new_pane.update(cx, |new_pane, cx| {
Some(new_pane.open_item(project_entry_id, true, cx, build_item))
})
})
.map(|option| option.ok_or_else(|| anyhow!("pane was dropped")))?
})
}
pub(crate) fn load_path(
&mut self,
@ -3038,10 +3038,10 @@ impl Workspace {
fn force_remove_pane(&mut self, pane: &View<Pane>, cx: &mut ViewContext<Workspace>) {
self.panes.retain(|p| p != pane);
if true {
todo!()
// cx.focus(self.panes.last().unwrap());
}
self.panes
.last()
.unwrap()
.update(cx, |pane, cx| pane.focus(cx));
if self.last_active_center_pane == Some(pane.downgrade()) {
self.last_active_center_pane = None;
}
@ -3410,10 +3410,6 @@ impl Workspace {
// });
}
// todo!()
// #[cfg(any(test, feature = "test-support"))]
// pub fn test_new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
// use node_runtime::FakeNodeRuntime;
#[cfg(any(test, feature = "test-support"))]
pub fn test_new(project: Model<Project>, cx: &mut ViewContext<Self>) -> Self {
use gpui::Context;
@ -3433,7 +3429,9 @@ impl Workspace {
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
node_runtime: FakeNodeRuntime::new(),
});
Self::new(0, project, app_state, cx)
let workspace = Self::new(0, project, app_state, cx);
workspace.active_pane.update(cx, |pane, cx| pane.focus(cx));
workspace
}
// fn render_dock(&self, position: DockPosition, cx: &WindowContext) -> Option<AnyElement<Self>> {
@ -3489,6 +3487,10 @@ impl Workspace {
div
}
pub fn current_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
self.modal_layer.read(cx).current_modal()
}
pub fn toggle_modal<V: Modal, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
where
B: FnOnce(&mut ViewContext<V>) -> V,
@ -3712,6 +3714,7 @@ impl Render for Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let mut context = KeyContext::default();
context.add("Workspace");
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
self.add_workspace_actions_listeners(div())
.context(context)
@ -3719,7 +3722,7 @@ impl Render for Workspace {
.size_full()
.flex()
.flex_col()
.font("Zed Sans")
.font(ui_font)
.gap_0()
.justify_start()
.items_start()

View file

@ -36,7 +36,7 @@ copilot = { package = "copilot2", path = "../copilot2" }
db = { package = "db2", path = "../db2" }
editor = { package="editor2", path = "../editor2" }
# feedback = { path = "../feedback" }
# file_finder = { path = "../file_finder" }
file_finder = { package="file_finder2", path = "../file_finder2" }
# search = { path = "../search" }
fs = { package = "fs2", path = "../fs2" }
fsevent = { path = "../fsevent" }

View file

@ -190,7 +190,7 @@ fn main() {
// recent_projects::init(cx);
go_to_line::init(cx);
// file_finder::init(cx);
file_finder::init(cx);
// outline::init(cx);
// project_symbols::init(cx);
project_panel::init(Assets, cx);