Merge branch 'main' into collab-ui-refinement

This commit is contained in:
Nate Butler 2023-12-01 10:50:25 -05:00
commit 88188b0c30
96 changed files with 4097 additions and 3868 deletions

2
Cargo.lock generated
View file

@ -9970,7 +9970,7 @@ dependencies = [
[[package]] [[package]]
name = "tree-sitter" name = "tree-sitter"
version = "0.20.10" version = "0.20.10"
source = "git+https://github.com/tree-sitter/tree-sitter?rev=3b0159d25559b603af566ade3c83d930bf466db1#3b0159d25559b603af566ade3c83d930bf466db1" source = "git+https://github.com/tree-sitter/tree-sitter?rev=b5f461a69bf3df7298b1903574d506179e6390b0#b5f461a69bf3df7298b1903574d506179e6390b0"
dependencies = [ dependencies = [
"cc", "cc",
"regex", "regex",

View file

@ -201,7 +201,7 @@ tree-sitter-vue = {git = "https://github.com/zed-industries/tree-sitter-vue", re
tree-sitter-uiua = {git = "https://github.com/shnarazk/tree-sitter-uiua", rev = "9260f11be5900beda4ee6d1a24ab8ddfaf5a19b2"} tree-sitter-uiua = {git = "https://github.com/shnarazk/tree-sitter-uiua", rev = "9260f11be5900beda4ee6d1a24ab8ddfaf5a19b2"}
[patch.crates-io] [patch.crates-io]
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "3b0159d25559b603af566ade3c83d930bf466db1" } tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "b5f461a69bf3df7298b1903574d506179e6390b0" }
async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" } async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" }
# TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457 # TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457

View file

@ -530,12 +530,17 @@
"alt-cmd-shift-c": "project_panel::CopyRelativePath", "alt-cmd-shift-c": "project_panel::CopyRelativePath",
"f2": "project_panel::Rename", "f2": "project_panel::Rename",
"enter": "project_panel::Rename", "enter": "project_panel::Rename",
"space": "project_panel::Open",
"backspace": "project_panel::Delete", "backspace": "project_panel::Delete",
"alt-cmd-r": "project_panel::RevealInFinder", "alt-cmd-r": "project_panel::RevealInFinder",
"alt-shift-f": "project_panel::NewSearchInDirectory" "alt-shift-f": "project_panel::NewSearchInDirectory"
} }
}, },
{
"context": "ProjectPanel && not_editing",
"bindings": {
"space": "project_panel::Open"
}
},
{ {
"context": "CollabPanel && not_editing", "context": "CollabPanel && not_editing",
"bindings": { "bindings": {

View file

@ -1218,6 +1218,31 @@ impl View for AssistantPanel {
let style = &theme.assistant; let style = &theme.assistant;
if let Some(api_key_editor) = self.api_key_editor.as_ref() { if let Some(api_key_editor) = self.api_key_editor.as_ref() {
Flex::column() Flex::column()
.with_child(
Text::new(
"To use the assistant panel or inline assistant, you need to add your OpenAI api key.",
style.api_key_prompt.text.clone(),
),
)
.with_child(
Text::new(
" - Having a subscription for another service like GitHub Copilot won't work.",
style.api_key_prompt.text.clone(),
),
)
.with_child(
Text::new(
" - You can create a api key at: platform.openai.com/api-keys",
style.api_key_prompt.text.clone(),
),
)
.with_child(
Text::new(
" ",
style.api_key_prompt.text.clone(),
)
.aligned(),
)
.with_child( .with_child(
Text::new( Text::new(
"Paste your OpenAI API key and press Enter to use the assistant", "Paste your OpenAI API key and press Enter to use the assistant",
@ -1231,6 +1256,20 @@ impl View for AssistantPanel {
.with_style(style.api_key_editor.container) .with_style(style.api_key_editor.container)
.aligned(), .aligned(),
) )
.with_child(
Text::new(
" ",
style.api_key_prompt.text.clone(),
)
.aligned(),
)
.with_child(
Text::new(
"Click on the Z button in the status bar to close this panel.",
style.api_key_prompt.text.clone(),
)
.aligned(),
)
.contained() .contained()
.with_style(style.api_key_prompt.container) .with_style(style.api_key_prompt.container)
.aligned() .aligned()

View file

@ -15,7 +15,7 @@ use collections::HashSet;
use futures::{channel::oneshot, future::Shared, Future, FutureExt}; use futures::{channel::oneshot, future::Shared, Future, FutureExt};
use gpui::{ use gpui::{
AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, PromptLevel, AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, PromptLevel,
Subscription, Task, View, ViewContext, VisualContext, WeakModel, WeakView, WindowHandle, Subscription, Task, View, ViewContext, VisualContext, WeakModel, WindowHandle,
}; };
pub use participant::ParticipantLocation; pub use participant::ParticipantLocation;
use postage::watch; use postage::watch;
@ -557,24 +557,17 @@ pub fn report_call_event_for_channel(
pub struct Call { pub struct Call {
active_call: Option<(Model<ActiveCall>, Vec<Subscription>)>, active_call: Option<(Model<ActiveCall>, Vec<Subscription>)>,
parent_workspace: WeakView<Workspace>,
} }
impl Call { impl Call {
pub fn new( pub fn new(cx: &mut ViewContext<'_, Workspace>) -> Box<dyn CallHandler> {
parent_workspace: WeakView<Workspace>,
cx: &mut ViewContext<'_, Workspace>,
) -> Box<dyn CallHandler> {
let mut active_call = None; let mut active_call = None;
if cx.has_global::<Model<ActiveCall>>() { if cx.has_global::<Model<ActiveCall>>() {
let call = cx.global::<Model<ActiveCall>>().clone(); let call = cx.global::<Model<ActiveCall>>().clone();
let subscriptions = vec![cx.subscribe(&call, Self::on_active_call_event)]; let subscriptions = vec![cx.subscribe(&call, Self::on_active_call_event)];
active_call = Some((call, subscriptions)); active_call = Some((call, subscriptions));
} }
Box::new(Self { Box::new(Self { active_call })
active_call,
parent_workspace,
})
} }
fn on_active_call_event( fn on_active_call_event(
workspace: &mut Workspace, workspace: &mut Workspace,
@ -597,6 +590,7 @@ impl CallHandler for Call {
fn peer_state( fn peer_state(
&mut self, &mut self,
leader_id: PeerId, leader_id: PeerId,
project: &Model<Project>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Option<(bool, bool)> { ) -> Option<(bool, bool)> {
let (call, _) = self.active_call.as_ref()?; let (call, _) = self.active_call.as_ref()?;
@ -608,12 +602,7 @@ impl CallHandler for Call {
match participant.location { match participant.location {
ParticipantLocation::SharedProject { project_id } => { ParticipantLocation::SharedProject { project_id } => {
leader_in_this_app = true; leader_in_this_app = true;
leader_in_this_project = Some(project_id) leader_in_this_project = Some(project_id) == project.read(cx).remote_id();
== self
.parent_workspace
.update(cx, |this, cx| this.project().read(cx).remote_id())
.log_err()
.flatten();
} }
ParticipantLocation::UnsharedProject => { ParticipantLocation::UnsharedProject => {
leader_in_this_app = true; leader_in_this_app = true;

View file

@ -3,10 +3,12 @@ use anyhow::Result;
use client::{proto::PeerId, User}; use client::{proto::PeerId, User};
use futures::StreamExt; use futures::StreamExt;
use gpui::{ use gpui::{
div, AppContext, Div, Element, EventEmitter, FocusHandle, FocusableView, ParentElement, Render, div, img, AppContext, Div, Element, EventEmitter, FocusHandle, Focusable, FocusableView,
SharedString, Task, View, ViewContext, VisualContext, WindowContext, InteractiveElement, ParentElement, Render, SharedString, Styled, Task, View, ViewContext,
VisualContext, WindowContext,
}; };
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use ui::{h_stack, Icon, IconElement};
use workspace::{item::Item, ItemNavHistory, WorkspaceId}; use workspace::{item::Item, ItemNavHistory, WorkspaceId};
pub enum Event { pub enum Event {
@ -16,8 +18,6 @@ pub enum Event {
pub struct SharedScreen { pub struct SharedScreen {
track: Weak<RemoteVideoTrack>, track: Weak<RemoteVideoTrack>,
frame: Option<Frame>, frame: Option<Frame>,
// temporary addition just to render something interactive.
current_frame_id: usize,
pub peer_id: PeerId, pub peer_id: PeerId,
user: Arc<User>, user: Arc<User>,
nav_history: Option<ItemNavHistory>, nav_history: Option<ItemNavHistory>,
@ -51,7 +51,6 @@ impl SharedScreen {
Ok(()) Ok(())
}), }),
focus: cx.focus_handle(), focus: cx.focus_handle(),
current_frame_id: 0,
} }
} }
} }
@ -65,50 +64,16 @@ impl FocusableView for SharedScreen {
} }
} }
impl Render for SharedScreen { impl Render for SharedScreen {
type Element = Div; type Element = Focusable<Div>;
fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element {
let frame = self.frame.clone(); div().track_focus(&self.focus).size_full().children(
let frame_id = self.current_frame_id; self.frame
self.current_frame_id = self.current_frame_id.wrapping_add(1); .as_ref()
div().children(frame.map(|_| { .map(|frame| img(frame.image()).size_full()),
ui::Label::new(frame_id.to_string()).color(ui::Color::Error) )
// img().data(Arc::new(ImageData::new(image::ImageBuffer::new(
// frame.width() as u32,
// frame.height() as u32,
// ))))
}))
} }
} }
// impl View for SharedScreen {
// fn ui_name() -> &'static str {
// "SharedScreen"
// }
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// enum Focus {}
// let frame = self.frame.clone();
// MouseEventHandler::new::<Focus, _>(0, cx, |_, cx| {
// Canvas::new(move |bounds, _, _, cx| {
// if let Some(frame) = frame.clone() {
// let size = constrain_size_preserving_aspect_ratio(
// bounds.size(),
// vec2f(frame.width() as f32, frame.height() as f32),
// );
// let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.;
// cx.scene().push_surface(gpui::platform::mac::Surface {
// bounds: RectF::new(origin, size),
// image_buffer: frame.image(),
// });
// }
// })
// .contained()
// .with_style(theme::current(cx).shared_screen)
// })
// .on_down(MouseButton::Left, |_, _, cx| cx.focus_parent())
// .into_any()
// }
// }
impl Item for SharedScreen { impl Item for SharedScreen {
fn tab_tooltip_text(&self, _: &AppContext) -> Option<SharedString> { fn tab_tooltip_text(&self, _: &AppContext) -> Option<SharedString> {
@ -121,25 +86,14 @@ impl Item for SharedScreen {
} }
fn tab_content(&self, _: Option<usize>, _: &WindowContext<'_>) -> gpui::AnyElement { fn tab_content(&self, _: Option<usize>, _: &WindowContext<'_>) -> gpui::AnyElement {
div().child("Shared screen").into_any() h_stack()
// Flex::row() .gap_1()
// .with_child( .child(IconElement::new(Icon::Screen))
// Svg::new("icons/desktop.svg") .child(SharedString::from(format!(
// .with_color(style.label.text.color) "{}'s screen",
// .constrained() self.user.github_login
// .with_width(style.type_icon_width) )))
// .aligned() .into_any()
// .contained()
// .with_margin_right(style.spacing),
// )
// .with_child(
// Label::new(
// format!("{}'s screen", self.user.github_login),
// style.label.clone(),
// )
// .aligned(),
// )
// .into_any()
} }
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) { fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {

View file

@ -3941,7 +3941,7 @@ async fn test_collaborating_with_diagnostics(
// Ensure client B observes the new diagnostics. // Ensure client B observes the new diagnostics.
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
&[( &[(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -3961,14 +3961,14 @@ async fn test_collaborating_with_diagnostics(
let project_c = client_c.build_remote_project(project_id, cx_c).await; let project_c = client_c.build_remote_project(project_id, cx_c).await;
let project_c_diagnostic_summaries = let project_c_diagnostic_summaries =
Rc::new(RefCell::new(project_c.read_with(cx_c, |project, cx| { Rc::new(RefCell::new(project_c.read_with(cx_c, |project, cx| {
project.diagnostic_summaries(cx).collect::<Vec<_>>() project.diagnostic_summaries(false, cx).collect::<Vec<_>>()
}))); })));
project_c.update(cx_c, |_, cx| { project_c.update(cx_c, |_, cx| {
let summaries = project_c_diagnostic_summaries.clone(); let summaries = project_c_diagnostic_summaries.clone();
cx.subscribe(&project_c, { cx.subscribe(&project_c, {
move |p, _, event, cx| { move |p, _, event, cx| {
if let project::Event::DiskBasedDiagnosticsFinished { .. } = event { if let project::Event::DiskBasedDiagnosticsFinished { .. } = event {
*summaries.borrow_mut() = p.diagnostic_summaries(cx).collect(); *summaries.borrow_mut() = p.diagnostic_summaries(false, cx).collect();
} }
} }
}) })
@ -4018,7 +4018,7 @@ async fn test_collaborating_with_diagnostics(
deterministic.run_until_parked(); deterministic.run_until_parked();
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[( [(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -4034,7 +4034,7 @@ async fn test_collaborating_with_diagnostics(
}); });
project_c.read_with(cx_c, |project, cx| { project_c.read_with(cx_c, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[( [(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -4097,13 +4097,22 @@ async fn test_collaborating_with_diagnostics(
); );
deterministic.run_until_parked(); deterministic.run_until_parked();
project_a.read_with(cx_a, |project, cx| { project_a.read_with(cx_a, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
project_c.read_with(cx_c, |project, cx| { project_c.read_with(cx_c, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
} }

View file

@ -3688,7 +3688,7 @@ async fn test_collaborating_with_diagnostics(
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
&[( &[(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -3708,14 +3708,14 @@ async fn test_collaborating_with_diagnostics(
let project_c = client_c.build_remote_project(project_id, cx_c).await; let project_c = client_c.build_remote_project(project_id, cx_c).await;
let project_c_diagnostic_summaries = let project_c_diagnostic_summaries =
Rc::new(RefCell::new(project_c.read_with(cx_c, |project, cx| { Rc::new(RefCell::new(project_c.read_with(cx_c, |project, cx| {
project.diagnostic_summaries(cx).collect::<Vec<_>>() project.diagnostic_summaries(false, cx).collect::<Vec<_>>()
}))); })));
project_c.update(cx_c, |_, cx| { project_c.update(cx_c, |_, cx| {
let summaries = project_c_diagnostic_summaries.clone(); let summaries = project_c_diagnostic_summaries.clone();
cx.subscribe(&project_c, { cx.subscribe(&project_c, {
move |p, _, event, cx| { move |p, _, event, cx| {
if let project::Event::DiskBasedDiagnosticsFinished { .. } = event { if let project::Event::DiskBasedDiagnosticsFinished { .. } = event {
*summaries.borrow_mut() = p.diagnostic_summaries(cx).collect(); *summaries.borrow_mut() = p.diagnostic_summaries(false, cx).collect();
} }
} }
}) })
@ -3766,7 +3766,7 @@ async fn test_collaborating_with_diagnostics(
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[( [(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -3783,7 +3783,7 @@ async fn test_collaborating_with_diagnostics(
project_c.read_with(cx_c, |project, cx| { project_c.read_with(cx_c, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summaries(cx).collect::<Vec<_>>(), project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[( [(
ProjectPath { ProjectPath {
worktree_id, worktree_id,
@ -3844,15 +3844,24 @@ async fn test_collaborating_with_diagnostics(
executor.run_until_parked(); executor.run_until_parked();
project_a.read_with(cx_a, |project, cx| { project_a.read_with(cx_a, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
project_b.read_with(cx_b, |project, cx| { project_b.read_with(cx_b, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
project_c.read_with(cx_c, |project, cx| { project_c.read_with(cx_c, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).collect::<Vec<_>>(), []) assert_eq!(
project.diagnostic_summaries(false, cx).collect::<Vec<_>>(),
[]
)
}); });
} }

View file

@ -221,7 +221,7 @@ impl TestServer {
fs: fs.clone(), fs: fs.clone(),
build_window_options: |_, _, _| Default::default(), build_window_options: |_, _, _| Default::default(),
node_runtime: FakeNodeRuntime::new(), node_runtime: FakeNodeRuntime::new(),
call_factory: |_, _| Box::new(workspace::TestCallHandler), call_factory: |_| Box::new(workspace::TestCallHandler),
}); });
cx.update(|cx| { cx.update(|cx| {

View file

@ -17,7 +17,7 @@ mod contact_finder;
// Client, Contact, User, UserStore, // Client, Contact, User, UserStore,
// }; // };
use contact_finder::ContactFinder; use contact_finder::ContactFinder;
use menu::Confirm; use menu::{Cancel, Confirm, SelectNext, SelectPrev};
use rpc::proto; use rpc::proto;
use theme::{ActiveTheme, ThemeSettings}; use theme::{ActiveTheme, ThemeSettings};
// use context_menu::{ContextMenu, ContextMenuItem}; // use context_menu::{ContextMenu, ContextMenuItem};
@ -170,10 +170,10 @@ use feature_flags::{ChannelsAlpha, FeatureFlagAppExt, FeatureFlagViewExt};
use fuzzy::{match_strings, StringMatchCandidate}; use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
actions, div, img, overlay, prelude::*, px, rems, serde_json, Action, AppContext, actions, div, img, overlay, prelude::*, px, rems, serde_json, Action, AppContext,
AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, Focusable, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle,
FocusableView, InteractiveElement, IntoElement, Model, MouseDownEvent, ParentElement, Pixels, Focusable, FocusableView, InteractiveElement, IntoElement, Model, MouseDownEvent,
Point, PromptLevel, Render, RenderOnce, SharedString, Stateful, Styled, Subscription, Task, ParentElement, Pixels, Point, PromptLevel, Render, RenderOnce, ScrollHandle, SharedString,
View, ViewContext, VisualContext, WeakView, Stateful, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
}; };
use project::{Fs, Project}; use project::{Fs, Project};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@ -302,7 +302,7 @@ pub struct CollabPanel {
client: Arc<Client>, client: Arc<Client>,
project: Model<Project>, project: Model<Project>,
match_candidates: Vec<StringMatchCandidate>, match_candidates: Vec<StringMatchCandidate>,
// list_state: ListState<Self>, scroll_handle: ScrollHandle,
subscriptions: Vec<Subscription>, subscriptions: Vec<Subscription>,
collapsed_sections: Vec<Section>, collapsed_sections: Vec<Section>,
collapsed_channels: Vec<ChannelId>, collapsed_channels: Vec<ChannelId>,
@ -384,10 +384,6 @@ enum ListEntry {
ContactPlaceholder, ContactPlaceholder,
} }
// impl Entity for CollabPanel {
// type Event = Event;
// }
impl CollabPanel { impl CollabPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
cx.build_view(|cx| { cx.build_view(|cx| {
@ -399,28 +395,28 @@ impl CollabPanel {
editor editor
}); });
// cx.subscribe(&filter_editor, |this, _, event, cx| { cx.subscribe(&filter_editor, |this: &mut Self, _, event, cx| {
// if let editor::Event::BufferEdited = event { if let editor::EditorEvent::BufferEdited = event {
// let query = this.filter_editor.read(cx).text(cx); let query = this.filter_editor.read(cx).text(cx);
// if !query.is_empty() { if !query.is_empty() {
// this.selection.take(); this.selection.take();
// } }
// this.update_entries(true, cx); this.update_entries(true, cx);
// if !query.is_empty() { if !query.is_empty() {
// this.selection = this this.selection = this
// .entries .entries
// .iter() .iter()
// .position(|entry| !matches!(entry, ListEntry::Header(_))); .position(|entry| !matches!(entry, ListEntry::Header(_)));
// } }
// } else if let editor::Event::Blurred = event { } else if let editor::EditorEvent::Blurred = event {
// let query = this.filter_editor.read(cx).text(cx); let query = this.filter_editor.read(cx).text(cx);
// if query.is_empty() { if query.is_empty() {
// this.selection.take(); this.selection.take();
// this.update_entries(true, cx); this.update_entries(true, cx);
// } }
// } }
// }) })
// .detach(); .detach();
let channel_name_editor = cx.build_view(|cx| Editor::single_line(cx)); let channel_name_editor = cx.build_view(|cx| Editor::single_line(cx));
@ -586,13 +582,13 @@ impl CollabPanel {
project: workspace.project().clone(), project: workspace.project().clone(),
subscriptions: Vec::default(), subscriptions: Vec::default(),
match_candidates: Vec::default(), match_candidates: Vec::default(),
scroll_handle: ScrollHandle::new(),
collapsed_sections: vec![Section::Offline], collapsed_sections: vec![Section::Offline],
collapsed_channels: Vec::default(), collapsed_channels: Vec::default(),
workspace: workspace.weak_handle(), workspace: workspace.weak_handle(),
client: workspace.app_state().client.clone(), client: workspace.app_state().client.clone(),
// context_menu_on_selected: true, // context_menu_on_selected: true,
drag_target_channel: ChannelDragTarget::None, drag_target_channel: ChannelDragTarget::None,
// list_state,
}; };
this.update_entries(false, cx); this.update_entries(false, cx);
@ -708,9 +704,9 @@ impl CollabPanel {
let query = self.filter_editor.read(cx).text(cx); let query = self.filter_editor.read(cx).text(cx);
let executor = cx.background_executor().clone(); let executor = cx.background_executor().clone();
// let prev_selected_entry = self.selection.and_then(|ix| self.entries.get(ix).cloned()); let prev_selected_entry = self.selection.and_then(|ix| self.entries.get(ix).cloned());
let _old_entries = mem::take(&mut self.entries); let old_entries = mem::take(&mut self.entries);
// let mut scroll_to_top = false; let scroll_to_top = false;
// if let Some(room) = ActiveCall::global(cx).read(cx).room() { // if let Some(room) = ActiveCall::global(cx).read(cx).room() {
// self.entries.push(ListEntry::Header(Section::ActiveCall)); // self.entries.push(ListEntry::Header(Section::ActiveCall));
@ -1077,71 +1073,62 @@ impl CollabPanel {
self.entries.push(ListEntry::ContactPlaceholder); self.entries.push(ListEntry::ContactPlaceholder);
} }
// if select_same_item { if select_same_item {
// if let Some(prev_selected_entry) = prev_selected_entry { if let Some(prev_selected_entry) = prev_selected_entry {
// self.selection.take(); self.selection.take();
// for (ix, entry) in self.entries.iter().enumerate() { for (ix, entry) in self.entries.iter().enumerate() {
// if *entry == prev_selected_entry { if *entry == prev_selected_entry {
// self.selection = Some(ix); self.selection = Some(ix);
// break; self.scroll_handle.scroll_to_item(ix);
// } break;
// } }
// } }
// } else { }
// self.selection = self.selection.and_then(|prev_selection| { } else {
// if self.entries.is_empty() { self.selection = self.selection.and_then(|prev_selection| {
// None if self.entries.is_empty() {
// } else { None
// Some(prev_selection.min(self.entries.len() - 1)) } else {
// } let ix = prev_selection.min(self.entries.len() - 1);
// }); self.scroll_handle.scroll_to_item(ix);
// } Some(ix)
}
});
}
// let old_scroll_top = self.list_state.logical_scroll_top(); if scroll_to_top {
self.scroll_handle.scroll_to_item(0)
} else {
let (old_index, old_offset) = self.scroll_handle.logical_scroll_top();
// Attempt to maintain the same scroll position.
if let Some(old_top_entry) = old_entries.get(old_index) {
let (new_index, new_offset) = self
.entries
.iter()
.position(|entry| entry == old_top_entry)
.map(|item_ix| (item_ix, old_offset))
.or_else(|| {
let entry_after_old_top = old_entries.get(old_index + 1)?;
let item_ix = self
.entries
.iter()
.position(|entry| entry == entry_after_old_top)?;
Some((item_ix, px(0.)))
})
.or_else(|| {
let entry_before_old_top = old_entries.get(old_index.saturating_sub(1))?;
let item_ix = self
.entries
.iter()
.position(|entry| entry == entry_before_old_top)?;
Some((item_ix, px(0.)))
})
.unwrap_or_else(|| (old_index, old_offset));
// self.list_state.reset(self.entries.len()); self.scroll_handle
.set_logical_scroll_top(new_index, new_offset);
// if scroll_to_top { }
// self.list_state.scroll_to(ListOffset::default()); }
// } else {
// // Attempt to maintain the same scroll position.
// if let Some(old_top_entry) = old_entries.get(old_scroll_top.item_ix) {
// let new_scroll_top = self
// .entries
// .iter()
// .position(|entry| entry == old_top_entry)
// .map(|item_ix| ListOffset {
// item_ix,
// offset_in_item: old_scroll_top.offset_in_item,
// })
// .or_else(|| {
// let entry_after_old_top = old_entries.get(old_scroll_top.item_ix + 1)?;
// let item_ix = self
// .entries
// .iter()
// .position(|entry| entry == entry_after_old_top)?;
// Some(ListOffset {
// item_ix,
// offset_in_item: 0.,
// })
// })
// .or_else(|| {
// let entry_before_old_top =
// old_entries.get(old_scroll_top.item_ix.saturating_sub(1))?;
// let item_ix = self
// .entries
// .iter()
// .position(|entry| entry == entry_before_old_top)?;
// Some(ListOffset {
// item_ix,
// offset_in_item: 0.,
// })
// });
// self.list_state
// .scroll_to(new_scroll_top.unwrap_or(old_scroll_top));
// }
// }
cx.notify(); cx.notify();
} }
@ -1685,8 +1672,6 @@ impl CollabPanel {
ix: usize, ix: usize,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
// self.context_menu_on_selected = position.is_none();
let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| { let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| {
self.channel_store self.channel_store
.read(cx) .read(cx)
@ -1777,7 +1762,13 @@ impl CollabPanel {
}); });
cx.focus_view(&context_menu); cx.focus_view(&context_menu);
let subscription = cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| { let subscription =
cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
if this.context_menu.as_ref().is_some_and(|context_menu| {
context_menu.0.focus_handle(cx).contains_focused(cx)
}) {
cx.focus_self();
}
this.context_menu.take(); this.context_menu.take();
cx.notify(); cx.notify();
}); });
@ -1786,76 +1777,68 @@ impl CollabPanel {
cx.notify(); cx.notify();
} }
// fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
// if self.take_editing_state(cx) { if self.take_editing_state(cx) {
// cx.focus(&self.filter_editor); cx.focus_view(&self.filter_editor);
// } else { } else {
// self.filter_editor.update(cx, |editor, cx| { self.filter_editor.update(cx, |editor, cx| {
// if editor.buffer().read(cx).len(cx) > 0 { if editor.buffer().read(cx).len(cx) > 0 {
// editor.set_text("", cx); editor.set_text("", cx);
// } }
// }); });
// } }
// self.update_entries(false, cx); self.update_entries(false, cx);
// } }
// fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) { fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
// let ix = self.selection.map_or(0, |ix| ix + 1); let ix = self.selection.map_or(0, |ix| ix + 1);
// if ix < self.entries.len() { if ix < self.entries.len() {
// self.selection = Some(ix); self.selection = Some(ix);
// } }
// self.list_state.reset(self.entries.len()); if let Some(ix) = self.selection {
// if let Some(ix) = self.selection { self.scroll_handle.scroll_to_item(ix)
// self.list_state.scroll_to(ListOffset { }
// item_ix: ix, cx.notify();
// offset_in_item: 0., }
// });
// }
// cx.notify();
// }
// fn select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) { fn select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
// let ix = self.selection.take().unwrap_or(0); let ix = self.selection.take().unwrap_or(0);
// if ix > 0 { if ix > 0 {
// self.selection = Some(ix - 1); self.selection = Some(ix - 1);
// } }
// self.list_state.reset(self.entries.len()); if let Some(ix) = self.selection {
// if let Some(ix) = self.selection { self.scroll_handle.scroll_to_item(ix)
// self.list_state.scroll_to(ListOffset { }
// item_ix: ix, cx.notify();
// offset_in_item: 0., }
// });
// }
// cx.notify();
// }
fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) { fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
if self.confirm_channel_edit(cx) { if self.confirm_channel_edit(cx) {
return; return;
} }
// if let Some(selection) = self.selection { if let Some(selection) = self.selection {
// if let Some(entry) = self.entries.get(selection) { if let Some(entry) = self.entries.get(selection) {
// match entry { match entry {
// ListEntry::Header(section) => match section { ListEntry::Header(section) => match section {
// Section::ActiveCall => Self::leave_call(cx), Section::ActiveCall => Self::leave_call(cx),
// Section::Channels => self.new_root_channel(cx), Section::Channels => self.new_root_channel(cx),
// Section::Contacts => self.toggle_contact_finder(cx), Section::Contacts => self.toggle_contact_finder(cx),
// Section::ContactRequests Section::ContactRequests
// | Section::Online | Section::Online
// | Section::Offline | Section::Offline
// | Section::ChannelInvites => { | Section::ChannelInvites => {
// self.toggle_section_expanded(*section, cx); self.toggle_section_expanded(*section, cx);
// } }
// }, },
// ListEntry::Contact { contact, calling } => { ListEntry::Contact { contact, calling } => {
// if contact.online && !contact.busy && !calling { if contact.online && !contact.busy && !calling {
// self.call(contact.user.id, Some(self.project.clone()), cx); self.call(contact.user.id, cx);
// } }
// } }
// ListEntry::ParticipantProject { // ListEntry::ParticipantProject {
// project_id, // project_id,
// host_user_id, // host_user_id,
@ -1882,33 +1865,28 @@ impl CollabPanel {
// }); // });
// } // }
// } // }
// ListEntry::Channel { channel, .. } => { ListEntry::Channel { channel, .. } => {
// let is_active = maybe!({ let is_active = maybe!({
// let call_channel = ActiveCall::global(cx) let call_channel = ActiveCall::global(cx)
// .read(cx) .read(cx)
// .room()? .room()?
// .read(cx) .read(cx)
// .channel_id()?; .channel_id()?;
// Some(call_channel == channel.id) Some(call_channel == channel.id)
// }) })
// .unwrap_or(false); .unwrap_or(false);
// if is_active { if is_active {
// self.open_channel_notes( self.open_channel_notes(channel.id, cx)
// &OpenChannelNotes { } else {
// channel_id: channel.id, self.join_channel(channel.id, cx)
// }, }
// cx, }
// ) ListEntry::ContactPlaceholder => self.toggle_contact_finder(cx),
// } else { _ => {}
// self.join_channel(channel.id, cx) }
// } }
// } }
// ListEntry::ContactPlaceholder => self.toggle_contact_finder(cx),
// _ => {}
// }
// }
// }
} }
fn insert_space(&mut self, _: &InsertSpace, cx: &mut ViewContext<Self>) { fn insert_space(&mut self, _: &InsertSpace, cx: &mut ViewContext<Self>) {
@ -1975,33 +1953,33 @@ impl CollabPanel {
self.update_entries(false, cx); self.update_entries(false, cx);
} }
// fn collapse_selected_channel( fn collapse_selected_channel(
// &mut self, &mut self,
// _: &CollapseSelectedChannel, _: &CollapseSelectedChannel,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) { ) {
// let Some(channel_id) = self.selected_channel().map(|channel| channel.id) else { let Some(channel_id) = self.selected_channel().map(|channel| channel.id) else {
// return; return;
// }; };
// if self.is_channel_collapsed(channel_id) { if self.is_channel_collapsed(channel_id) {
// return; return;
// } }
// self.toggle_channel_collapsed(channel_id, cx); self.toggle_channel_collapsed(channel_id, cx);
// } }
// fn expand_selected_channel(&mut self, _: &ExpandSelectedChannel, cx: &mut ViewContext<Self>) { fn expand_selected_channel(&mut self, _: &ExpandSelectedChannel, cx: &mut ViewContext<Self>) {
// let Some(id) = self.selected_channel().map(|channel| channel.id) else { let Some(id) = self.selected_channel().map(|channel| channel.id) else {
// return; return;
// }; };
// if !self.is_channel_collapsed(id) { if !self.is_channel_collapsed(id) {
// return; return;
// } }
// self.toggle_channel_collapsed(id, cx) self.toggle_channel_collapsed(id, cx)
// } }
// fn toggle_channel_collapsed_action( // fn toggle_channel_collapsed_action(
// &mut self, // &mut self,
@ -2030,11 +2008,11 @@ impl CollabPanel {
self.collapsed_channels.binary_search(&channel_id).is_ok() self.collapsed_channels.binary_search(&channel_id).is_ok()
} }
// fn leave_call(cx: &mut ViewContext<Self>) { fn leave_call(cx: &mut ViewContext<Self>) {
// ActiveCall::global(cx) ActiveCall::global(cx)
// .update(cx, |call, cx| call.hang_up(cx)) .update(cx, |call, cx| call.hang_up(cx))
// .detach_and_log_err(cx); .detach_and_log_err(cx);
// } }
fn toggle_contact_finder(&mut self, cx: &mut ViewContext<Self>) { fn toggle_contact_finder(&mut self, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade() { if let Some(workspace) = self.workspace.upgrade() {
@ -2154,13 +2132,20 @@ impl CollabPanel {
} }
} }
// fn show_inline_context_menu(&mut self, _: &menu::ShowContextMenu, cx: &mut ViewContext<Self>) { fn show_inline_context_menu(&mut self, _: &menu::ShowContextMenu, cx: &mut ViewContext<Self>) {
// let Some(channel) = self.selected_channel() else { let Some(channel) = self.selected_channel() else {
// return; return;
// }; };
let Some(bounds) = self
.selection
.and_then(|ix| self.scroll_handle.bounds_for_item(ix))
else {
return;
};
// self.deploy_channel_context_menu(None, &channel.clone(), self.selection.unwrap(), cx); self.deploy_channel_context_menu(bounds.center(), channel.id, self.selection.unwrap(), cx);
// } cx.stop_propagation();
}
fn selected_channel(&self) -> Option<&Arc<Channel>> { fn selected_channel(&self) -> Option<&Arc<Channel>> {
self.selection self.selection
@ -2350,17 +2335,31 @@ impl CollabPanel {
) )
} }
fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> List { fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> Div {
let is_selected = false; // todo!() this.selection == Some(ix); v_stack()
.size_full()
List::new().children( .child(
div()
.p_2()
.child(div().rounded(px(2.0)).child(self.filter_editor.clone())),
)
.child(
v_stack()
.size_full()
.id("scroll")
.overflow_y_scroll()
.track_scroll(&self.scroll_handle)
.children(
self.entries self.entries
.clone() .clone()
.into_iter() .into_iter()
.enumerate() .enumerate()
.map(|(ix, entry)| match entry { .map(|(ix, entry)| {
let is_selected = self.selection == Some(ix);
match entry {
ListEntry::Header(section) => { ListEntry::Header(section) => {
let is_collapsed = self.collapsed_sections.contains(&section); let is_collapsed =
self.collapsed_sections.contains(&section);
self.render_header(section, is_selected, is_collapsed, cx) self.render_header(section, is_selected, is_collapsed, cx)
.into_any_element() .into_any_element()
} }
@ -2381,12 +2380,21 @@ impl CollabPanel {
depth, depth,
has_children, has_children,
} => self } => self
.render_channel(&*channel, depth, has_children, is_selected, ix, cx) .render_channel(
&*channel,
depth,
has_children,
is_selected,
ix,
cx,
)
.into_any_element(), .into_any_element(),
ListEntry::ChannelEditor { depth } => { ListEntry::ChannelEditor { depth } => {
self.render_channel_editor(depth, cx).into_any_element() self.render_channel_editor(depth, cx).into_any_element()
} }
}
}), }),
),
) )
} }
@ -2494,6 +2502,7 @@ impl CollabPanel {
el.child( el.child(
ListItem::new(text.clone()) ListItem::new(text.clone())
.child(div().w_full().child(Label::new(text))) .child(div().w_full().child(Label::new(text)))
.selected(is_selected)
.toggle(Some(!is_collapsed)) .toggle(Some(!is_collapsed))
.on_click(cx.listener(move |this, _, cx| { .on_click(cx.listener(move |this, _, cx| {
this.toggle_section_expanded(section, cx) this.toggle_section_expanded(section, cx)
@ -2502,7 +2511,7 @@ impl CollabPanel {
} else { } else {
el.child( el.child(
ListHeader::new(text) ListHeader::new(text)
.when_some(button, |el, button| el.right_button(button)) .when_some(button, |el, button| el.meta(button))
.selected(is_selected), .selected(is_selected),
) )
} }
@ -3214,23 +3223,36 @@ impl CollabPanel {
// } // }
impl Render for CollabPanel { impl Render for CollabPanel {
type Element = Focusable<Stateful<Div>>; type Element = Focusable<Div>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
div() v_stack()
.id("collab-panel")
.key_context("CollabPanel") .key_context("CollabPanel")
.on_action(cx.listener(CollabPanel::cancel))
.on_action(cx.listener(CollabPanel::select_next))
.on_action(cx.listener(CollabPanel::select_prev))
.on_action(cx.listener(CollabPanel::confirm))
.on_action(cx.listener(CollabPanel::insert_space))
// .on_action(cx.listener(CollabPanel::remove))
.on_action(cx.listener(CollabPanel::remove_selected_channel))
.on_action(cx.listener(CollabPanel::show_inline_context_menu))
// .on_action(cx.listener(CollabPanel::new_subchannel))
// .on_action(cx.listener(CollabPanel::invite_members))
// .on_action(cx.listener(CollabPanel::manage_members))
.on_action(cx.listener(CollabPanel::rename_selected_channel))
// .on_action(cx.listener(CollabPanel::rename_channel))
// .on_action(cx.listener(CollabPanel::toggle_channel_collapsed_action))
.on_action(cx.listener(CollabPanel::collapse_selected_channel))
.on_action(cx.listener(CollabPanel::expand_selected_channel))
// .on_action(cx.listener(CollabPanel::open_channel_notes))
// .on_action(cx.listener(CollabPanel::join_channel_chat))
// .on_action(cx.listener(CollabPanel::copy_channel_link))
.track_focus(&self.focus_handle) .track_focus(&self.focus_handle)
.size_full() .size_full()
.overflow_scroll() .child(if self.user_store.read(cx).current_user().is_none() {
.on_action(cx.listener(Self::confirm)) self.render_signed_out(cx)
.on_action(cx.listener(Self::insert_space))
.map(|el| {
if self.user_store.read(cx).current_user().is_none() {
el.child(self.render_signed_out(cx))
} else { } else {
el.child(self.render_signed_in(cx)) self.render_signed_in(cx)
}
}) })
.children(self.context_menu.as_ref().map(|(menu, position, _)| { .children(self.context_menu.as_ref().map(|(menu, position, _)| {
overlay() overlay()
@ -3392,19 +3414,19 @@ impl Panel for CollabPanel {
} }
impl FocusableView for CollabPanel { impl FocusableView for CollabPanel {
fn focus_handle(&self, _cx: &AppContext) -> gpui::FocusHandle { fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
self.focus_handle.clone() self.filter_editor.focus_handle(cx).clone()
} }
} }
// impl PartialEq for ListEntry { impl PartialEq for ListEntry {
// fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
// match self { match self {
// ListEntry::Header(section_1) => { ListEntry::Header(section_1) => {
// if let ListEntry::Header(section_2) = other { if let ListEntry::Header(section_2) = other {
// return section_1 == section_2; return section_1 == section_2;
// } }
// } }
// ListEntry::CallParticipant { user: user_1, .. } => { // ListEntry::CallParticipant { user: user_1, .. } => {
// if let ListEntry::CallParticipant { user: user_2, .. } = other { // if let ListEntry::CallParticipant { user: user_2, .. } = other {
// return user_1.id == user_2.id; // return user_1.id == user_2.id;
@ -3432,16 +3454,16 @@ impl FocusableView for CollabPanel {
// return peer_id_1 == peer_id_2; // return peer_id_1 == peer_id_2;
// } // }
// } // }
// ListEntry::Channel { ListEntry::Channel {
// channel: channel_1, .. channel: channel_1, ..
// } => { } => {
// if let ListEntry::Channel { if let ListEntry::Channel {
// channel: channel_2, .. channel: channel_2, ..
// } = other } = other
// { {
// return channel_1.id == channel_2.id; return channel_1.id == channel_2.id;
// } }
// } }
// ListEntry::ChannelNotes { channel_id } => { // ListEntry::ChannelNotes { channel_id } => {
// if let ListEntry::ChannelNotes { // if let ListEntry::ChannelNotes {
// channel_id: other_id, // channel_id: other_id,
@ -3463,40 +3485,40 @@ impl FocusableView for CollabPanel {
// return channel_1.id == channel_2.id; // return channel_1.id == channel_2.id;
// } // }
// } // }
// ListEntry::IncomingRequest(user_1) => { ListEntry::IncomingRequest(user_1) => {
// if let ListEntry::IncomingRequest(user_2) = other { if let ListEntry::IncomingRequest(user_2) = other {
// return user_1.id == user_2.id; return user_1.id == user_2.id;
// } }
// } }
// ListEntry::OutgoingRequest(user_1) => { ListEntry::OutgoingRequest(user_1) => {
// if let ListEntry::OutgoingRequest(user_2) = other { if let ListEntry::OutgoingRequest(user_2) = other {
// return user_1.id == user_2.id; return user_1.id == user_2.id;
// } }
// } }
// ListEntry::Contact { ListEntry::Contact {
// contact: contact_1, .. contact: contact_1, ..
// } => { } => {
// if let ListEntry::Contact { if let ListEntry::Contact {
// contact: contact_2, .. contact: contact_2, ..
// } = other } = other
// { {
// return contact_1.user.id == contact_2.user.id; return contact_1.user.id == contact_2.user.id;
// } }
// } }
// ListEntry::ChannelEditor { depth } => { ListEntry::ChannelEditor { depth } => {
// if let ListEntry::ChannelEditor { depth: other_depth } = other { if let ListEntry::ChannelEditor { depth: other_depth } = other {
// return depth == other_depth; return depth == other_depth;
// } }
// } }
// ListEntry::ContactPlaceholder => { ListEntry::ContactPlaceholder => {
// if let ListEntry::ContactPlaceholder = other { if let ListEntry::ContactPlaceholder = other {
// return true; return true;
// } }
// } }
// } }
// false false
// } }
// } }
// fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element<CollabPanel> { // fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element<CollabPanel> {
// Svg::new(svg_path) // Svg::new(svg_path)

View file

@ -185,7 +185,7 @@ impl PickerDelegate for ContactFinderDelegate {
div() div()
.flex_1() .flex_1()
.justify_between() .justify_between()
.children(user.avatar.clone().map(|avatar| img().data(avatar))) .children(user.avatar.clone().map(|avatar| img(avatar)))
.child(Label::new(user.github_login.clone())) .child(Label::new(user.github_login.clone()))
.children(icon_path.map(|icon_path| svg().path(icon_path))), .children(icon_path.map(|icon_path| svg().path(icon_path))),
) )

View file

@ -11,7 +11,7 @@ use gpui::{
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use ui::{h_stack, v_stack, HighlightedLabel, KeyBinding, ListItem}; use ui::{h_stack, prelude::*, v_stack, HighlightedLabel, KeyBinding, ListItem};
use util::{ use util::{
channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL}, channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},
ResultExt, ResultExt,

View file

@ -126,7 +126,7 @@ impl View for ProjectDiagnosticsEditor {
json!({ json!({
"project": json!({ "project": json!({
"language_servers": project.language_server_statuses().collect::<Vec<_>>(), "language_servers": project.language_server_statuses().collect::<Vec<_>>(),
"summary": project.diagnostic_summary(cx), "summary": project.diagnostic_summary(false, cx),
}), }),
"summary": self.summary, "summary": self.summary,
"paths_to_update": self.paths_to_update.iter().map(|(server_id, paths)| "paths_to_update": self.paths_to_update.iter().map(|(server_id, paths)|
@ -195,7 +195,7 @@ impl ProjectDiagnosticsEditor {
}); });
let project = project_handle.read(cx); let project = project_handle.read(cx);
let summary = project.diagnostic_summary(cx); let summary = project.diagnostic_summary(false, cx);
let mut this = Self { let mut this = Self {
project: project_handle, project: project_handle,
summary, summary,
@ -241,7 +241,7 @@ impl ProjectDiagnosticsEditor {
let mut new_summaries: HashMap<LanguageServerId, HashSet<ProjectPath>> = self let mut new_summaries: HashMap<LanguageServerId, HashSet<ProjectPath>> = self
.project .project
.read(cx) .read(cx)
.diagnostic_summaries(cx) .diagnostic_summaries(false, cx)
.fold(HashMap::default(), |mut summaries, (path, server_id, _)| { .fold(HashMap::default(), |mut summaries, (path, server_id, _)| {
summaries.entry(server_id).or_default().insert(path); summaries.entry(server_id).or_default().insert(path);
summaries summaries
@ -320,7 +320,7 @@ impl ProjectDiagnosticsEditor {
.context("rechecking diagnostics for paths")?; .context("rechecking diagnostics for paths")?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.summary = this.project.read(cx).diagnostic_summary(cx); this.summary = this.project.read(cx).diagnostic_summary(false, cx);
cx.emit(Event::TitleChanged); cx.emit(Event::TitleChanged);
})?; })?;
anyhow::Ok(()) anyhow::Ok(())

View file

@ -34,19 +34,19 @@ impl DiagnosticIndicator {
} }
project::Event::DiskBasedDiagnosticsFinished { language_server_id } project::Event::DiskBasedDiagnosticsFinished { language_server_id }
| project::Event::LanguageServerRemoved(language_server_id) => { | project::Event::LanguageServerRemoved(language_server_id) => {
this.summary = project.read(cx).diagnostic_summary(cx); this.summary = project.read(cx).diagnostic_summary(false, cx);
this.in_progress_checks.remove(language_server_id); this.in_progress_checks.remove(language_server_id);
cx.notify(); cx.notify();
} }
project::Event::DiagnosticsUpdated { .. } => { project::Event::DiagnosticsUpdated { .. } => {
this.summary = project.read(cx).diagnostic_summary(cx); this.summary = project.read(cx).diagnostic_summary(false, cx);
cx.notify(); cx.notify();
} }
_ => {} _ => {}
}) })
.detach(); .detach();
Self { Self {
summary: project.read(cx).diagnostic_summary(cx), summary: project.read(cx).diagnostic_summary(false, cx),
in_progress_checks: project in_progress_checks: project
.read(cx) .read(cx)
.language_servers_running_disk_based_diagnostics() .language_servers_running_disk_based_diagnostics()

View file

@ -165,7 +165,7 @@ impl ProjectDiagnosticsEditor {
}); });
let project = project_handle.read(cx); let project = project_handle.read(cx);
let summary = project.diagnostic_summary(cx); let summary = project.diagnostic_summary(false, cx);
let mut this = Self { let mut this = Self {
project: project_handle, project: project_handle,
summary, summary,
@ -252,7 +252,7 @@ impl ProjectDiagnosticsEditor {
let mut new_summaries: HashMap<LanguageServerId, HashSet<ProjectPath>> = self let mut new_summaries: HashMap<LanguageServerId, HashSet<ProjectPath>> = self
.project .project
.read(cx) .read(cx)
.diagnostic_summaries(cx) .diagnostic_summaries(false, cx)
.fold(HashMap::default(), |mut summaries, (path, server_id, _)| { .fold(HashMap::default(), |mut summaries, (path, server_id, _)| {
summaries.entry(server_id).or_default().insert(path); summaries.entry(server_id).or_default().insert(path);
summaries summaries
@ -332,7 +332,7 @@ impl ProjectDiagnosticsEditor {
.context("rechecking diagnostics for paths")?; .context("rechecking diagnostics for paths")?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.summary = this.project.read(cx).diagnostic_summary(cx); this.summary = this.project.read(cx).diagnostic_summary(false, cx);
cx.emit(ItemEvent::UpdateTab); cx.emit(ItemEvent::UpdateTab);
cx.emit(ItemEvent::UpdateBreadcrumbs); cx.emit(ItemEvent::UpdateBreadcrumbs);
})?; })?;

View file

@ -77,13 +77,13 @@ impl DiagnosticIndicator {
project::Event::DiskBasedDiagnosticsFinished { language_server_id } project::Event::DiskBasedDiagnosticsFinished { language_server_id }
| project::Event::LanguageServerRemoved(language_server_id) => { | project::Event::LanguageServerRemoved(language_server_id) => {
this.summary = project.read(cx).diagnostic_summary(cx); this.summary = project.read(cx).diagnostic_summary(false, cx);
this.in_progress_checks.remove(language_server_id); this.in_progress_checks.remove(language_server_id);
cx.notify(); cx.notify();
} }
project::Event::DiagnosticsUpdated { .. } => { project::Event::DiagnosticsUpdated { .. } => {
this.summary = project.read(cx).diagnostic_summary(cx); this.summary = project.read(cx).diagnostic_summary(false, cx);
cx.notify(); cx.notify();
} }
@ -92,7 +92,7 @@ impl DiagnosticIndicator {
.detach(); .detach();
Self { Self {
summary: project.read(cx).diagnostic_summary(cx), summary: project.read(cx).diagnostic_summary(false, cx),
in_progress_checks: project in_progress_checks: project
.read(cx) .read(cx)
.language_servers_running_disk_based_diagnostics() .language_servers_running_disk_based_diagnostics()

View file

@ -162,7 +162,7 @@ impl WrapMap {
{ {
let tab_snapshot = new_snapshot.tab_snapshot.clone(); let tab_snapshot = new_snapshot.tab_snapshot.clone();
let range = TabPoint::zero()..tab_snapshot.max_point(); let range = TabPoint::zero()..tab_snapshot.max_point();
let edits = new_snapshot edits = new_snapshot
.update( .update(
tab_snapshot, tab_snapshot,
&[TabEdit { &[TabEdit {

View file

@ -63,6 +63,7 @@ use language::{
use lazy_static::lazy_static; use lazy_static::lazy_static;
use link_go_to_definition::{GoToDefinitionLink, InlayHighlight, LinkGoToDefinitionState}; use link_go_to_definition::{GoToDefinitionLink, InlayHighlight, LinkGoToDefinitionState};
use lsp::{DiagnosticSeverity, LanguageServerId}; use lsp::{DiagnosticSeverity, LanguageServerId};
use mouse_context_menu::MouseContextMenu;
use movement::TextLayoutDetails; use movement::TextLayoutDetails;
use multi_buffer::ToOffsetUtf16; use multi_buffer::ToOffsetUtf16;
pub use multi_buffer::{ pub use multi_buffer::{
@ -407,133 +408,17 @@ pub fn init_settings(cx: &mut AppContext) {
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
init_settings(cx); init_settings(cx);
// cx.register_action_type(Editor::new_file);
// cx.register_action_type(Editor::new_file_in_direction);
// cx.register_action_type(Editor::cancel);
// cx.register_action_type(Editor::newline);
// cx.register_action_type(Editor::newline_above);
// cx.register_action_type(Editor::newline_below);
// cx.register_action_type(Editor::backspace);
// cx.register_action_type(Editor::delete);
// cx.register_action_type(Editor::tab);
// cx.register_action_type(Editor::tab_prev);
// cx.register_action_type(Editor::indent);
// cx.register_action_type(Editor::outdent);
// cx.register_action_type(Editor::delete_line);
// cx.register_action_type(Editor::join_lines);
// cx.register_action_type(Editor::sort_lines_case_sensitive);
// cx.register_action_type(Editor::sort_lines_case_insensitive);
// cx.register_action_type(Editor::reverse_lines);
// cx.register_action_type(Editor::shuffle_lines);
// cx.register_action_type(Editor::convert_to_upper_case);
// cx.register_action_type(Editor::convert_to_lower_case);
// cx.register_action_type(Editor::convert_to_title_case);
// cx.register_action_type(Editor::convert_to_snake_case);
// cx.register_action_type(Editor::convert_to_kebab_case);
// cx.register_action_type(Editor::convert_to_upper_camel_case);
// cx.register_action_type(Editor::convert_to_lower_camel_case);
// cx.register_action_type(Editor::delete_to_previous_word_start);
// cx.register_action_type(Editor::delete_to_previous_subword_start);
// cx.register_action_type(Editor::delete_to_next_word_end);
// cx.register_action_type(Editor::delete_to_next_subword_end);
// cx.register_action_type(Editor::delete_to_beginning_of_line);
// cx.register_action_type(Editor::delete_to_end_of_line);
// cx.register_action_type(Editor::cut_to_end_of_line);
// cx.register_action_type(Editor::duplicate_line);
// cx.register_action_type(Editor::move_line_up);
// cx.register_action_type(Editor::move_line_down);
// cx.register_action_type(Editor::transpose);
// cx.register_action_type(Editor::cut);
// cx.register_action_type(Editor::copy);
// cx.register_action_type(Editor::paste);
// cx.register_action_type(Editor::undo);
// cx.register_action_type(Editor::redo);
// cx.register_action_type(Editor::move_page_up);
// cx.register_action_type::<MoveDown>();
// cx.register_action_type(Editor::move_page_down);
// cx.register_action_type(Editor::next_screen);
// cx.register_action_type::<MoveLeft>();
// cx.register_action_type::<MoveRight>();
// cx.register_action_type(Editor::move_to_previous_word_start);
// cx.register_action_type(Editor::move_to_previous_subword_start);
// cx.register_action_type(Editor::move_to_next_word_end);
// cx.register_action_type(Editor::move_to_next_subword_end);
// cx.register_action_type(Editor::move_to_beginning_of_line);
// cx.register_action_type(Editor::move_to_end_of_line);
// cx.register_action_type(Editor::move_to_start_of_paragraph);
// cx.register_action_type(Editor::move_to_end_of_paragraph);
// cx.register_action_type(Editor::move_to_beginning);
// cx.register_action_type(Editor::move_to_end);
// cx.register_action_type(Editor::select_up);
// cx.register_action_type(Editor::select_down);
// cx.register_action_type(Editor::select_left);
// cx.register_action_type(Editor::select_right);
// cx.register_action_type(Editor::select_to_previous_word_start);
// cx.register_action_type(Editor::select_to_previous_subword_start);
// cx.register_action_type(Editor::select_to_next_word_end);
// cx.register_action_type(Editor::select_to_next_subword_end);
// cx.register_action_type(Editor::select_to_beginning_of_line);
// cx.register_action_type(Editor::select_to_end_of_line);
// cx.register_action_type(Editor::select_to_start_of_paragraph);
// cx.register_action_type(Editor::select_to_end_of_paragraph);
// cx.register_action_type(Editor::select_to_beginning);
// cx.register_action_type(Editor::select_to_end);
// cx.register_action_type(Editor::select_all);
// cx.register_action_type(Editor::select_all_matches);
// cx.register_action_type(Editor::select_line);
// cx.register_action_type(Editor::split_selection_into_lines);
// cx.register_action_type(Editor::add_selection_above);
// cx.register_action_type(Editor::add_selection_below);
// cx.register_action_type(Editor::select_next);
// cx.register_action_type(Editor::select_previous);
// cx.register_action_type(Editor::toggle_comments);
// cx.register_action_type(Editor::select_larger_syntax_node);
// cx.register_action_type(Editor::select_smaller_syntax_node);
// cx.register_action_type(Editor::move_to_enclosing_bracket);
// cx.register_action_type(Editor::undo_selection);
// cx.register_action_type(Editor::redo_selection);
// cx.register_action_type(Editor::go_to_diagnostic);
// cx.register_action_type(Editor::go_to_prev_diagnostic);
// cx.register_action_type(Editor::go_to_hunk);
// cx.register_action_type(Editor::go_to_prev_hunk);
// cx.register_action_type(Editor::go_to_definition);
// cx.register_action_type(Editor::go_to_definition_split);
// cx.register_action_type(Editor::go_to_type_definition);
// cx.register_action_type(Editor::go_to_type_definition_split);
// cx.register_action_type(Editor::fold);
// cx.register_action_type(Editor::fold_at);
// cx.register_action_type(Editor::unfold_lines);
// cx.register_action_type(Editor::unfold_at);
// cx.register_action_type(Editor::gutter_hover);
// cx.register_action_type(Editor::fold_selected_ranges);
// cx.register_action_type(Editor::show_completions);
// cx.register_action_type(Editor::toggle_code_actions);
// cx.register_action_type(Editor::open_excerpts);
// cx.register_action_type(Editor::toggle_soft_wrap);
// cx.register_action_type(Editor::toggle_inlay_hints);
// cx.register_action_type(Editor::reveal_in_finder);
// cx.register_action_type(Editor::copy_path);
// cx.register_action_type(Editor::copy_relative_path);
// cx.register_action_type(Editor::copy_highlight_json);
// cx.add_async_action(Editor::format);
// cx.register_action_type(Editor::restart_language_server);
// cx.register_action_type(Editor::show_character_palette);
// cx.add_async_action(Editor::confirm_completion);
// cx.add_async_action(Editor::confirm_code_action);
// cx.add_async_action(Editor::rename);
// cx.add_async_action(Editor::confirm_rename);
// cx.add_async_action(Editor::find_all_references);
// cx.register_action_type(Editor::next_copilot_suggestion);
// cx.register_action_type(Editor::previous_copilot_suggestion);
// cx.register_action_type(Editor::copilot_suggest);
// cx.register_action_type(Editor::context_menu_first);
// cx.register_action_type(Editor::context_menu_prev);
// cx.register_action_type(Editor::context_menu_next);
// cx.register_action_type(Editor::context_menu_last);
workspace::register_project_item::<Editor>(cx); workspace::register_project_item::<Editor>(cx);
workspace::register_followable_item::<Editor>(cx); workspace::register_followable_item::<Editor>(cx);
workspace::register_deserializable_item::<Editor>(cx); workspace::register_deserializable_item::<Editor>(cx);
cx.observe_new_views(
|workspace: &mut Workspace, cx: &mut ViewContext<Workspace>| {
workspace.register_action(Editor::new_file);
workspace.register_action(Editor::new_file_in_direction);
},
)
.detach();
} }
trait InvalidationRegion { trait InvalidationRegion {
@ -621,8 +506,6 @@ pub struct Editor {
ime_transaction: Option<TransactionId>, ime_transaction: Option<TransactionId>,
active_diagnostics: Option<ActiveDiagnosticGroup>, active_diagnostics: Option<ActiveDiagnosticGroup>,
soft_wrap_mode_override: Option<language_settings::SoftWrap>, soft_wrap_mode_override: Option<language_settings::SoftWrap>,
// get_field_editor_theme: Option<Arc<GetFieldEditorTheme>>,
// override_text_style: Option<Box<OverrideTextStyle>>,
project: Option<Model<Project>>, project: Option<Model<Project>>,
collaboration_hub: Option<Box<dyn CollaborationHub>>, collaboration_hub: Option<Box<dyn CollaborationHub>>,
blink_manager: Model<BlinkManager>, blink_manager: Model<BlinkManager>,
@ -636,7 +519,7 @@ pub struct Editor {
inlay_background_highlights: TreeMap<Option<TypeId>, InlayBackgroundHighlight>, inlay_background_highlights: TreeMap<Option<TypeId>, InlayBackgroundHighlight>,
nav_history: Option<ItemNavHistory>, nav_history: Option<ItemNavHistory>,
context_menu: RwLock<Option<ContextMenu>>, context_menu: RwLock<Option<ContextMenu>>,
// mouse_context_menu: View<context_menu::ContextMenu>, mouse_context_menu: Option<MouseContextMenu>,
completion_tasks: Vec<(CompletionId, Task<Option<()>>)>, completion_tasks: Vec<(CompletionId, Task<Option<()>>)>,
next_completion_id: CompletionId, next_completion_id: CompletionId,
available_code_actions: Option<(Model<Buffer>, Arc<[CodeAction]>)>, available_code_actions: Option<(Model<Buffer>, Arc<[CodeAction]>)>,
@ -1734,21 +1617,11 @@ impl Editor {
// Self::new(EditorMode::Full, buffer, None, field_editor_style, cx) // Self::new(EditorMode::Full, buffer, None, field_editor_style, cx)
// } // }
// pub fn auto_height( pub fn auto_height(max_lines: usize, cx: &mut ViewContext<Self>) -> Self {
// max_lines: usize, let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new()));
// field_editor_style: Option<Arc<GetFieldEditorTheme>>, let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
// cx: &mut ViewContext<Self>, Self::new(EditorMode::AutoHeight { max_lines }, buffer, None, cx)
// ) -> Self { }
// let buffer = cx.build_model(|cx| Buffer::new(0, cx.model_id() as u64, String::new()));
// let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
// Self::new(
// EditorMode::AutoHeight { max_lines },
// buffer,
// None,
// field_editor_style,
// cx,
// )
// }
pub fn for_buffer( pub fn for_buffer(
buffer: Model<Buffer>, buffer: Model<Buffer>,
@ -1768,14 +1641,7 @@ impl Editor {
} }
pub fn clone(&self, cx: &mut ViewContext<Self>) -> Self { pub fn clone(&self, cx: &mut ViewContext<Self>) -> Self {
let mut clone = Self::new( let mut clone = Self::new(self.mode, self.buffer.clone(), self.project.clone(), cx);
self.mode,
self.buffer.clone(),
self.project.clone(),
// todo!
// self.get_field_editor_theme.clone(),
cx,
);
self.display_map.update(cx, |display_map, cx| { self.display_map.update(cx, |display_map, cx| {
let snapshot = display_map.snapshot(cx); let snapshot = display_map.snapshot(cx);
clone.display_map.update(cx, |display_map, cx| { clone.display_map.update(cx, |display_map, cx| {
@ -1792,17 +1658,11 @@ impl Editor {
mode: EditorMode, mode: EditorMode,
buffer: Model<MultiBuffer>, buffer: Model<MultiBuffer>,
project: Option<Model<Project>>, project: Option<Model<Project>>,
// todo!()
// get_field_editor_theme: Option<Arc<GetFieldEditorTheme>>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
// let editor_view_id = cx.view_id();
let style = cx.text_style(); let style = cx.text_style();
let font_size = style.font_size.to_pixels(cx.rem_size()); let font_size = style.font_size.to_pixels(cx.rem_size());
let display_map = cx.build_model(|cx| { let display_map = cx.build_model(|cx| {
// todo!()
// let settings = settings::get::<ThemeSettings>(cx);
// let style = build_style(settings, get_field_editor_theme.as_deref(), None, cx);
DisplayMap::new(buffer.clone(), style.font(), font_size, None, 2, 1, cx) DisplayMap::new(buffer.clone(), style.font(), font_size, None, 2, 1, cx)
}); });
@ -1858,7 +1718,6 @@ impl Editor {
ime_transaction: Default::default(), ime_transaction: Default::default(),
active_diagnostics: None, active_diagnostics: None,
soft_wrap_mode_override, soft_wrap_mode_override,
// get_field_editor_theme,
collaboration_hub: project.clone().map(|project| Box::new(project) as _), collaboration_hub: project.clone().map(|project| Box::new(project) as _),
project, project,
blink_manager: blink_manager.clone(), blink_manager: blink_manager.clone(),
@ -1872,8 +1731,7 @@ impl Editor {
inlay_background_highlights: Default::default(), inlay_background_highlights: Default::default(),
nav_history: None, nav_history: None,
context_menu: RwLock::new(None), context_menu: RwLock::new(None),
// mouse_context_menu: cx mouse_context_menu: None,
// .add_view(|cx| context_menu::ContextMenu::new(editor_view_id, cx)),
completion_tasks: Default::default(), completion_tasks: Default::default(),
next_completion_id: 0, next_completion_id: 0,
next_inlay_id: 0, next_inlay_id: 0,
@ -1882,7 +1740,6 @@ impl Editor {
document_highlights_task: Default::default(), document_highlights_task: Default::default(),
pending_rename: Default::default(), pending_rename: Default::default(),
searchable: true, searchable: true,
// override_text_style: None,
cursor_shape: Default::default(), cursor_shape: Default::default(),
autoindent_mode: Some(AutoindentMode::EachLine), autoindent_mode: Some(AutoindentMode::EachLine),
collapse_matches: false, collapse_matches: false,
@ -2000,25 +1857,25 @@ impl Editor {
} }
} }
// pub fn new_file_in_direction( pub fn new_file_in_direction(
// workspace: &mut Workspace, workspace: &mut Workspace,
// action: &workspace::NewFileInDirection, action: &workspace::NewFileInDirection,
// cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
// ) { ) {
// let project = workspace.project().clone(); let project = workspace.project().clone();
// if project.read(cx).is_remote() { if project.read(cx).is_remote() {
// cx.propagate(); cx.propagate();
// } else if let Some(buffer) = project } else if let Some(buffer) = project
// .update(cx, |project, cx| project.create_buffer("", None, cx)) .update(cx, |project, cx| project.create_buffer("", None, cx))
// .log_err() .log_err()
// { {
// workspace.split_item( workspace.split_item(
// action.0, action.0,
// Box::new(cx.add_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))), Box::new(cx.build_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),
// cx, cx,
// ); );
// } }
// } }
pub fn replica_id(&self, cx: &AppContext) -> ReplicaId { pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
self.buffer.read(cx).replica_id() self.buffer.read(cx).replica_id()
@ -8374,6 +8231,18 @@ impl Editor {
cx.notify(); cx.notify();
} }
pub fn set_style(&mut self, style: EditorStyle, cx: &mut ViewContext<Self>) {
let rem_size = cx.rem_size();
self.display_map.update(cx, |map, cx| {
map.set_font(
style.text.font(),
style.text.font_size.to_pixels(rem_size),
cx,
)
});
self.style = Some(style);
}
pub fn set_wrap_width(&self, width: Option<Pixels>, cx: &mut AppContext) -> bool { pub fn set_wrap_width(&self, width: Option<Pixels>, cx: &mut AppContext) -> bool {
self.display_map self.display_map
.update(cx, |map, cx| map.set_wrap_width(width, cx)) .update(cx, |map, cx| map.set_wrap_width(width, cx))
@ -8796,62 +8665,56 @@ impl Editor {
// self.searchable // self.searchable
// } // }
// fn open_excerpts(workspace: &mut Workspace, _: &OpenExcerpts, cx: &mut ViewContext<Workspace>) { fn open_excerpts(&mut self, _: &OpenExcerpts, cx: &mut ViewContext<Self>) {
// let active_item = workspace.active_item(cx); let buffer = self.buffer.read(cx);
// let editor_handle = if let Some(editor) = active_item if buffer.is_singleton() {
// .as_ref() cx.propagate();
// .and_then(|item| item.act_as::<Self>(cx)) return;
// { }
// editor
// } else {
// cx.propagate();
// return;
// };
// let editor = editor_handle.read(cx); let Some(workspace) = self.workspace() else {
// let buffer = editor.buffer.read(cx); cx.propagate();
// if buffer.is_singleton() { return;
// cx.propagate(); };
// return;
// }
// let mut new_selections_by_buffer = HashMap::default(); let mut new_selections_by_buffer = HashMap::default();
// for selection in editor.selections.all::<usize>(cx) { for selection in self.selections.all::<usize>(cx) {
// for (buffer, mut range, _) in for (buffer, mut range, _) in
// buffer.range_to_buffer_ranges(selection.start..selection.end, cx) buffer.range_to_buffer_ranges(selection.start..selection.end, cx)
// { {
// if selection.reversed { if selection.reversed {
// mem::swap(&mut range.start, &mut range.end); mem::swap(&mut range.start, &mut range.end);
// } }
// new_selections_by_buffer new_selections_by_buffer
// .entry(buffer) .entry(buffer)
// .or_insert(Vec::new()) .or_insert(Vec::new())
// .push(range) .push(range)
// } }
// } }
// editor_handle.update(cx, |editor, cx| { self.push_to_nav_history(self.selections.newest_anchor().head(), None, cx);
// editor.push_to_nav_history(editor.selections.newest_anchor().head(), None, cx);
// });
// let pane = workspace.active_pane().clone();
// pane.update(cx, |pane, _| pane.disable_history());
// // We defer the pane interaction because we ourselves are a workspace item // We defer the pane interaction because we ourselves are a workspace item
// // and activating a new item causes the pane to call a method on us reentrantly, // and activating a new item causes the pane to call a method on us reentrantly,
// // which panics if we're on the stack. // which panics if we're on the stack.
// cx.defer(move |workspace, cx| { cx.window_context().defer(move |cx| {
// for (buffer, ranges) in new_selections_by_buffer.into_iter() { workspace.update(cx, |workspace, cx| {
// let editor = workspace.open_project_item::<Self>(buffer, cx); let pane = workspace.active_pane().clone();
// editor.update(cx, |editor, cx| { pane.update(cx, |pane, _| pane.disable_history());
// editor.change_selections(Some(Autoscroll::newest()), cx, |s| {
// s.select_ranges(ranges);
// });
// });
// }
// pane.update(cx, |pane, _| pane.enable_history()); for (buffer, ranges) in new_selections_by_buffer.into_iter() {
// }); let editor = workspace.open_project_item::<Self>(buffer, cx);
// } editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::newest()), cx, |s| {
s.select_ranges(ranges);
});
});
}
pane.update(cx, |pane, _| pane.enable_history());
})
});
}
fn jump( fn jump(
&mut self, &mut self,
@ -9397,7 +9260,7 @@ impl Render for Editor {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let settings = ThemeSettings::get_global(cx); let settings = ThemeSettings::get_global(cx);
let text_style = match self.mode { let text_style = match self.mode {
EditorMode::SingleLine => TextStyle { EditorMode::SingleLine | EditorMode::AutoHeight { .. } => TextStyle {
color: cx.theme().colors().text, color: cx.theme().colors().text,
font_family: settings.ui_font.family.clone(), font_family: settings.ui_font.family.clone(),
font_features: settings.ui_font.features, font_features: settings.ui_font.features,
@ -9410,8 +9273,6 @@ impl Render for Editor {
white_space: WhiteSpace::Normal, white_space: WhiteSpace::Normal,
}, },
EditorMode::AutoHeight { max_lines } => todo!(),
EditorMode::Full => TextStyle { EditorMode::Full => TextStyle {
color: cx.theme().colors().text, color: cx.theme().colors().text,
font_family: settings.buffer_font.family.clone(), font_family: settings.buffer_font.family.clone(),
@ -9446,106 +9307,6 @@ impl Render for Editor {
} }
} }
// impl View for Editor {
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// let style = self.style(cx);
// let font_changed = self.display_map.update(cx, |map, cx| {
// map.set_fold_ellipses_color(style.folds.ellipses.text_color);
// map.set_font_with_size(style.text.font_id, style.text.font_size, cx)
// });
// if font_changed {
// cx.defer(move |editor, cx: &mut ViewContext<Editor>| {
// hide_hover(editor, cx);
// hide_link_definition(editor, cx);
// });
// }
// Stack::new()
// .with_child(EditorElement::new(style.clone()))
// .with_child(ChildView::new(&self.mouse_context_menu, cx))
// .into_any()
// }
// fn ui_name() -> &'static str {
// "Editor"
// }
// fn focus_in(&mut self, focused: AnyView, cx: &mut ViewContext<Self>) {
// if cx.is_self_focused() {
// let focused_event = EditorFocused(cx.handle());
// cx.emit(Event::Focused);
// cx.emit_global(focused_event);
// }
// if let Some(rename) = self.pending_rename.as_ref() {
// cx.focus(&rename.editor);
// } else if cx.is_self_focused() || !focused.is::<Editor>() {
// if !self.focused {
// self.blink_manager.update(cx, BlinkManager::enable);
// }
// self.focused = true;
// self.buffer.update(cx, |buffer, cx| {
// buffer.finalize_last_transaction(cx);
// if self.leader_peer_id.is_none() {
// buffer.set_active_selections(
// &self.selections.disjoint_anchors(),
// self.selections.line_mode,
// self.cursor_shape,
// cx,
// );
// }
// });
// }
// }
// fn focus_out(&mut self, _: AnyView, cx: &mut ViewContext<Self>) {
// let blurred_event = EditorBlurred(cx.handle());
// cx.emit_global(blurred_event);
// self.focused = false;
// self.blink_manager.update(cx, BlinkManager::disable);
// self.buffer
// .update(cx, |buffer, cx| buffer.remove_active_selections(cx));
// self.hide_context_menu(cx);
// hide_hover(self, cx);
// cx.emit(Event::Blurred);
// cx.notify();
// }
// fn modifiers_changed(
// &mut self,
// event: &gpui::platform::ModifiersChangedEvent,
// cx: &mut ViewContext<Self>,
// ) -> bool {
// let pending_selection = self.has_pending_selection();
// if let Some(point) = &self.link_go_to_definition_state.last_trigger_point {
// if event.cmd && !pending_selection {
// let point = point.clone();
// let snapshot = self.snapshot(cx);
// let kind = point.definition_kind(event.shift);
// show_link_definition(kind, self, point, snapshot, cx);
// return false;
// }
// }
// {
// if self.link_go_to_definition_state.symbol_range.is_some()
// || !self.link_go_to_definition_state.definitions.is_empty()
// {
// self.link_go_to_definition_state.symbol_range.take();
// self.link_go_to_definition_state.definitions.clear();
// cx.notify();
// }
// self.link_go_to_definition_state.task = None;
// self.clear_highlights::<LinkGoToDefinitionState>(cx);
// }
// false
// }
impl InputHandler for Editor { impl InputHandler for Editor {
fn text_for_range( fn text_for_range(
&mut self, &mut self,
@ -9792,72 +9553,6 @@ impl InputHandler for Editor {
} }
} }
// fn build_style(
// settings: &ThemeSettings,
// get_field_editor_theme: Option<&GetFieldEditorTheme>,
// override_text_style: Option<&OverrideTextStyle>,
// cx: &mut AppContext,
// ) -> EditorStyle {
// let font_cache = cx.font_cache();
// let line_height_scalar = settings.line_height();
// let theme_id = settings.theme.meta.id;
// let mut theme = settings.theme.editor.clone();
// let mut style = if let Some(get_field_editor_theme) = get_field_editor_theme {
// let field_editor_theme = get_field_editor_theme(&settings.theme);
// theme.text_color = field_editor_theme.text.color;
// theme.selection = field_editor_theme.selection;
// theme.background = field_editor_theme
// .container
// .background_color
// .unwrap_or_default();
// EditorStyle {
// text: field_editor_theme.text,
// placeholder_text: field_editor_theme.placeholder_text,
// line_height_scalar,
// theme,
// theme_id,
// }
// } else {
// todo!();
// // let font_family_id = settings.buffer_font_family;
// // let font_family_name = cx.font_cache().family_name(font_family_id).unwrap();
// // let font_properties = Default::default();
// // let font_id = font_cache
// // .select_font(font_family_id, &font_properties)
// // .unwrap();
// // let font_size = settings.buffer_font_size(cx);
// // EditorStyle {
// // text: TextStyle {
// // color: settings.theme.editor.text_color,
// // font_family_name,
// // font_family_id,
// // font_id,
// // font_size,
// // font_properties,
// // underline: Default::default(),
// // soft_wrap: false,
// // },
// // placeholder_text: None,
// // line_height_scalar,
// // theme,
// // theme_id,
// // }
// };
// if let Some(highlight_style) = override_text_style.and_then(|build_style| build_style(&style)) {
// if let Some(highlighted) = style
// .text
// .clone()
// .highlight(highlight_style, font_cache)
// .log_err()
// {
// style.text = highlighted;
// }
// }
// style
// }
trait SelectionExt { trait SelectionExt {
fn offset_range(&self, buffer: &MultiBufferSnapshot) -> Range<usize>; fn offset_range(&self, buffer: &MultiBufferSnapshot) -> Range<usize>;
fn point_range(&self, buffer: &MultiBufferSnapshot) -> Range<Point>; fn point_range(&self, buffer: &MultiBufferSnapshot) -> Range<Point>;

File diff suppressed because it is too large Load diff

View file

@ -4,13 +4,14 @@ use crate::{
EditorEvent, EditorSettings, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, EditorEvent, EditorSettings, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot,
NavigationData, ToPoint as _, NavigationData, ToPoint as _,
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context as _, Result};
use collections::HashSet; use collections::HashSet;
use futures::future::try_join_all; use futures::future::try_join_all;
use gpui::{ use gpui::{
div, point, AnyElement, AppContext, AsyncAppContext, Entity, EntityId, EventEmitter, div, point, AnyElement, AppContext, AsyncAppContext, AsyncWindowContext, Context, Div, Entity,
FocusHandle, Model, ParentElement, Pixels, SharedString, Styled, Subscription, Task, View, EntityId, EventEmitter, FocusHandle, IntoElement, Model, ParentElement, Pixels, Render,
ViewContext, VisualContext, WeakView, WindowContext, SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
WindowContext,
}; };
use language::{ use language::{
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, OffsetRangeExt, proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, OffsetRangeExt,
@ -20,6 +21,7 @@ use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPat
use rpc::proto::{self, update_view, PeerId}; use rpc::proto::{self, update_view, PeerId};
use settings::Settings; use settings::Settings;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::fmt::Write;
use std::{ use std::{
borrow::Cow, borrow::Cow,
cmp::{self, Ordering}, cmp::{self, Ordering},
@ -31,8 +33,11 @@ use std::{
use text::Selection; use text::Selection;
use theme::{ActiveTheme, Theme}; use theme::{ActiveTheme, Theme};
use ui::{Color, Label}; use ui::{Color, Label};
use util::{paths::PathExt, ResultExt, TryFutureExt}; use util::{paths::PathExt, paths::FILE_ROW_COLUMN_DELIMITER, ResultExt, TryFutureExt};
use workspace::item::{BreadcrumbText, FollowEvent, FollowableEvents, FollowableItemHandle}; use workspace::{
item::{BreadcrumbText, FollowEvent, FollowableEvents, FollowableItemHandle},
StatusItemView,
};
use workspace::{ use workspace::{
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem}, item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle}, searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},
@ -71,110 +76,108 @@ impl FollowableItem for Editor {
workspace: View<Workspace>, workspace: View<Workspace>,
remote_id: ViewId, remote_id: ViewId,
state: &mut Option<proto::view::Variant>, state: &mut Option<proto::view::Variant>,
cx: &mut AppContext, cx: &mut WindowContext,
) -> Option<Task<Result<View<Self>>>> { ) -> Option<Task<Result<View<Self>>>> {
todo!() let project = workspace.read(cx).project().to_owned();
let Some(proto::view::Variant::Editor(_)) = state else {
return None;
};
let Some(proto::view::Variant::Editor(state)) = state.take() else {
unreachable!()
};
let client = project.read(cx).client();
let replica_id = project.read(cx).replica_id();
let buffer_ids = state
.excerpts
.iter()
.map(|excerpt| excerpt.buffer_id)
.collect::<HashSet<_>>();
let buffers = project.update(cx, |project, cx| {
buffer_ids
.iter()
.map(|id| project.open_buffer_by_id(*id, cx))
.collect::<Vec<_>>()
});
let pane = pane.downgrade();
Some(cx.spawn(|mut cx| async move {
let mut buffers = futures::future::try_join_all(buffers).await?;
let editor = pane.update(&mut cx, |pane, cx| {
let mut editors = pane.items_of_type::<Self>();
editors.find(|editor| {
let ids_match = editor.remote_id(&client, cx) == Some(remote_id);
let singleton_buffer_matches = state.singleton
&& buffers.first()
== editor.read(cx).buffer.read(cx).as_singleton().as_ref();
ids_match || singleton_buffer_matches
})
})?;
let editor = if let Some(editor) = editor {
editor
} else {
pane.update(&mut cx, |_, cx| {
let multibuffer = cx.build_model(|cx| {
let mut multibuffer;
if state.singleton && buffers.len() == 1 {
multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx)
} else {
multibuffer = MultiBuffer::new(replica_id);
let mut excerpts = state.excerpts.into_iter().peekable();
while let Some(excerpt) = excerpts.peek() {
let buffer_id = excerpt.buffer_id;
let buffer_excerpts = iter::from_fn(|| {
let excerpt = excerpts.peek()?;
(excerpt.buffer_id == buffer_id)
.then(|| excerpts.next().unwrap())
});
let buffer =
buffers.iter().find(|b| b.read(cx).remote_id() == buffer_id);
if let Some(buffer) = buffer {
multibuffer.push_excerpts(
buffer.clone(),
buffer_excerpts.filter_map(deserialize_excerpt_range),
cx,
);
} }
// let project = workspace.read(cx).project().to_owned(); }
// let Some(proto::view::Variant::Editor(_)) = state else { };
// return None;
// };
// let Some(proto::view::Variant::Editor(state)) = state.take() else {
// unreachable!()
// };
// let client = project.read(cx).client(); if let Some(title) = &state.title {
// let replica_id = project.read(cx).replica_id(); multibuffer = multibuffer.with_title(title.clone())
// let buffer_ids = state }
// .excerpts
// .iter()
// .map(|excerpt| excerpt.buffer_id)
// .collect::<HashSet<_>>();
// let buffers = project.update(cx, |project, cx| {
// buffer_ids
// .iter()
// .map(|id| project.open_buffer_by_id(*id, cx))
// .collect::<Vec<_>>()
// });
// let pane = pane.downgrade(); multibuffer
// Some(cx.spawn(|mut cx| async move { });
// let mut buffers = futures::future::try_join_all(buffers).await?;
// let editor = pane.read_with(&cx, |pane, cx| {
// let mut editors = pane.items_of_type::<Self>();
// editors.find(|editor| {
// let ids_match = editor.remote_id(&client, cx) == Some(remote_id);
// let singleton_buffer_matches = state.singleton
// && buffers.first()
// == editor.read(cx).buffer.read(cx).as_singleton().as_ref();
// ids_match || singleton_buffer_matches
// })
// })?;
// let editor = if let Some(editor) = editor { cx.build_view(|cx| {
// editor let mut editor =
// } else { Editor::for_multibuffer(multibuffer, Some(project.clone()), cx);
// pane.update(&mut cx, |_, cx| { editor.remote_id = Some(remote_id);
// let multibuffer = cx.add_model(|cx| { editor
// let mut multibuffer; })
// if state.singleton && buffers.len() == 1 { })?
// multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx) };
// } else {
// multibuffer = MultiBuffer::new(replica_id);
// let mut excerpts = state.excerpts.into_iter().peekable();
// while let Some(excerpt) = excerpts.peek() {
// let buffer_id = excerpt.buffer_id;
// let buffer_excerpts = iter::from_fn(|| {
// let excerpt = excerpts.peek()?;
// (excerpt.buffer_id == buffer_id)
// .then(|| excerpts.next().unwrap())
// });
// let buffer =
// buffers.iter().find(|b| b.read(cx).remote_id() == buffer_id);
// if let Some(buffer) = buffer {
// multibuffer.push_excerpts(
// buffer.clone(),
// buffer_excerpts.filter_map(deserialize_excerpt_range),
// cx,
// );
// }
// }
// };
// if let Some(title) = &state.title { update_editor_from_message(
// multibuffer = multibuffer.with_title(title.clone()) editor.downgrade(),
// } project,
proto::update_view::Editor {
selections: state.selections,
pending_selection: state.pending_selection,
scroll_top_anchor: state.scroll_top_anchor,
scroll_x: state.scroll_x,
scroll_y: state.scroll_y,
..Default::default()
},
&mut cx,
)
.await?;
// multibuffer Ok(editor)
// }); }))
}
// cx.add_view(|cx| {
// let mut editor =
// Editor::for_multibuffer(multibuffer, Some(project.clone()), cx);
// editor.remote_id = Some(remote_id);
// editor
// })
// })?
// };
// update_editor_from_message(
// editor.downgrade(),
// project,
// proto::update_view::Editor {
// selections: state.selections,
// pending_selection: state.pending_selection,
// scroll_top_anchor: state.scroll_top_anchor,
// scroll_x: state.scroll_x,
// scroll_y: state.scroll_y,
// ..Default::default()
// },
// &mut cx,
// )
// .await?;
// Ok(editor)
// }))
// }
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>) { fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>) {
self.leader_peer_id = leader_peer_id; self.leader_peer_id = leader_peer_id;
@ -195,7 +198,7 @@ impl FollowableItem for Editor {
cx.notify(); cx.notify();
} }
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant> { fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant> {
let buffer = self.buffer.read(cx); let buffer = self.buffer.read(cx);
let scroll_anchor = self.scroll_manager.anchor(); let scroll_anchor = self.scroll_manager.anchor();
let excerpts = buffer let excerpts = buffer
@ -242,7 +245,7 @@ impl FollowableItem for Editor {
&self, &self,
event: &Self::FollowableEvent, event: &Self::FollowableEvent,
update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
cx: &AppContext, cx: &WindowContext,
) -> bool { ) -> bool {
let update = let update =
update.get_or_insert_with(|| proto::update_view::Variant::Editor(Default::default())); update.get_or_insert_with(|| proto::update_view::Variant::Editor(Default::default()));
@ -315,7 +318,7 @@ impl FollowableItem for Editor {
}) })
} }
fn is_project_item(&self, _cx: &AppContext) -> bool { fn is_project_item(&self, _cx: &WindowContext) -> bool {
true true
} }
} }
@ -324,132 +327,129 @@ async fn update_editor_from_message(
this: WeakView<Editor>, this: WeakView<Editor>,
project: Model<Project>, project: Model<Project>,
message: proto::update_view::Editor, message: proto::update_view::Editor,
cx: &mut AsyncAppContext, cx: &mut AsyncWindowContext,
) -> Result<()> { ) -> Result<()> {
todo!() // Open all of the buffers of which excerpts were added to the editor.
let inserted_excerpt_buffer_ids = message
.inserted_excerpts
.iter()
.filter_map(|insertion| Some(insertion.excerpt.as_ref()?.buffer_id))
.collect::<HashSet<_>>();
let inserted_excerpt_buffers = project.update(cx, |project, cx| {
inserted_excerpt_buffer_ids
.into_iter()
.map(|id| project.open_buffer_by_id(id, cx))
.collect::<Vec<_>>()
})?;
let _inserted_excerpt_buffers = try_join_all(inserted_excerpt_buffers).await?;
// Update the editor's excerpts.
this.update(cx, |editor, cx| {
editor.buffer.update(cx, |multibuffer, cx| {
let mut removed_excerpt_ids = message
.deleted_excerpts
.into_iter()
.map(ExcerptId::from_proto)
.collect::<Vec<_>>();
removed_excerpt_ids.sort_by({
let multibuffer = multibuffer.read(cx);
move |a, b| a.cmp(&b, &multibuffer)
});
let mut insertions = message.inserted_excerpts.into_iter().peekable();
while let Some(insertion) = insertions.next() {
let Some(excerpt) = insertion.excerpt else {
continue;
};
let Some(previous_excerpt_id) = insertion.previous_excerpt_id else {
continue;
};
let buffer_id = excerpt.buffer_id;
let Some(buffer) = project.read(cx).buffer_for_id(buffer_id) else {
continue;
};
let adjacent_excerpts = iter::from_fn(|| {
let insertion = insertions.peek()?;
if insertion.previous_excerpt_id.is_none()
&& insertion.excerpt.as_ref()?.buffer_id == buffer_id
{
insertions.next()?.excerpt
} else {
None
} }
// Previous implementation of the above });
// // Open all of the buffers of which excerpts were added to the editor.
// let inserted_excerpt_buffer_ids = message
// .inserted_excerpts
// .iter()
// .filter_map(|insertion| Some(insertion.excerpt.as_ref()?.buffer_id))
// .collect::<HashSet<_>>();
// let inserted_excerpt_buffers = project.update(cx, |project, cx| {
// inserted_excerpt_buffer_ids
// .into_iter()
// .map(|id| project.open_buffer_by_id(id, cx))
// .collect::<Vec<_>>()
// })?;
// let _inserted_excerpt_buffers = try_join_all(inserted_excerpt_buffers).await?;
// // Update the editor's excerpts. multibuffer.insert_excerpts_with_ids_after(
// this.update(cx, |editor, cx| { ExcerptId::from_proto(previous_excerpt_id),
// editor.buffer.update(cx, |multibuffer, cx| { buffer,
// let mut removed_excerpt_ids = message [excerpt]
// .deleted_excerpts .into_iter()
// .into_iter() .chain(adjacent_excerpts)
// .map(ExcerptId::from_proto) .filter_map(|excerpt| {
// .collect::<Vec<_>>(); Some((
// removed_excerpt_ids.sort_by({ ExcerptId::from_proto(excerpt.id),
// let multibuffer = multibuffer.read(cx); deserialize_excerpt_range(excerpt)?,
// move |a, b| a.cmp(&b, &multibuffer) ))
// }); }),
cx,
);
}
// let mut insertions = message.inserted_excerpts.into_iter().peekable(); multibuffer.remove_excerpts(removed_excerpt_ids, cx);
// while let Some(insertion) = insertions.next() { });
// let Some(excerpt) = insertion.excerpt else { })?;
// continue;
// };
// let Some(previous_excerpt_id) = insertion.previous_excerpt_id else {
// continue;
// };
// let buffer_id = excerpt.buffer_id;
// let Some(buffer) = project.read(cx).buffer_for_id(buffer_id) else {
// continue;
// };
// let adjacent_excerpts = iter::from_fn(|| { // Deserialize the editor state.
// let insertion = insertions.peek()?; let (selections, pending_selection, scroll_top_anchor) = this.update(cx, |editor, cx| {
// if insertion.previous_excerpt_id.is_none() let buffer = editor.buffer.read(cx).read(cx);
// && insertion.excerpt.as_ref()?.buffer_id == buffer_id let selections = message
// { .selections
// insertions.next()?.excerpt .into_iter()
// } else { .filter_map(|selection| deserialize_selection(&buffer, selection))
// None .collect::<Vec<_>>();
// } let pending_selection = message
// }); .pending_selection
.and_then(|selection| deserialize_selection(&buffer, selection));
let scroll_top_anchor = message
.scroll_top_anchor
.and_then(|anchor| deserialize_anchor(&buffer, anchor));
anyhow::Ok((selections, pending_selection, scroll_top_anchor))
})??;
// multibuffer.insert_excerpts_with_ids_after( // Wait until the buffer has received all of the operations referenced by
// ExcerptId::from_proto(previous_excerpt_id), // the editor's new state.
// buffer, this.update(cx, |editor, cx| {
// [excerpt] editor.buffer.update(cx, |buffer, cx| {
// .into_iter() buffer.wait_for_anchors(
// .chain(adjacent_excerpts) selections
// .filter_map(|excerpt| { .iter()
// Some(( .chain(pending_selection.as_ref())
// ExcerptId::from_proto(excerpt.id), .flat_map(|selection| [selection.start, selection.end])
// deserialize_excerpt_range(excerpt)?, .chain(scroll_top_anchor),
// )) cx,
// }), )
// cx, })
// ); })?
// } .await?;
// multibuffer.remove_excerpts(removed_excerpt_ids, cx); // Update the editor's state.
// }); this.update(cx, |editor, cx| {
// })?; if !selections.is_empty() || pending_selection.is_some() {
editor.set_selections_from_remote(selections, pending_selection, cx);
// // Deserialize the editor state. editor.request_autoscroll_remotely(Autoscroll::newest(), cx);
// let (selections, pending_selection, scroll_top_anchor) = this.update(cx, |editor, cx| { } else if let Some(scroll_top_anchor) = scroll_top_anchor {
// let buffer = editor.buffer.read(cx).read(cx); editor.set_scroll_anchor_remote(
// let selections = message ScrollAnchor {
// .selections anchor: scroll_top_anchor,
// .into_iter() offset: point(message.scroll_x, message.scroll_y),
// .filter_map(|selection| deserialize_selection(&buffer, selection)) },
// .collect::<Vec<_>>(); cx,
// let pending_selection = message );
// .pending_selection }
// .and_then(|selection| deserialize_selection(&buffer, selection)); })?;
// let scroll_top_anchor = message Ok(())
// .scroll_top_anchor }
// .and_then(|anchor| deserialize_anchor(&buffer, anchor));
// anyhow::Ok((selections, pending_selection, scroll_top_anchor))
// })??;
// // Wait until the buffer has received all of the operations referenced by
// // the editor's new state.
// this.update(cx, |editor, cx| {
// editor.buffer.update(cx, |buffer, cx| {
// buffer.wait_for_anchors(
// selections
// .iter()
// .chain(pending_selection.as_ref())
// .flat_map(|selection| [selection.start, selection.end])
// .chain(scroll_top_anchor),
// cx,
// )
// })
// })?
// .await?;
// // Update the editor's state.
// this.update(cx, |editor, cx| {
// if !selections.is_empty() || pending_selection.is_some() {
// editor.set_selections_from_remote(selections, pending_selection, cx);
// editor.request_autoscroll_remotely(Autoscroll::newest(), cx);
// } else if let Some(scroll_top_anchor) = scroll_top_anchor {
// editor.set_scroll_anchor_remote(
// ScrollAnchor {
// anchor: scroll_top_anchor,
// offset: point(message.scroll_x, message.scroll_y),
// },
// cx,
// );
// }
// })?;
// Ok(())
// }
fn serialize_excerpt( fn serialize_excerpt(
buffer_id: u64, buffer_id: u64,
@ -529,39 +529,38 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor)
impl Item for Editor { impl Item for Editor {
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool { fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
todo!(); if let Ok(data) = data.downcast::<NavigationData>() {
// if let Ok(data) = data.downcast::<NavigationData>() { let newest_selection = self.selections.newest::<Point>(cx);
// let newest_selection = self.selections.newest::<Point>(cx); let buffer = self.buffer.read(cx).read(cx);
// let buffer = self.buffer.read(cx).read(cx); let offset = if buffer.can_resolve(&data.cursor_anchor) {
// let offset = if buffer.can_resolve(&data.cursor_anchor) { data.cursor_anchor.to_point(&buffer)
// data.cursor_anchor.to_point(&buffer) } else {
// } else { buffer.clip_point(data.cursor_position, Bias::Left)
// buffer.clip_point(data.cursor_position, Bias::Left) };
// };
// let mut scroll_anchor = data.scroll_anchor; let mut scroll_anchor = data.scroll_anchor;
// if !buffer.can_resolve(&scroll_anchor.anchor) { if !buffer.can_resolve(&scroll_anchor.anchor) {
// scroll_anchor.anchor = buffer.anchor_before( scroll_anchor.anchor = buffer.anchor_before(
// buffer.clip_point(Point::new(data.scroll_top_row, 0), Bias::Left), buffer.clip_point(Point::new(data.scroll_top_row, 0), Bias::Left),
// ); );
// } }
// drop(buffer); drop(buffer);
// if newest_selection.head() == offset { if newest_selection.head() == offset {
// false false
// } else { } else {
// let nav_history = self.nav_history.take(); let nav_history = self.nav_history.take();
// self.set_scroll_anchor(scroll_anchor, cx); self.set_scroll_anchor(scroll_anchor, cx);
// self.change_selections(Some(Autoscroll::fit()), cx, |s| { self.change_selections(Some(Autoscroll::fit()), cx, |s| {
// s.select_ranges([offset..offset]) s.select_ranges([offset..offset])
// }); });
// self.nav_history = nav_history; self.nav_history = nav_history;
// true true
// } }
// } else { } else {
// false false
// } }
} }
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> { fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
@ -765,35 +764,34 @@ impl Item for Editor {
} }
fn breadcrumbs(&self, variant: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> { fn breadcrumbs(&self, variant: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {
todo!(); let cursor = self.selections.newest_anchor().head();
// let cursor = self.selections.newest_anchor().head(); let multibuffer = &self.buffer().read(cx);
// let multibuffer = &self.buffer().read(cx); let (buffer_id, symbols) =
// let (buffer_id, symbols) = multibuffer.symbols_containing(cursor, Some(&variant.syntax()), cx)?;
// multibuffer.symbols_containing(cursor, Some(&theme.editor.syntax), cx)?; let buffer = multibuffer.buffer(buffer_id)?;
// let buffer = multibuffer.buffer(buffer_id)?;
// let buffer = buffer.read(cx); let buffer = buffer.read(cx);
// let filename = buffer let filename = buffer
// .snapshot() .snapshot()
// .resolve_file_path( .resolve_file_path(
// cx, cx,
// self.project self.project
// .as_ref() .as_ref()
// .map(|project| project.read(cx).visible_worktrees(cx).count() > 1) .map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
// .unwrap_or_default(), .unwrap_or_default(),
// ) )
// .map(|path| path.to_string_lossy().to_string()) .map(|path| path.to_string_lossy().to_string())
// .unwrap_or_else(|| "untitled".to_string()); .unwrap_or_else(|| "untitled".to_string());
// let mut breadcrumbs = vec![BreadcrumbText { let mut breadcrumbs = vec![BreadcrumbText {
// text: filename, text: filename,
// highlights: None, highlights: None,
// }]; }];
// breadcrumbs.extend(symbols.into_iter().map(|symbol| BreadcrumbText { breadcrumbs.extend(symbols.into_iter().map(|symbol| BreadcrumbText {
// text: symbol.text, text: symbol.text,
// highlights: Some(symbol.highlight_ranges), highlights: Some(symbol.highlight_ranges),
// })); }));
// Some(breadcrumbs) Some(breadcrumbs)
} }
fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) { fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
@ -1120,86 +1118,78 @@ pub struct CursorPosition {
_observe_active_editor: Option<Subscription>, _observe_active_editor: Option<Subscription>,
} }
// impl Default for CursorPosition { impl Default for CursorPosition {
// fn default() -> Self { fn default() -> Self {
// Self::new() Self::new()
// } }
// } }
// impl CursorPosition { impl CursorPosition {
// pub fn new() -> Self { pub fn new() -> Self {
// Self { Self {
// position: None, position: None,
// selected_count: 0, selected_count: 0,
// _observe_active_editor: None, _observe_active_editor: None,
// } }
// } }
// fn update_position(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) { fn update_position(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
// let editor = editor.read(cx); let editor = editor.read(cx);
// let buffer = editor.buffer().read(cx).snapshot(cx); let buffer = editor.buffer().read(cx).snapshot(cx);
// self.selected_count = 0; self.selected_count = 0;
// let mut last_selection: Option<Selection<usize>> = None; let mut last_selection: Option<Selection<usize>> = None;
// for selection in editor.selections.all::<usize>(cx) { for selection in editor.selections.all::<usize>(cx) {
// self.selected_count += selection.end - selection.start; self.selected_count += selection.end - selection.start;
// if last_selection if last_selection
// .as_ref() .as_ref()
// .map_or(true, |last_selection| selection.id > last_selection.id) .map_or(true, |last_selection| selection.id > last_selection.id)
// { {
// last_selection = Some(selection); last_selection = Some(selection);
// } }
// } }
// self.position = last_selection.map(|s| s.head().to_point(&buffer)); self.position = last_selection.map(|s| s.head().to_point(&buffer));
// cx.notify(); cx.notify();
// } }
// } }
// impl Entity for CursorPosition { impl Render for CursorPosition {
// type Event = (); type Element = Div;
// }
// impl View for CursorPosition { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
// fn ui_name() -> &'static str { div().when_some(self.position, |el, position| {
// "CursorPosition" let mut text = format!(
// } "{}{FILE_ROW_COLUMN_DELIMITER}{}",
position.row + 1,
position.column + 1
);
if self.selected_count > 0 {
write!(text, " ({} selected)", self.selected_count).unwrap();
}
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { el.child(Label::new(text))
// if let Some(position) = self.position { })
// let theme = &theme::current(cx).workspace.status_bar; }
// let mut text = format!( }
// "{}{FILE_ROW_COLUMN_DELIMITER}{}",
// position.row + 1,
// position.column + 1
// );
// if self.selected_count > 0 {
// write!(text, " ({} selected)", self.selected_count).unwrap();
// }
// Label::new(text, theme.cursor_position.clone()).into_any()
// } else {
// Empty::new().into_any()
// }
// }
// }
// impl StatusItemView for CursorPosition { impl StatusItemView for CursorPosition {
// fn set_active_pane_item( fn set_active_pane_item(
// &mut self, &mut self,
// active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) { ) {
// if let Some(editor) = active_pane_item.and_then(|item| item.act_as::<Editor>(cx)) { if let Some(editor) = active_pane_item.and_then(|item| item.act_as::<Editor>(cx)) {
// self._observe_active_editor = Some(cx.observe(&editor, Self::update_position)); self._observe_active_editor = Some(cx.observe(&editor, Self::update_position));
// self.update_position(editor, cx); self.update_position(editor, cx);
// } else { } else {
// self.position = None; self.position = None;
// self._observe_active_editor = None; self._observe_active_editor = None;
// } }
// cx.notify(); cx.notify();
// } }
// } }
fn path_for_buffer<'a>( fn path_for_buffer<'a>(
buffer: &Model<MultiBuffer>, buffer: &Model<MultiBuffer>,

View file

@ -1,5 +1,14 @@
use crate::{DisplayPoint, Editor, EditorMode, SelectMode}; use crate::{
use gpui::{Pixels, Point, ViewContext}; DisplayPoint, Editor, EditorMode, FindAllReferences, GoToDefinition, GoToTypeDefinition,
Rename, RevealInFinder, SelectMode, ToggleCodeActions,
};
use gpui::{DismissEvent, Pixels, Point, Subscription, View, ViewContext};
pub struct MouseContextMenu {
pub(crate) position: Point<Pixels>,
pub(crate) context_menu: View<ui::ContextMenu>,
_subscription: Subscription,
}
pub fn deploy_context_menu( pub fn deploy_context_menu(
editor: &mut Editor, editor: &mut Editor,
@ -7,50 +16,57 @@ pub fn deploy_context_menu(
point: DisplayPoint, point: DisplayPoint,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) { ) {
todo!(); if !editor.is_focused(cx) {
editor.focus(cx);
}
// if !editor.focused { // Don't show context menu for inline editors
// cx.focus_self(); if editor.mode() != EditorMode::Full {
// } return;
}
// // Don't show context menu for inline editors // Don't show the context menu if there isn't a project associated with this editor
// if editor.mode() != EditorMode::Full { if editor.project.is_none() {
// return; return;
// } }
// // Don't show the context menu if there isn't a project associated with this editor // Move the cursor to the clicked location so that dispatched actions make sense
// if editor.project.is_none() { editor.change_selections(None, cx, |s| {
// return; s.clear_disjoint();
// } s.set_pending_display_range(point..point, SelectMode::Character);
});
// // Move the cursor to the clicked location so that dispatched actions make sense let context_menu = ui::ContextMenu::build(cx, |menu, cx| {
// editor.change_selections(None, cx, |s| { menu.action("Rename Symbol", Box::new(Rename), cx)
// s.clear_disjoint(); .action("Go to Definition", Box::new(GoToDefinition), cx)
// s.set_pending_display_range(point..point, SelectMode::Character); .action("Go to Type Definition", Box::new(GoToTypeDefinition), cx)
// }); .action("Find All References", Box::new(FindAllReferences), cx)
.action(
"Code Actions",
Box::new(ToggleCodeActions {
deployed_from_indicator: false,
}),
cx,
)
.separator()
.action("Reveal in Finder", Box::new(RevealInFinder), cx)
});
let context_menu_focus = context_menu.focus_handle(cx);
cx.focus(&context_menu_focus);
// editor.mouse_context_menu.update(cx, |menu, cx| { let _subscription = cx.subscribe(&context_menu, move |this, _, event: &DismissEvent, cx| {
// menu.show( this.mouse_context_menu.take();
// position, if context_menu_focus.contains_focused(cx) {
// AnchorCorner::TopLeft, this.focus(cx);
// vec![ }
// ContextMenuItem::action("Rename Symbol", Rename), });
// ContextMenuItem::action("Go to Definition", GoToDefinition),
// ContextMenuItem::action("Go to Type Definition", GoToTypeDefinition), editor.mouse_context_menu = Some(MouseContextMenu {
// ContextMenuItem::action("Find All References", FindAllReferences), position,
// ContextMenuItem::action( context_menu,
// "Code Actions", _subscription,
// ToggleCodeActions { });
// deployed_from_indicator: false, cx.notify();
// },
// ),
// ContextMenuItem::Separator,
// ContextMenuItem::action("Reveal in Finder", RevealInFinder),
// ],
// cx,
// );
// });
// cx.notify();
} }
// #[cfg(test)] // #[cfg(test)]

View file

@ -315,14 +315,11 @@ impl SelectionsCollection {
let line = display_map.layout_row(row, &text_layout_details); let line = display_map.layout_row(row, &text_layout_details);
dbg!("****START COL****");
let start_col = line.closest_index_for_x(positions.start) as u32; let start_col = line.closest_index_for_x(positions.start) as u32;
if start_col < line_len || (is_empty && positions.start == line.width) { if start_col < line_len || (is_empty && positions.start == line.width) {
let start = DisplayPoint::new(row, start_col); let start = DisplayPoint::new(row, start_col);
dbg!("****END COL****");
let end_col = line.closest_index_for_x(positions.end) as u32; let end_col = line.closest_index_for_x(positions.end) as u32;
let end = DisplayPoint::new(row, end_col); let end = DisplayPoint::new(row, end_col);
dbg!(start_col, end_col);
Some(Selection { Some(Selection {
id: post_inc(&mut self.next_selection_id), id: post_inc(&mut self.next_selection_id),

View file

@ -27,7 +27,7 @@ pub fn marked_display_snapshot(
let (unmarked_text, markers) = marked_text_offsets(text); let (unmarked_text, markers) = marked_text_offsets(text);
let font = cx.text_style().font(); let font = cx.text_style().font();
let font_size: Pixels = 14.into(); let font_size: Pixels = 14usize.into();
let buffer = MultiBuffer::build_simple(&unmarked_text, cx); let buffer = MultiBuffer::build_simple(&unmarked_text, cx);
let display_map = cx.build_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx)); let display_map = cx.build_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx));

View file

@ -518,6 +518,7 @@ impl PickerDelegate for FileFinderDelegate {
} }
fn update_matches(&mut self, raw_query: String, cx: &mut ViewContext<FileFinder>) -> Task<()> { fn update_matches(&mut self, raw_query: String, cx: &mut ViewContext<FileFinder>) -> Task<()> {
let raw_query = raw_query.trim();
if raw_query.is_empty() { if raw_query.is_empty() {
let project = self.project.read(cx); let project = self.project.read(cx);
self.latest_search_id = post_inc(&mut self.search_count); self.latest_search_id = post_inc(&mut self.search_count);
@ -539,7 +540,6 @@ impl PickerDelegate for FileFinderDelegate {
cx.notify(); cx.notify();
Task::ready(()) Task::ready(())
} else { } else {
let raw_query = &raw_query;
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| { let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
Ok::<_, std::convert::Infallible>(FileSearchQuery { Ok::<_, std::convert::Infallible>(FileSearchQuery {
raw_query: raw_query.to_owned(), raw_query: raw_query.to_owned(),
@ -735,6 +735,7 @@ mod tests {
cx.dispatch_action(window.into(), Toggle); cx.dispatch_action(window.into(), Toggle);
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap()); let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
finder finder
.update(cx, |finder, cx| { .update(cx, |finder, cx| {
finder.delegate_mut().update_matches("bna".to_string(), cx) finder.delegate_mut().update_matches("bna".to_string(), cx)
@ -743,7 +744,6 @@ mod tests {
finder.read_with(cx, |finder, _| { finder.read_with(cx, |finder, _| {
assert_eq!(finder.delegate().matches.len(), 2); assert_eq!(finder.delegate().matches.len(), 2);
}); });
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone()); let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
cx.dispatch_action(window.into(), SelectNext); cx.dispatch_action(window.into(), SelectNext);
cx.dispatch_action(window.into(), Confirm); cx.dispatch_action(window.into(), Confirm);
@ -762,6 +762,49 @@ mod tests {
"bandana" "bandana"
); );
}); });
for bandana_query in [
"bandana",
" bandana",
"bandana ",
" bandana ",
" ndan ",
" band ",
] {
finder
.update(cx, |finder, cx| {
finder
.delegate_mut()
.update_matches(bandana_query.to_string(), cx)
})
.await;
finder.read_with(cx, |finder, _| {
assert_eq!(
finder.delegate().matches.len(),
1,
"Wrong number of matches for bandana query '{bandana_query}'"
);
});
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
cx.dispatch_action(window.into(), SelectNext);
cx.dispatch_action(window.into(), Confirm);
active_pane
.condition(cx, |pane, _| pane.active_item().is_some())
.await;
cx.read(|cx| {
let active_item = active_pane.read(cx).active_item().unwrap();
assert_eq!(
active_item
.as_any()
.downcast_ref::<Editor>()
.unwrap()
.read(cx)
.title(cx),
"bandana",
"Wrong match for bandana query '{bandana_query}'"
);
});
}
} }
#[gpui::test] #[gpui::test]

View file

@ -15,7 +15,7 @@ use std::{
}, },
}; };
use text::Point; use text::Point;
use ui::{v_stack, HighlightedLabel, ListItem}; use ui::{prelude::*, v_stack, HighlightedLabel, ListItem};
use util::{paths::PathLikeWithPosition, post_inc, ResultExt}; use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
use workspace::Workspace; use workspace::Workspace;
@ -552,6 +552,7 @@ impl PickerDelegate for FileFinderDelegate {
raw_query: String, raw_query: String,
cx: &mut ViewContext<Picker<Self>>, cx: &mut ViewContext<Picker<Self>>,
) -> Task<()> { ) -> Task<()> {
let raw_query = raw_query.trim();
if raw_query.is_empty() { if raw_query.is_empty() {
let project = self.project.read(cx); let project = self.project.read(cx);
self.latest_search_id = post_inc(&mut self.search_count); self.latest_search_id = post_inc(&mut self.search_count);
@ -573,7 +574,6 @@ impl PickerDelegate for FileFinderDelegate {
cx.notify(); cx.notify();
Task::ready(()) Task::ready(())
} else { } else {
let raw_query = &raw_query;
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| { let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
Ok::<_, std::convert::Infallible>(FileSearchQuery { Ok::<_, std::convert::Infallible>(FileSearchQuery {
raw_query: raw_query.to_owned(), raw_query: raw_query.to_owned(),
@ -766,18 +766,49 @@ mod tests {
let (picker, workspace, cx) = build_find_picker(project, cx); let (picker, workspace, cx) = build_find_picker(project, cx);
cx.simulate_input("bna"); cx.simulate_input("bna");
picker.update(cx, |picker, _| { picker.update(cx, |picker, _| {
assert_eq!(picker.delegate.matches.len(), 2); assert_eq!(picker.delegate.matches.len(), 2);
}); });
cx.dispatch_action(SelectNext); cx.dispatch_action(SelectNext);
cx.dispatch_action(Confirm); cx.dispatch_action(Confirm);
cx.read(|cx| { cx.read(|cx| {
let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap(); let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
assert_eq!(active_editor.read(cx).title(cx), "bandana"); assert_eq!(active_editor.read(cx).title(cx), "bandana");
}); });
for bandana_query in [
"bandana",
" bandana",
"bandana ",
" bandana ",
" ndan ",
" band ",
] {
picker
.update(cx, |picker, cx| {
picker
.delegate
.update_matches(bandana_query.to_string(), cx)
})
.await;
picker.update(cx, |picker, _| {
assert_eq!(
picker.delegate.matches.len(),
1,
"Wrong number of matches for bandana query '{bandana_query}'"
);
});
cx.dispatch_action(SelectNext);
cx.dispatch_action(Confirm);
cx.read(|cx| {
let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
assert_eq!(
active_editor.read(cx).title(cx),
"bandana",
"Wrong match for bandana query '{bandana_query}'"
);
});
}
} }
#[gpui::test] #[gpui::test]
@ -1225,7 +1256,7 @@ mod tests {
// //
// TODO: without closing, the opened items do not propagate their history changes for some reason // TODO: without closing, the opened items do not propagate their history changes for some reason
// it does work in real app though, only tests do not propagate. // it does work in real app though, only tests do not propagate.
workspace.update(cx, |_, cx| dbg!(cx.focused())); workspace.update(cx, |_, cx| cx.focused());
let initial_history = open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await; let initial_history = open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
assert!( assert!(

View file

@ -65,6 +65,8 @@ fn generate_shader_bindings() -> PathBuf {
"MonochromeSprite".into(), "MonochromeSprite".into(),
"PolychromeSprite".into(), "PolychromeSprite".into(),
"PathSprite".into(), "PathSprite".into(),
"SurfaceInputIndex".into(),
"SurfaceBounds".into(),
]); ]);
config.no_includes = true; config.no_includes = true;
config.enumeration.prefix_with_name = true; config.enumeration.prefix_with_name = true;

View file

@ -2,8 +2,8 @@ use crate::{
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext, div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
BackgroundExecutor, Context, Div, Entity, EventEmitter, ForegroundExecutor, InputEvent, BackgroundExecutor, Context, Div, Entity, EventEmitter, ForegroundExecutor, InputEvent,
KeyDownEvent, Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher, KeyDownEvent, Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher,
TestPlatform, TestWindow, View, ViewContext, VisualContext, WindowContext, WindowHandle, TestPlatform, TestWindow, TestWindowHandlers, View, ViewContext, VisualContext, WindowContext,
WindowOptions, WindowHandle, WindowOptions,
}; };
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
@ -502,6 +502,19 @@ impl<'a> VisualTestContext<'a> {
self.cx.dispatch_action(self.window, action) self.cx.dispatch_action(self.window, action)
} }
pub fn window_title(&mut self) -> Option<String> {
self.cx
.update_window(self.window, |_, cx| {
cx.window
.platform_window
.as_test()
.unwrap()
.window_title
.clone()
})
.unwrap()
}
pub fn simulate_keystrokes(&mut self, keystrokes: &str) { pub fn simulate_keystrokes(&mut self, keystrokes: &str) {
self.cx.simulate_keystrokes(self.window, keystrokes) self.cx.simulate_keystrokes(self.window, keystrokes)
} }
@ -509,6 +522,39 @@ impl<'a> VisualTestContext<'a> {
pub fn simulate_input(&mut self, input: &str) { pub fn simulate_input(&mut self, input: &str) {
self.cx.simulate_input(self.window, input) self.cx.simulate_input(self.window, input)
} }
pub fn simulate_activation(&mut self) {
self.simulate_window_events(&mut |handlers| {
handlers
.active_status_change
.iter_mut()
.for_each(|f| f(true));
})
}
pub fn simulate_deactivation(&mut self) {
self.simulate_window_events(&mut |handlers| {
handlers
.active_status_change
.iter_mut()
.for_each(|f| f(false));
})
}
fn simulate_window_events(&mut self, f: &mut dyn FnMut(&mut TestWindowHandlers)) {
let handlers = self
.cx
.update_window(self.window, |_, cx| {
cx.window
.platform_window
.as_test()
.unwrap()
.handlers
.clone()
})
.unwrap();
f(&mut *handlers.lock());
}
} }
impl<'a> Context for VisualTestContext<'a> { impl<'a> Context for VisualTestContext<'a> {

View file

@ -12,6 +12,7 @@ use smallvec::SmallVec;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
cell::RefCell, cell::RefCell,
cmp::Ordering,
fmt::Debug, fmt::Debug,
mem, mem,
rc::Rc, rc::Rc,
@ -357,6 +358,11 @@ pub trait StatefulInteractiveElement: InteractiveElement {
self self
} }
fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self {
self.interactivity().scroll_handle = Some(scroll_handle.clone());
self
}
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where where
Self: Sized, Self: Sized,
@ -626,6 +632,26 @@ impl Element for Div {
let mut child_max = Point::default(); let mut child_max = Point::default();
let content_size = if element_state.child_layout_ids.is_empty() { let content_size = if element_state.child_layout_ids.is_empty() {
bounds.size bounds.size
} else if let Some(scroll_handle) = self.interactivity.scroll_handle.as_ref() {
let mut state = scroll_handle.0.borrow_mut();
state.child_bounds = Vec::with_capacity(element_state.child_layout_ids.len());
state.bounds = bounds;
let requested = state.requested_scroll_top.take();
for (ix, child_layout_id) in element_state.child_layout_ids.iter().enumerate() {
let child_bounds = cx.layout_bounds(*child_layout_id);
child_min = child_min.min(&child_bounds.origin);
child_max = child_max.max(&child_bounds.lower_right());
state.child_bounds.push(child_bounds);
if let Some(requested) = requested.as_ref() {
if requested.0 == ix {
*state.offset.borrow_mut() =
bounds.origin - (child_bounds.origin - point(px(0.), requested.1));
}
}
}
(child_max - child_min).into()
} else { } else {
for child_layout_id in &element_state.child_layout_ids { for child_layout_id in &element_state.child_layout_ids {
let child_bounds = cx.layout_bounds(*child_layout_id); let child_bounds = cx.layout_bounds(*child_layout_id);
@ -696,6 +722,7 @@ pub struct Interactivity {
pub key_context: KeyContext, pub key_context: KeyContext,
pub focusable: bool, pub focusable: bool,
pub tracked_focus_handle: Option<FocusHandle>, pub tracked_focus_handle: Option<FocusHandle>,
pub scroll_handle: Option<ScrollHandle>,
pub focus_listeners: FocusListeners, pub focus_listeners: FocusListeners,
pub group: Option<SharedString>, pub group: Option<SharedString>,
pub base_style: StyleRefinement, pub base_style: StyleRefinement,
@ -754,6 +781,10 @@ impl Interactivity {
}); });
} }
if let Some(scroll_handle) = self.scroll_handle.as_ref() {
element_state.scroll_offset = Some(scroll_handle.0.borrow().offset.clone());
}
let style = self.compute_style(None, &mut element_state, cx); let style = self.compute_style(None, &mut element_state, cx);
let layout_id = f(style, cx); let layout_id = f(style, cx);
(layout_id, element_state) (layout_id, element_state)
@ -1206,6 +1237,7 @@ impl Default for Interactivity {
key_context: KeyContext::default(), key_context: KeyContext::default(),
focusable: false, focusable: false,
tracked_focus_handle: None, tracked_focus_handle: None,
scroll_handle: None,
focus_listeners: SmallVec::default(), focus_listeners: SmallVec::default(),
// scroll_offset: Point::default(), // scroll_offset: Point::default(),
group: None, group: None,
@ -1429,3 +1461,83 @@ where
self.element.children_mut() self.element.children_mut()
} }
} }
#[derive(Default)]
struct ScrollHandleState {
// not great to have the nested rc's...
offset: Rc<RefCell<Point<Pixels>>>,
bounds: Bounds<Pixels>,
child_bounds: Vec<Bounds<Pixels>>,
requested_scroll_top: Option<(usize, Pixels)>,
}
#[derive(Clone)]
pub struct ScrollHandle(Rc<RefCell<ScrollHandleState>>);
impl ScrollHandle {
pub fn new() -> Self {
Self(Rc::default())
}
pub fn offset(&self) -> Point<Pixels> {
self.0.borrow().offset.borrow().clone()
}
pub fn top_item(&self) -> usize {
let state = self.0.borrow();
let top = state.bounds.top() - state.offset.borrow().y;
match state.child_bounds.binary_search_by(|bounds| {
if top < bounds.top() {
Ordering::Greater
} else if top > bounds.bottom() {
Ordering::Less
} else {
Ordering::Equal
}
}) {
Ok(ix) => ix,
Err(ix) => ix.min(state.child_bounds.len().saturating_sub(1)),
}
}
pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>> {
self.0.borrow().child_bounds.get(ix).cloned()
}
/// scroll_to_item scrolls the minimal amount to ensure that the item is
/// fully visible
pub fn scroll_to_item(&self, ix: usize) {
let state = self.0.borrow();
let Some(bounds) = state.child_bounds.get(ix) else {
return;
};
let scroll_offset = state.offset.borrow().y;
if bounds.top() + scroll_offset < state.bounds.top() {
state.offset.borrow_mut().y = state.bounds.top() - bounds.top();
} else if bounds.bottom() + scroll_offset > state.bounds.bottom() {
state.offset.borrow_mut().y = state.bounds.bottom() - bounds.bottom();
}
}
pub fn logical_scroll_top(&self) -> (usize, Pixels) {
let ix = self.top_item();
let state = self.0.borrow();
if let Some(child_bounds) = state.child_bounds.get(ix) {
(
ix,
child_bounds.top() + state.offset.borrow().y - state.bounds.top(),
)
} else {
(ix, px(0.))
}
}
pub fn set_logical_scroll_top(&self, ix: usize, px: Pixels) {
self.0.borrow_mut().requested_scroll_top = Some((ix, px));
}
}

View file

@ -1,10 +1,12 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{ use crate::{
Bounds, Element, ImageData, InteractiveElement, InteractiveElementState, Interactivity, point, size, Bounds, DevicePixels, Element, ImageData, InteractiveElement,
IntoElement, LayoutId, Pixels, SharedString, StyleRefinement, Styled, WindowContext, InteractiveElementState, Interactivity, IntoElement, LayoutId, Pixels, SharedString, Size,
StyleRefinement, Styled, WindowContext,
}; };
use futures::FutureExt; use futures::FutureExt;
use media::core_video::CVImageBuffer;
use util::ResultExt; use util::ResultExt;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -12,6 +14,7 @@ pub enum ImageSource {
/// Image content will be loaded from provided URI at render time. /// Image content will be loaded from provided URI at render time.
Uri(SharedString), Uri(SharedString),
Data(Arc<ImageData>), Data(Arc<ImageData>),
Surface(CVImageBuffer),
} }
impl From<SharedString> for ImageSource { impl From<SharedString> for ImageSource {
@ -20,40 +23,45 @@ impl From<SharedString> for ImageSource {
} }
} }
impl From<&'static str> for ImageSource {
fn from(uri: &'static str) -> Self {
Self::Uri(uri.into())
}
}
impl From<String> for ImageSource {
fn from(uri: String) -> Self {
Self::Uri(uri.into())
}
}
impl From<Arc<ImageData>> for ImageSource { impl From<Arc<ImageData>> for ImageSource {
fn from(value: Arc<ImageData>) -> Self { fn from(value: Arc<ImageData>) -> Self {
Self::Data(value) Self::Data(value)
} }
} }
impl From<CVImageBuffer> for ImageSource {
fn from(value: CVImageBuffer) -> Self {
Self::Surface(value)
}
}
pub struct Img { pub struct Img {
interactivity: Interactivity, interactivity: Interactivity,
source: Option<ImageSource>, source: ImageSource,
grayscale: bool, grayscale: bool,
} }
pub fn img() -> Img { pub fn img(source: impl Into<ImageSource>) -> Img {
Img { Img {
interactivity: Interactivity::default(), interactivity: Interactivity::default(),
source: None, source: source.into(),
grayscale: false, grayscale: false,
} }
} }
impl Img { impl Img {
pub fn uri(mut self, uri: impl Into<SharedString>) -> Self {
self.source = Some(ImageSource::from(uri.into()));
self
}
pub fn data(mut self, data: Arc<ImageData>) -> Self {
self.source = Some(ImageSource::from(data));
self
}
pub fn source(mut self, source: impl Into<ImageSource>) -> Self {
self.source = Some(source.into());
self
}
pub fn grayscale(mut self, grayscale: bool) -> Self { pub fn grayscale(mut self, grayscale: bool) -> Self {
self.grayscale = grayscale; self.grayscale = grayscale;
self self
@ -68,9 +76,8 @@ impl Element for Img {
element_state: Option<Self::State>, element_state: Option<Self::State>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
self.interactivity.layout(element_state, cx, |style, cx| { self.interactivity
cx.request_layout(&style, None) .layout(element_state, cx, |style, cx| cx.request_layout(&style, []))
})
} }
fn paint( fn paint(
@ -85,10 +92,9 @@ impl Element for Img {
element_state, element_state,
cx, cx,
|style, _scroll_offset, cx| { |style, _scroll_offset, cx| {
let corner_radii = style.corner_radii; let corner_radii = style.corner_radii.to_pixels(bounds.size, cx.rem_size());
cx.with_z_index(1, |cx| {
if let Some(source) = self.source { match self.source {
let image = match source {
ImageSource::Uri(uri) => { ImageSource::Uri(uri) => {
let image_future = cx.image_cache.get(uri.clone()); let image_future = cx.image_cache.get(uri.clone());
if let Some(data) = image_future if let Some(data) = image_future
@ -96,7 +102,9 @@ impl Element for Img {
.now_or_never() .now_or_never()
.and_then(|result| result.ok()) .and_then(|result| result.ok())
{ {
data let new_bounds = preserve_aspect_ratio(bounds, data.size());
cx.paint_image(new_bounds, corner_radii, data, self.grayscale)
.log_err();
} else { } else {
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
if image_future.await.ok().is_some() { if image_future.await.ok().is_some() {
@ -104,17 +112,23 @@ impl Element for Img {
} }
}) })
.detach(); .detach();
return;
} }
} }
ImageSource::Data(image) => image,
ImageSource::Data(data) => {
let new_bounds = preserve_aspect_ratio(bounds, data.size());
cx.paint_image(new_bounds, corner_radii, data, self.grayscale)
.log_err();
}
ImageSource::Surface(surface) => {
let size = size(surface.width().into(), surface.height().into());
let new_bounds = preserve_aspect_ratio(bounds, size);
// TODO: Add support for corner_radii and grayscale.
cx.paint_surface(new_bounds, surface);
}
}; };
let corner_radii = corner_radii.to_pixels(bounds.size, cx.rem_size());
cx.with_z_index(1, |cx| {
cx.paint_image(bounds, corner_radii, image, self.grayscale)
.log_err()
}); });
}
}, },
) )
} }
@ -143,3 +157,29 @@ impl InteractiveElement for Img {
&mut self.interactivity &mut self.interactivity
} }
} }
fn preserve_aspect_ratio(bounds: Bounds<Pixels>, image_size: Size<DevicePixels>) -> Bounds<Pixels> {
let image_size = image_size.map(|dimension| Pixels::from(u32::from(dimension)));
let image_ratio = image_size.width / image_size.height;
let bounds_ratio = bounds.size.width / bounds.size.height;
let new_size = if bounds_ratio > image_ratio {
size(
image_size.width * (bounds.size.height / image_size.height),
bounds.size.height,
)
} else {
size(
bounds.size.width,
image_size.height * (bounds.size.width / image_size.width),
)
};
Bounds {
origin: point(
bounds.origin.x + (bounds.size.width - new_size.width) / 2.0,
bounds.origin.y + (bounds.size.height - new_size.height) / 2.0,
),
size: new_size,
}
}

View file

@ -144,7 +144,6 @@ impl TextState {
runs: Option<Vec<TextRun>>, runs: Option<Vec<TextRun>>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> LayoutId { ) -> LayoutId {
let text_system = cx.text_system().clone();
let text_style = cx.text_style(); let text_style = cx.text_style();
let font_size = text_style.font_size.to_pixels(cx.rem_size()); let font_size = text_style.font_size.to_pixels(cx.rem_size());
let line_height = text_style let line_height = text_style
@ -152,18 +151,16 @@ impl TextState {
.to_pixels(font_size.into(), cx.rem_size()); .to_pixels(font_size.into(), cx.rem_size());
let text = SharedString::from(text); let text = SharedString::from(text);
let rem_size = cx.rem_size();
let runs = if let Some(runs) = runs { let runs = if let Some(runs) = runs {
runs runs
} else { } else {
vec![text_style.to_run(text.len())] vec![text_style.to_run(text.len())]
}; };
let layout_id = cx.request_measured_layout(Default::default(), rem_size, { let layout_id = cx.request_measured_layout(Default::default(), {
let element_state = self.clone(); let element_state = self.clone();
move |known_dimensions, available_space| { move |known_dimensions, available_space, cx| {
let wrap_width = if text_style.white_space == WhiteSpace::Normal { let wrap_width = if text_style.white_space == WhiteSpace::Normal {
known_dimensions.width.or(match available_space.width { known_dimensions.width.or(match available_space.width {
crate::AvailableSpace::Definite(x) => Some(x), crate::AvailableSpace::Definite(x) => Some(x),
@ -181,7 +178,8 @@ impl TextState {
} }
} }
let Some(lines) = text_system let Some(lines) = cx
.text_system()
.shape_text( .shape_text(
&text, font_size, &runs, wrap_width, // Wrap if we know the width. &text, font_size, &runs, wrap_width, // Wrap if we know the width.
) )

View file

@ -109,7 +109,6 @@ impl Element for UniformList {
cx: &mut WindowContext, cx: &mut WindowContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
let max_items = self.item_count; let max_items = self.item_count;
let rem_size = cx.rem_size();
let item_size = state let item_size = state
.as_ref() .as_ref()
.map(|s| s.item_size) .map(|s| s.item_size)
@ -120,9 +119,7 @@ impl Element for UniformList {
.layout(state.map(|s| s.interactive), cx, |style, cx| { .layout(state.map(|s| s.interactive), cx, |style, cx| {
cx.request_measured_layout( cx.request_measured_layout(
style, style,
rem_size, move |known_dimensions, available_space, _cx| {
move |known_dimensions: Size<Option<Pixels>>,
available_space: Size<AvailableSpace>| {
let desired_height = item_size.height * max_items; let desired_height = item_size.height * max_items;
let width = let width =
known_dimensions known_dimensions

View file

@ -655,6 +655,20 @@ pub struct Corners<T: Clone + Default + Debug> {
pub bottom_left: T, pub bottom_left: T,
} }
impl<T> Corners<T>
where
T: Clone + Default + Debug,
{
pub fn all(value: T) -> Self {
Self {
top_left: value.clone(),
top_right: value.clone(),
bottom_right: value.clone(),
bottom_left: value,
}
}
}
impl Corners<AbsoluteLength> { impl Corners<AbsoluteLength> {
pub fn to_pixels(&self, size: Size<Pixels>, rem_size: Pixels) -> Corners<Pixels> { pub fn to_pixels(&self, size: Size<Pixels>, rem_size: Pixels) -> Corners<Pixels> {
let max = size.width.max(size.height) / 2.; let max = size.width.max(size.height) / 2.;
@ -905,6 +919,12 @@ impl From<Pixels> for usize {
} }
} }
impl From<usize> for Pixels {
fn from(pixels: usize) -> Self {
Pixels(pixels as f32)
}
}
#[derive( #[derive(
Add, AddAssign, Clone, Copy, Default, Div, Eq, Hash, Ord, PartialEq, PartialOrd, Sub, SubAssign, Add, AddAssign, Clone, Copy, Default, Div, Eq, Hash, Ord, PartialEq, PartialOrd, Sub, SubAssign,
)] )]
@ -959,6 +979,18 @@ impl From<u64> for DevicePixels {
} }
} }
impl From<DevicePixels> for usize {
fn from(device_pixels: DevicePixels) -> Self {
device_pixels.0 as usize
}
}
impl From<usize> for DevicePixels {
fn from(device_pixels: usize) -> Self {
DevicePixels(device_pixels as i32)
}
}
#[derive(Clone, Copy, Default, Add, AddAssign, Sub, SubAssign, Div, PartialEq, PartialOrd)] #[derive(Clone, Copy, Default, Add, AddAssign, Sub, SubAssign, Div, PartialEq, PartialOrd)]
#[repr(transparent)] #[repr(transparent)]
pub struct ScaledPixels(pub(crate) f32); pub struct ScaledPixels(pub(crate) f32);

View file

@ -158,6 +158,11 @@ pub(crate) trait PlatformWindow {
fn draw(&self, scene: Scene); fn draw(&self, scene: Scene);
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>; fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
#[cfg(any(test, feature = "test-support"))]
fn as_test(&self) -> Option<&TestWindow> {
None
}
} }
pub trait PlatformDispatcher: Send + Sync { pub trait PlatformDispatcher: Send + Sync {

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
point, size, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, ContentMask, DevicePixels, point, size, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, ContentMask, DevicePixels,
Hsla, MetalAtlas, MonochromeSprite, Path, PathId, PathVertex, PolychromeSprite, PrimitiveBatch, Hsla, MetalAtlas, MonochromeSprite, Path, PathId, PathVertex, PolychromeSprite, PrimitiveBatch,
Quad, ScaledPixels, Scene, Shadow, Size, Underline, Quad, ScaledPixels, Scene, Shadow, Size, Surface, Underline,
}; };
use cocoa::{ use cocoa::{
base::{NO, YES}, base::{NO, YES},
@ -9,6 +9,9 @@ use cocoa::{
quartzcore::AutoresizingMask, quartzcore::AutoresizingMask,
}; };
use collections::HashMap; use collections::HashMap;
use core_foundation::base::TCFType;
use foreign_types::ForeignType;
use media::core_video::CVMetalTextureCache;
use metal::{CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange}; use metal::{CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange};
use objc::{self, msg_send, sel, sel_impl}; use objc::{self, msg_send, sel, sel_impl};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -27,9 +30,11 @@ pub(crate) struct MetalRenderer {
underlines_pipeline_state: metal::RenderPipelineState, underlines_pipeline_state: metal::RenderPipelineState,
monochrome_sprites_pipeline_state: metal::RenderPipelineState, monochrome_sprites_pipeline_state: metal::RenderPipelineState,
polychrome_sprites_pipeline_state: metal::RenderPipelineState, polychrome_sprites_pipeline_state: metal::RenderPipelineState,
surfaces_pipeline_state: metal::RenderPipelineState,
unit_vertices: metal::Buffer, unit_vertices: metal::Buffer,
instances: metal::Buffer, instances: metal::Buffer,
sprite_atlas: Arc<MetalAtlas>, sprite_atlas: Arc<MetalAtlas>,
core_video_texture_cache: CVMetalTextureCache,
} }
impl MetalRenderer { impl MetalRenderer {
@ -143,6 +148,14 @@ impl MetalRenderer {
"polychrome_sprite_fragment", "polychrome_sprite_fragment",
MTLPixelFormat::BGRA8Unorm, MTLPixelFormat::BGRA8Unorm,
); );
let surfaces_pipeline_state = build_pipeline_state(
&device,
&library,
"surfaces",
"surface_vertex",
"surface_fragment",
MTLPixelFormat::BGRA8Unorm,
);
let command_queue = device.new_command_queue(); let command_queue = device.new_command_queue();
let sprite_atlas = Arc::new(MetalAtlas::new(device.clone())); let sprite_atlas = Arc::new(MetalAtlas::new(device.clone()));
@ -157,9 +170,11 @@ impl MetalRenderer {
underlines_pipeline_state, underlines_pipeline_state,
monochrome_sprites_pipeline_state, monochrome_sprites_pipeline_state,
polychrome_sprites_pipeline_state, polychrome_sprites_pipeline_state,
surfaces_pipeline_state,
unit_vertices, unit_vertices,
instances, instances,
sprite_atlas, sprite_atlas,
core_video_texture_cache: CVMetalTextureCache::new(device.as_ptr()).unwrap(),
} }
} }
@ -268,6 +283,14 @@ impl MetalRenderer {
command_encoder, command_encoder,
); );
} }
PrimitiveBatch::Surfaces(surfaces) => {
self.draw_surfaces(
surfaces,
&mut instance_offset,
viewport_size,
command_encoder,
);
}
} }
} }
@ -793,6 +816,102 @@ impl MetalRenderer {
); );
*offset = next_offset; *offset = next_offset;
} }
fn draw_surfaces(
&mut self,
surfaces: &[Surface],
offset: &mut usize,
viewport_size: Size<DevicePixels>,
command_encoder: &metal::RenderCommandEncoderRef,
) {
command_encoder.set_render_pipeline_state(&self.surfaces_pipeline_state);
command_encoder.set_vertex_buffer(
SurfaceInputIndex::Vertices as u64,
Some(&self.unit_vertices),
0,
);
command_encoder.set_vertex_bytes(
SurfaceInputIndex::ViewportSize as u64,
mem::size_of_val(&viewport_size) as u64,
&viewport_size as *const Size<DevicePixels> as *const _,
);
for surface in surfaces {
let texture_size = size(
DevicePixels::from(surface.image_buffer.width() as i32),
DevicePixels::from(surface.image_buffer.height() as i32),
);
assert_eq!(
surface.image_buffer.pixel_format_type(),
media::core_video::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
);
let y_texture = self
.core_video_texture_cache
.create_texture_from_image(
surface.image_buffer.as_concrete_TypeRef(),
ptr::null(),
MTLPixelFormat::R8Unorm,
surface.image_buffer.plane_width(0),
surface.image_buffer.plane_height(0),
0,
)
.unwrap();
let cb_cr_texture = self
.core_video_texture_cache
.create_texture_from_image(
surface.image_buffer.as_concrete_TypeRef(),
ptr::null(),
MTLPixelFormat::RG8Unorm,
surface.image_buffer.plane_width(1),
surface.image_buffer.plane_height(1),
1,
)
.unwrap();
align_offset(offset);
let next_offset = *offset + mem::size_of::<Surface>();
assert!(
next_offset <= INSTANCE_BUFFER_SIZE,
"instance buffer exhausted"
);
command_encoder.set_vertex_buffer(
SurfaceInputIndex::Surfaces as u64,
Some(&self.instances),
*offset as u64,
);
command_encoder.set_vertex_bytes(
SurfaceInputIndex::TextureSize as u64,
mem::size_of_val(&texture_size) as u64,
&texture_size as *const Size<DevicePixels> as *const _,
);
command_encoder.set_fragment_texture(
SurfaceInputIndex::YTexture as u64,
Some(y_texture.as_texture_ref()),
);
command_encoder.set_fragment_texture(
SurfaceInputIndex::CbCrTexture as u64,
Some(cb_cr_texture.as_texture_ref()),
);
unsafe {
let buffer_contents =
(self.instances.contents() as *mut u8).add(*offset) as *mut SurfaceBounds;
ptr::write(
buffer_contents,
SurfaceBounds {
bounds: surface.bounds,
content_mask: surface.content_mask.clone(),
},
);
}
command_encoder.draw_primitives(metal::MTLPrimitiveType::Triangle, 0, 6);
*offset = next_offset;
}
}
} }
fn build_pipeline_state( fn build_pipeline_state(
@ -898,6 +1017,16 @@ enum SpriteInputIndex {
AtlasTexture = 4, AtlasTexture = 4,
} }
#[repr(C)]
enum SurfaceInputIndex {
Vertices = 0,
Surfaces = 1,
ViewportSize = 2,
TextureSize = 3,
YTexture = 4,
CbCrTexture = 5,
}
#[repr(C)] #[repr(C)]
enum PathRasterizationInputIndex { enum PathRasterizationInputIndex {
Vertices = 0, Vertices = 0,
@ -911,3 +1040,10 @@ pub struct PathSprite {
pub color: Hsla, pub color: Hsla,
pub tile: AtlasTile, pub tile: AtlasTile,
} }
#[derive(Clone, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct SurfaceBounds {
pub bounds: Bounds<ScaledPixels>,
pub content_mask: ContentMask<ScaledPixels>,
}

View file

@ -469,6 +469,58 @@ fragment float4 path_sprite_fragment(
return color; return color;
} }
struct SurfaceVertexOutput {
float4 position [[position]];
float2 texture_position;
float clip_distance [[clip_distance]][4];
};
struct SurfaceFragmentInput {
float4 position [[position]];
float2 texture_position;
};
vertex SurfaceVertexOutput surface_vertex(
uint unit_vertex_id [[vertex_id]], uint surface_id [[instance_id]],
constant float2 *unit_vertices [[buffer(SurfaceInputIndex_Vertices)]],
constant SurfaceBounds *surfaces [[buffer(SurfaceInputIndex_Surfaces)]],
constant Size_DevicePixels *viewport_size
[[buffer(SurfaceInputIndex_ViewportSize)]],
constant Size_DevicePixels *texture_size
[[buffer(SurfaceInputIndex_TextureSize)]]) {
float2 unit_vertex = unit_vertices[unit_vertex_id];
SurfaceBounds surface = surfaces[surface_id];
float4 device_position =
to_device_position(unit_vertex, surface.bounds, viewport_size);
float4 clip_distance = distance_from_clip_rect(unit_vertex, surface.bounds,
surface.content_mask.bounds);
// We are going to copy the whole texture, so the texture position corresponds
// to the current vertex of the unit triangle.
float2 texture_position = unit_vertex;
return SurfaceVertexOutput{
device_position,
texture_position,
{clip_distance.x, clip_distance.y, clip_distance.z, clip_distance.w}};
}
fragment float4 surface_fragment(SurfaceFragmentInput input [[stage_in]],
texture2d<float> y_texture
[[texture(SurfaceInputIndex_YTexture)]],
texture2d<float> cb_cr_texture
[[texture(SurfaceInputIndex_CbCrTexture)]]) {
constexpr sampler texture_sampler(mag_filter::linear, min_filter::linear);
const float4x4 ycbcrToRGBTransform =
float4x4(float4(+1.0000f, +1.0000f, +1.0000f, +0.0000f),
float4(+0.0000f, -0.3441f, +1.7720f, +0.0000f),
float4(+1.4020f, -0.7141f, +0.0000f, +0.0000f),
float4(-0.7010f, +0.5291f, -0.8860f, +1.0000f));
float4 ycbcr = float4(
y_texture.sample(texture_sampler, input.texture_position).r,
cb_cr_texture.sample(texture_sampler, input.texture_position).rg, 1.0);
return ycbcrToRGBTransform * ycbcr;
}
float4 hsla_to_rgba(Hsla hsla) { float4 hsla_to_rgba(Hsla hsla) {
float h = hsla.h * 6.0; // Now, it's an angle but scaled in [0, 6) range float h = hsla.h * 6.0; // Now, it's an angle but scaled in [0, 6) range
float s = hsla.s; float s = hsla.s;

View file

@ -189,13 +189,9 @@ impl Platform for TestPlatform {
unimplemented!() unimplemented!()
} }
fn on_become_active(&self, _callback: Box<dyn FnMut()>) { fn on_become_active(&self, _callback: Box<dyn FnMut()>) {}
unimplemented!()
}
fn on_resign_active(&self, _callback: Box<dyn FnMut()>) { fn on_resign_active(&self, _callback: Box<dyn FnMut()>) {}
unimplemented!()
}
fn on_quit(&self, _callback: Box<dyn FnMut()>) {} fn on_quit(&self, _callback: Box<dyn FnMut()>) {}

View file

@ -11,19 +11,20 @@ use std::{
}; };
#[derive(Default)] #[derive(Default)]
struct Handlers { pub(crate) struct TestWindowHandlers {
active_status_change: Vec<Box<dyn FnMut(bool)>>, pub(crate) active_status_change: Vec<Box<dyn FnMut(bool)>>,
input: Vec<Box<dyn FnMut(crate::InputEvent) -> bool>>, pub(crate) input: Vec<Box<dyn FnMut(crate::InputEvent) -> bool>>,
moved: Vec<Box<dyn FnMut()>>, pub(crate) moved: Vec<Box<dyn FnMut()>>,
resize: Vec<Box<dyn FnMut(Size<Pixels>, f32)>>, pub(crate) resize: Vec<Box<dyn FnMut(Size<Pixels>, f32)>>,
} }
pub struct TestWindow { pub struct TestWindow {
bounds: WindowBounds, bounds: WindowBounds,
current_scene: Mutex<Option<Scene>>, current_scene: Mutex<Option<Scene>>,
display: Rc<dyn PlatformDisplay>, display: Rc<dyn PlatformDisplay>,
pub(crate) window_title: Option<String>,
pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>, pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>,
handlers: Mutex<Handlers>, pub(crate) handlers: Arc<Mutex<TestWindowHandlers>>,
platform: Weak<TestPlatform>, platform: Weak<TestPlatform>,
sprite_atlas: Arc<dyn PlatformAtlas>, sprite_atlas: Arc<dyn PlatformAtlas>,
} }
@ -42,6 +43,7 @@ impl TestWindow {
input_handler: None, input_handler: None,
sprite_atlas: Arc::new(TestAtlas::new()), sprite_atlas: Arc::new(TestAtlas::new()),
handlers: Default::default(), handlers: Default::default(),
window_title: Default::default(),
} }
} }
} }
@ -100,8 +102,8 @@ impl PlatformWindow for TestWindow {
todo!() todo!()
} }
fn set_title(&mut self, _title: &str) { fn set_title(&mut self, title: &str) {
todo!() self.window_title = Some(title.to_owned());
} }
fn set_edited(&mut self, _edited: bool) { fn set_edited(&mut self, _edited: bool) {
@ -167,6 +169,10 @@ impl PlatformWindow for TestWindow {
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> { fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
self.sprite_atlas.clone() self.sprite_atlas.clone()
} }
fn as_test(&self) -> Option<&TestWindow> {
Some(self)
}
} }
pub struct TestAtlasState { pub struct TestAtlasState {

View file

@ -25,6 +25,7 @@ pub(crate) struct SceneBuilder {
underlines: Vec<Underline>, underlines: Vec<Underline>,
monochrome_sprites: Vec<MonochromeSprite>, monochrome_sprites: Vec<MonochromeSprite>,
polychrome_sprites: Vec<PolychromeSprite>, polychrome_sprites: Vec<PolychromeSprite>,
surfaces: Vec<Surface>,
} }
impl Default for SceneBuilder { impl Default for SceneBuilder {
@ -38,6 +39,7 @@ impl Default for SceneBuilder {
underlines: Vec::new(), underlines: Vec::new(),
monochrome_sprites: Vec::new(), monochrome_sprites: Vec::new(),
polychrome_sprites: Vec::new(), polychrome_sprites: Vec::new(),
surfaces: Vec::new(),
} }
} }
} }
@ -120,6 +122,7 @@ impl SceneBuilder {
(PrimitiveKind::PolychromeSprite, ix) => { (PrimitiveKind::PolychromeSprite, ix) => {
self.polychrome_sprites[ix].order = draw_order as DrawOrder self.polychrome_sprites[ix].order = draw_order as DrawOrder
} }
(PrimitiveKind::Surface, ix) => self.surfaces[ix].order = draw_order as DrawOrder,
} }
} }
@ -129,6 +132,7 @@ impl SceneBuilder {
self.underlines.sort_unstable(); self.underlines.sort_unstable();
self.monochrome_sprites.sort_unstable(); self.monochrome_sprites.sort_unstable();
self.polychrome_sprites.sort_unstable(); self.polychrome_sprites.sort_unstable();
self.surfaces.sort_unstable();
Scene { Scene {
shadows: mem::take(&mut self.shadows), shadows: mem::take(&mut self.shadows),
@ -137,6 +141,7 @@ impl SceneBuilder {
underlines: mem::take(&mut self.underlines), underlines: mem::take(&mut self.underlines),
monochrome_sprites: mem::take(&mut self.monochrome_sprites), monochrome_sprites: mem::take(&mut self.monochrome_sprites),
polychrome_sprites: mem::take(&mut self.polychrome_sprites), polychrome_sprites: mem::take(&mut self.polychrome_sprites),
surfaces: mem::take(&mut self.surfaces),
} }
} }
@ -185,6 +190,10 @@ impl SceneBuilder {
sprite.order = layer_id; sprite.order = layer_id;
self.polychrome_sprites.push(sprite); self.polychrome_sprites.push(sprite);
} }
Primitive::Surface(mut surface) => {
surface.order = layer_id;
self.surfaces.push(surface);
}
} }
} }
} }
@ -196,6 +205,7 @@ pub(crate) struct Scene {
pub underlines: Vec<Underline>, pub underlines: Vec<Underline>,
pub monochrome_sprites: Vec<MonochromeSprite>, pub monochrome_sprites: Vec<MonochromeSprite>,
pub polychrome_sprites: Vec<PolychromeSprite>, pub polychrome_sprites: Vec<PolychromeSprite>,
pub surfaces: Vec<Surface>,
} }
impl Scene { impl Scene {
@ -224,6 +234,9 @@ impl Scene {
polychrome_sprites: &self.polychrome_sprites, polychrome_sprites: &self.polychrome_sprites,
polychrome_sprites_start: 0, polychrome_sprites_start: 0,
polychrome_sprites_iter: self.polychrome_sprites.iter().peekable(), polychrome_sprites_iter: self.polychrome_sprites.iter().peekable(),
surfaces: &self.surfaces,
surfaces_start: 0,
surfaces_iter: self.surfaces.iter().peekable(),
} }
} }
} }
@ -247,6 +260,9 @@ struct BatchIterator<'a> {
polychrome_sprites: &'a [PolychromeSprite], polychrome_sprites: &'a [PolychromeSprite],
polychrome_sprites_start: usize, polychrome_sprites_start: usize,
polychrome_sprites_iter: Peekable<slice::Iter<'a, PolychromeSprite>>, polychrome_sprites_iter: Peekable<slice::Iter<'a, PolychromeSprite>>,
surfaces: &'a [Surface],
surfaces_start: usize,
surfaces_iter: Peekable<slice::Iter<'a, Surface>>,
} }
impl<'a> Iterator for BatchIterator<'a> { impl<'a> Iterator for BatchIterator<'a> {
@ -272,6 +288,10 @@ impl<'a> Iterator for BatchIterator<'a> {
self.polychrome_sprites_iter.peek().map(|s| s.order), self.polychrome_sprites_iter.peek().map(|s| s.order),
PrimitiveKind::PolychromeSprite, PrimitiveKind::PolychromeSprite,
), ),
(
self.surfaces_iter.peek().map(|s| s.order),
PrimitiveKind::Surface,
),
]; ];
orders_and_kinds.sort_by_key(|(order, kind)| (order.unwrap_or(u32::MAX), *kind)); orders_and_kinds.sort_by_key(|(order, kind)| (order.unwrap_or(u32::MAX), *kind));
@ -378,6 +398,21 @@ impl<'a> Iterator for BatchIterator<'a> {
sprites: &self.polychrome_sprites[sprites_start..sprites_end], sprites: &self.polychrome_sprites[sprites_start..sprites_end],
}) })
} }
PrimitiveKind::Surface => {
let surfaces_start = self.surfaces_start;
let mut surfaces_end = surfaces_start;
while self
.surfaces_iter
.next_if(|surface| surface.order <= max_order)
.is_some()
{
surfaces_end += 1;
}
self.surfaces_start = surfaces_end;
Some(PrimitiveBatch::Surfaces(
&self.surfaces[surfaces_start..surfaces_end],
))
}
} }
} }
} }
@ -391,6 +426,7 @@ pub enum PrimitiveKind {
Underline, Underline,
MonochromeSprite, MonochromeSprite,
PolychromeSprite, PolychromeSprite,
Surface,
} }
pub enum Primitive { pub enum Primitive {
@ -400,6 +436,7 @@ pub enum Primitive {
Underline(Underline), Underline(Underline),
MonochromeSprite(MonochromeSprite), MonochromeSprite(MonochromeSprite),
PolychromeSprite(PolychromeSprite), PolychromeSprite(PolychromeSprite),
Surface(Surface),
} }
impl Primitive { impl Primitive {
@ -411,6 +448,7 @@ impl Primitive {
Primitive::Underline(underline) => &underline.bounds, Primitive::Underline(underline) => &underline.bounds,
Primitive::MonochromeSprite(sprite) => &sprite.bounds, Primitive::MonochromeSprite(sprite) => &sprite.bounds,
Primitive::PolychromeSprite(sprite) => &sprite.bounds, Primitive::PolychromeSprite(sprite) => &sprite.bounds,
Primitive::Surface(surface) => &surface.bounds,
} }
} }
@ -422,6 +460,7 @@ impl Primitive {
Primitive::Underline(underline) => &underline.content_mask, Primitive::Underline(underline) => &underline.content_mask,
Primitive::MonochromeSprite(sprite) => &sprite.content_mask, Primitive::MonochromeSprite(sprite) => &sprite.content_mask,
Primitive::PolychromeSprite(sprite) => &sprite.content_mask, Primitive::PolychromeSprite(sprite) => &sprite.content_mask,
Primitive::Surface(surface) => &surface.content_mask,
} }
} }
} }
@ -440,6 +479,7 @@ pub(crate) enum PrimitiveBatch<'a> {
texture_id: AtlasTextureId, texture_id: AtlasTextureId,
sprites: &'a [PolychromeSprite], sprites: &'a [PolychromeSprite],
}, },
Surfaces(&'a [Surface]),
} }
#[derive(Default, Debug, Clone, Eq, PartialEq)] #[derive(Default, Debug, Clone, Eq, PartialEq)]
@ -593,6 +633,32 @@ impl From<PolychromeSprite> for Primitive {
} }
} }
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Surface {
pub order: u32,
pub bounds: Bounds<ScaledPixels>,
pub content_mask: ContentMask<ScaledPixels>,
pub image_buffer: media::core_video::CVImageBuffer,
}
impl Ord for Surface {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.order.cmp(&other.order)
}
}
impl PartialOrd for Surface {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl From<Surface> for Primitive {
fn from(surface: Surface) -> Self {
Primitive::Surface(surface)
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct PathId(pub(crate) usize); pub(crate) struct PathId(pub(crate) usize);

View file

@ -1,4 +1,7 @@
use super::{AbsoluteLength, Bounds, DefiniteLength, Edges, Length, Pixels, Point, Size, Style}; use crate::{
AbsoluteLength, Bounds, DefiniteLength, Edges, Length, Pixels, Point, Size, Style,
WindowContext,
};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::fmt::Debug; use std::fmt::Debug;
@ -9,13 +12,21 @@ use taffy::{
Taffy, Taffy,
}; };
type Measureable = dyn Fn(Size<Option<Pixels>>, Size<AvailableSpace>) -> Size<Pixels> + Send + Sync;
pub struct TaffyLayoutEngine { pub struct TaffyLayoutEngine {
taffy: Taffy<Box<Measureable>>, taffy: Taffy,
children_to_parents: HashMap<LayoutId, LayoutId>, children_to_parents: HashMap<LayoutId, LayoutId>,
absolute_layout_bounds: HashMap<LayoutId, Bounds<Pixels>>, absolute_layout_bounds: HashMap<LayoutId, Bounds<Pixels>>,
computed_layouts: HashSet<LayoutId>, computed_layouts: HashSet<LayoutId>,
nodes_to_measure: HashMap<
LayoutId,
Box<
dyn FnMut(
Size<Option<Pixels>>,
Size<AvailableSpace>,
&mut WindowContext,
) -> Size<Pixels>,
>,
>,
} }
static EXPECT_MESSAGE: &'static str = static EXPECT_MESSAGE: &'static str =
@ -28,6 +39,7 @@ impl TaffyLayoutEngine {
children_to_parents: HashMap::default(), children_to_parents: HashMap::default(),
absolute_layout_bounds: HashMap::default(), absolute_layout_bounds: HashMap::default(),
computed_layouts: HashSet::default(), computed_layouts: HashSet::default(),
nodes_to_measure: HashMap::default(),
} }
} }
@ -36,6 +48,7 @@ impl TaffyLayoutEngine {
self.children_to_parents.clear(); self.children_to_parents.clear();
self.absolute_layout_bounds.clear(); self.absolute_layout_bounds.clear();
self.computed_layouts.clear(); self.computed_layouts.clear();
self.nodes_to_measure.clear();
} }
pub fn request_layout( pub fn request_layout(
@ -65,18 +78,18 @@ impl TaffyLayoutEngine {
&mut self, &mut self,
style: Style, style: Style,
rem_size: Pixels, rem_size: Pixels,
measure: impl Fn(Size<Option<Pixels>>, Size<AvailableSpace>) -> Size<Pixels> measure: impl FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>
+ Send
+ Sync
+ 'static, + 'static,
) -> LayoutId { ) -> LayoutId {
let style = style.to_taffy(rem_size); let style = style.to_taffy(rem_size);
let measurable = Box::new(measure); let layout_id = self
self.taffy .taffy
.new_leaf_with_context(style, measurable) .new_leaf_with_context(style, ())
.expect(EXPECT_MESSAGE) .expect(EXPECT_MESSAGE)
.into() .into();
self.nodes_to_measure.insert(layout_id, Box::new(measure));
layout_id
} }
// Used to understand performance // Used to understand performance
@ -126,7 +139,12 @@ impl TaffyLayoutEngine {
Ok(edges) Ok(edges)
} }
pub fn compute_layout(&mut self, id: LayoutId, available_space: Size<AvailableSpace>) { pub fn compute_layout(
&mut self,
id: LayoutId,
available_space: Size<AvailableSpace>,
cx: &mut WindowContext,
) {
// Leaving this here until we have a better instrumentation approach. // Leaving this here until we have a better instrumentation approach.
// println!("Laying out {} children", self.count_all_children(id)?); // println!("Laying out {} children", self.count_all_children(id)?);
// println!("Max layout depth: {}", self.max_depth(0, id)?); // println!("Max layout depth: {}", self.max_depth(0, id)?);
@ -159,8 +177,8 @@ impl TaffyLayoutEngine {
.compute_layout_with_measure( .compute_layout_with_measure(
id.into(), id.into(),
available_space.into(), available_space.into(),
|known_dimensions, available_space, _node_id, context| { |known_dimensions, available_space, node_id, _context| {
let Some(measure) = context else { let Some(measure) = self.nodes_to_measure.get_mut(&node_id.into()) else {
return taffy::geometry::Size::default(); return taffy::geometry::Size::default();
}; };
@ -169,10 +187,11 @@ impl TaffyLayoutEngine {
height: known_dimensions.height.map(Pixels), height: known_dimensions.height.map(Pixels),
}; };
measure(known_dimensions, available_space.into()).into() measure(known_dimensions, available_space.into(), cx).into()
}, },
) )
.expect(EXPECT_MESSAGE); .expect(EXPECT_MESSAGE);
// println!("compute_layout took {:?}", started_at.elapsed()); // println!("compute_layout took {:?}", started_at.elapsed());
} }

View file

@ -209,9 +209,7 @@ impl AnyView {
) { ) {
cx.with_absolute_element_offset(origin, |cx| { cx.with_absolute_element_offset(origin, |cx| {
let (layout_id, rendered_element) = (self.layout)(self, cx); let (layout_id, rendered_element) = (self.layout)(self, cx);
cx.window cx.compute_layout(layout_id, available_space);
.layout_engine
.compute_layout(layout_id, available_space);
(self.paint)(self, rendered_element, cx); (self.paint)(self, rendered_element, cx);
}) })
} }
@ -240,6 +238,10 @@ impl Element for AnyView {
} }
fn paint(self, _: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) { fn paint(self, _: Bounds<Pixels>, state: &mut Self::State, cx: &mut WindowContext) {
debug_assert!(
state.is_some(),
"state is None. Did you include an AnyView twice in the tree?"
);
(self.paint)(&self, state.take().unwrap(), cx) (self.paint)(&self, state.take().unwrap(), cx)
} }
} }

View file

@ -8,8 +8,8 @@ use crate::{
MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler,
PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams,
RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size,
Style, SubscriberSet, Subscription, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, Style, SubscriberSet, Subscription, Surface, TaffyLayoutEngine, Task, Underline,
VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS, UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,
}; };
use anyhow::{anyhow, Context as _, Result}; use anyhow::{anyhow, Context as _, Result};
use collections::HashMap; use collections::HashMap;
@ -18,6 +18,7 @@ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
StreamExt, StreamExt,
}; };
use media::core_video::CVImageBuffer;
use parking_lot::RwLock; use parking_lot::RwLock;
use slotmap::SlotMap; use slotmap::SlotMap;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -208,7 +209,7 @@ pub struct Window {
sprite_atlas: Arc<dyn PlatformAtlas>, sprite_atlas: Arc<dyn PlatformAtlas>,
rem_size: Pixels, rem_size: Pixels,
viewport_size: Size<Pixels>, viewport_size: Size<Pixels>,
pub(crate) layout_engine: TaffyLayoutEngine, layout_engine: Option<TaffyLayoutEngine>,
pub(crate) root_view: Option<AnyView>, pub(crate) root_view: Option<AnyView>,
pub(crate) element_id_stack: GlobalElementId, pub(crate) element_id_stack: GlobalElementId,
pub(crate) previous_frame: Frame, pub(crate) previous_frame: Frame,
@ -326,7 +327,7 @@ impl Window {
sprite_atlas, sprite_atlas,
rem_size: px(16.), rem_size: px(16.),
viewport_size: content_size, viewport_size: content_size,
layout_engine: TaffyLayoutEngine::new(), layout_engine: Some(TaffyLayoutEngine::new()),
root_view: None, root_view: None,
element_id_stack: GlobalElementId::default(), element_id_stack: GlobalElementId::default(),
previous_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())), previous_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())),
@ -605,9 +606,11 @@ impl<'a> WindowContext<'a> {
self.app.layout_id_buffer.extend(children.into_iter()); self.app.layout_id_buffer.extend(children.into_iter());
let rem_size = self.rem_size(); let rem_size = self.rem_size();
self.window self.window.layout_engine.as_mut().unwrap().request_layout(
.layout_engine style,
.request_layout(style, rem_size, &self.app.layout_id_buffer) rem_size,
&self.app.layout_id_buffer,
)
} }
/// Add a node to the layout tree for the current frame. Instead of taking a `Style` and children, /// Add a node to the layout tree for the current frame. Instead of taking a `Style` and children,
@ -617,22 +620,25 @@ impl<'a> WindowContext<'a> {
/// The given closure is invoked at layout time with the known dimensions and available space and /// The given closure is invoked at layout time with the known dimensions and available space and
/// returns a `Size`. /// returns a `Size`.
pub fn request_measured_layout< pub fn request_measured_layout<
F: Fn(Size<Option<Pixels>>, Size<AvailableSpace>) -> Size<Pixels> + Send + Sync + 'static, F: FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>
+ 'static,
>( >(
&mut self, &mut self,
style: Style, style: Style,
rem_size: Pixels,
measure: F, measure: F,
) -> LayoutId { ) -> LayoutId {
let rem_size = self.rem_size();
self.window self.window
.layout_engine .layout_engine
.as_mut()
.unwrap()
.request_measured_layout(style, rem_size, measure) .request_measured_layout(style, rem_size, measure)
} }
pub fn compute_layout(&mut self, layout_id: LayoutId, available_space: Size<AvailableSpace>) { pub fn compute_layout(&mut self, layout_id: LayoutId, available_space: Size<AvailableSpace>) {
self.window let mut layout_engine = self.window.layout_engine.take().unwrap();
.layout_engine layout_engine.compute_layout(layout_id, available_space, self);
.compute_layout(layout_id, available_space) self.window.layout_engine = Some(layout_engine);
} }
/// Obtain the bounds computed for the given LayoutId relative to the window. This method should not /// Obtain the bounds computed for the given LayoutId relative to the window. This method should not
@ -642,6 +648,8 @@ impl<'a> WindowContext<'a> {
let mut bounds = self let mut bounds = self
.window .window
.layout_engine .layout_engine
.as_mut()
.unwrap()
.layout_bounds(layout_id) .layout_bounds(layout_id)
.map(Into::into); .map(Into::into);
bounds.origin += self.element_offset(); bounds.origin += self.element_offset();
@ -677,6 +685,10 @@ impl<'a> WindowContext<'a> {
self.window.platform_window.zoom(); self.window.platform_window.zoom();
} }
pub fn set_window_title(&mut self, title: &str) {
self.window.platform_window.set_title(title);
}
pub fn display(&self) -> Option<Rc<dyn PlatformDisplay>> { pub fn display(&self) -> Option<Rc<dyn PlatformDisplay>> {
self.platform self.platform
.displays() .displays()
@ -1116,6 +1128,23 @@ impl<'a> WindowContext<'a> {
Ok(()) Ok(())
} }
/// Paint a surface into the scene for the current frame at the current z-index.
pub fn paint_surface(&mut self, bounds: Bounds<Pixels>, image_buffer: CVImageBuffer) {
let scale_factor = self.scale_factor();
let bounds = bounds.scale(scale_factor);
let content_mask = self.content_mask().scale(scale_factor);
let window = &mut *self.window;
window.current_frame.scene_builder.insert(
&window.current_frame.z_index_stack,
Surface {
order: 0,
bounds,
content_mask,
image_buffer,
},
);
}
/// Draw pixels to the display for this window based on the contents of its scene. /// Draw pixels to the display for this window based on the contents of its scene.
pub(crate) fn draw(&mut self) { pub(crate) fn draw(&mut self) {
let root_view = self.window.root_view.take().unwrap(); let root_view = self.window.root_view.take().unwrap();
@ -1171,7 +1200,7 @@ impl<'a> WindowContext<'a> {
self.text_system().start_frame(); self.text_system().start_frame();
let window = &mut *self.window; let window = &mut *self.window;
window.layout_engine.clear(); window.layout_engine.as_mut().unwrap().clear();
mem::swap(&mut window.previous_frame, &mut window.current_frame); mem::swap(&mut window.previous_frame, &mut window.current_frame);
let frame = &mut window.current_frame; let frame = &mut window.current_frame;

View file

@ -197,8 +197,12 @@ impl CachedLspAdapter {
self.adapter.code_action_kinds() self.adapter.code_action_kinds()
} }
pub fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { pub fn workspace_configuration(
self.adapter.workspace_configuration(cx) &self,
workspace_root: &Path,
cx: &mut AppContext,
) -> BoxFuture<'static, Value> {
self.adapter.workspace_configuration(workspace_root, cx)
} }
pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) { pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
@ -312,7 +316,7 @@ pub trait LspAdapter: 'static + Send + Sync {
None None
} }
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(&self, _: &Path, _: &mut AppContext) -> BoxFuture<'static, Value> {
futures::future::ready(serde_json::json!({})).boxed() futures::future::ready(serde_json::json!({})).boxed()
} }

View file

@ -200,8 +200,12 @@ impl CachedLspAdapter {
self.adapter.code_action_kinds() self.adapter.code_action_kinds()
} }
pub fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { pub fn workspace_configuration(
self.adapter.workspace_configuration(cx) &self,
workspace_root: &Path,
cx: &mut AppContext,
) -> BoxFuture<'static, Value> {
self.adapter.workspace_configuration(workspace_root, cx)
} }
pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) { pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
@ -315,7 +319,7 @@ pub trait LspAdapter: 'static + Send + Sync {
None None
} }
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(&self, _: &Path, _: &mut AppContext) -> BoxFuture<'static, Value> {
futures::future::ready(serde_json::json!({})).boxed() futures::future::ready(serde_json::json!({})).boxed()
} }

View file

@ -429,8 +429,8 @@ impl LanguageServer {
let root_uri = Url::from_file_path(&self.root_path).unwrap(); let root_uri = Url::from_file_path(&self.root_path).unwrap();
#[allow(deprecated)] #[allow(deprecated)]
let params = InitializeParams { let params = InitializeParams {
process_id: Default::default(), process_id: None,
root_path: Default::default(), root_path: None,
root_uri: Some(root_uri.clone()), root_uri: Some(root_uri.clone()),
initialization_options: options, initialization_options: options,
capabilities: ClientCapabilities { capabilities: ClientCapabilities {
@ -451,12 +451,15 @@ impl LanguageServer {
inlay_hint: Some(InlayHintWorkspaceClientCapabilities { inlay_hint: Some(InlayHintWorkspaceClientCapabilities {
refresh_support: Some(true), refresh_support: Some(true),
}), }),
diagnostic: Some(DiagnosticWorkspaceClientCapabilities {
refresh_support: None,
}),
..Default::default() ..Default::default()
}), }),
text_document: Some(TextDocumentClientCapabilities { text_document: Some(TextDocumentClientCapabilities {
definition: Some(GotoCapability { definition: Some(GotoCapability {
link_support: Some(true), link_support: Some(true),
..Default::default() dynamic_registration: None,
}), }),
code_action: Some(CodeActionClientCapabilities { code_action: Some(CodeActionClientCapabilities {
code_action_literal_support: Some(CodeActionLiteralSupport { code_action_literal_support: Some(CodeActionLiteralSupport {
@ -501,7 +504,7 @@ impl LanguageServer {
}), }),
hover: Some(HoverClientCapabilities { hover: Some(HoverClientCapabilities {
content_format: Some(vec![MarkupKind::Markdown]), content_format: Some(vec![MarkupKind::Markdown]),
..Default::default() dynamic_registration: None,
}), }),
inlay_hint: Some(InlayHintClientCapabilities { inlay_hint: Some(InlayHintClientCapabilities {
resolve_support: Some(InlayHintResolveClientCapabilities { resolve_support: Some(InlayHintResolveClientCapabilities {
@ -515,6 +518,20 @@ impl LanguageServer {
}), }),
dynamic_registration: Some(false), dynamic_registration: Some(false),
}), }),
publish_diagnostics: Some(PublishDiagnosticsClientCapabilities {
related_information: Some(true),
..Default::default()
}),
formatting: Some(DynamicRegistrationClientCapabilities {
dynamic_registration: None,
}),
on_type_formatting: Some(DynamicRegistrationClientCapabilities {
dynamic_registration: None,
}),
diagnostic: Some(DiagnosticClientCapabilities {
related_document_support: Some(true),
dynamic_registration: None,
}),
..Default::default() ..Default::default()
}), }),
experimental: Some(json!({ experimental: Some(json!({
@ -524,15 +541,15 @@ impl LanguageServer {
work_done_progress: Some(true), work_done_progress: Some(true),
..Default::default() ..Default::default()
}), }),
..Default::default() general: None,
}, },
trace: Default::default(), trace: None,
workspace_folders: Some(vec![WorkspaceFolder { workspace_folders: Some(vec![WorkspaceFolder {
uri: root_uri, uri: root_uri,
name: Default::default(), name: Default::default(),
}]), }]),
client_info: Default::default(), client_info: None,
locale: Default::default(), locale: None,
}; };
let response = self.request::<request::Initialize>(params).await?; let response = self.request::<request::Initialize>(params).await?;

View file

@ -434,8 +434,8 @@ impl LanguageServer {
let root_uri = Url::from_file_path(&self.root_path).unwrap(); let root_uri = Url::from_file_path(&self.root_path).unwrap();
#[allow(deprecated)] #[allow(deprecated)]
let params = InitializeParams { let params = InitializeParams {
process_id: Default::default(), process_id: None,
root_path: Default::default(), root_path: None,
root_uri: Some(root_uri.clone()), root_uri: Some(root_uri.clone()),
initialization_options: options, initialization_options: options,
capabilities: ClientCapabilities { capabilities: ClientCapabilities {
@ -456,12 +456,15 @@ impl LanguageServer {
inlay_hint: Some(InlayHintWorkspaceClientCapabilities { inlay_hint: Some(InlayHintWorkspaceClientCapabilities {
refresh_support: Some(true), refresh_support: Some(true),
}), }),
diagnostic: Some(DiagnosticWorkspaceClientCapabilities {
refresh_support: None,
}),
..Default::default() ..Default::default()
}), }),
text_document: Some(TextDocumentClientCapabilities { text_document: Some(TextDocumentClientCapabilities {
definition: Some(GotoCapability { definition: Some(GotoCapability {
link_support: Some(true), link_support: Some(true),
..Default::default() dynamic_registration: None,
}), }),
code_action: Some(CodeActionClientCapabilities { code_action: Some(CodeActionClientCapabilities {
code_action_literal_support: Some(CodeActionLiteralSupport { code_action_literal_support: Some(CodeActionLiteralSupport {
@ -503,7 +506,7 @@ impl LanguageServer {
}), }),
hover: Some(HoverClientCapabilities { hover: Some(HoverClientCapabilities {
content_format: Some(vec![MarkupKind::Markdown]), content_format: Some(vec![MarkupKind::Markdown]),
..Default::default() dynamic_registration: None,
}), }),
inlay_hint: Some(InlayHintClientCapabilities { inlay_hint: Some(InlayHintClientCapabilities {
resolve_support: Some(InlayHintResolveClientCapabilities { resolve_support: Some(InlayHintResolveClientCapabilities {
@ -517,6 +520,20 @@ impl LanguageServer {
}), }),
dynamic_registration: Some(false), dynamic_registration: Some(false),
}), }),
publish_diagnostics: Some(PublishDiagnosticsClientCapabilities {
related_information: Some(true),
..Default::default()
}),
formatting: Some(DynamicRegistrationClientCapabilities {
dynamic_registration: None,
}),
on_type_formatting: Some(DynamicRegistrationClientCapabilities {
dynamic_registration: None,
}),
diagnostic: Some(DiagnosticClientCapabilities {
related_document_support: Some(true),
dynamic_registration: None,
}),
..Default::default() ..Default::default()
}), }),
experimental: Some(json!({ experimental: Some(json!({
@ -526,15 +543,15 @@ impl LanguageServer {
work_done_progress: Some(true), work_done_progress: Some(true),
..Default::default() ..Default::default()
}), }),
..Default::default() general: None,
}, },
trace: Default::default(), trace: None,
workspace_folders: Some(vec![WorkspaceFolder { workspace_folders: Some(vec![WorkspaceFolder {
uri: root_uri, uri: root_uri,
name: Default::default(), name: Default::default(),
}]), }]),
client_info: Default::default(), client_info: None,
locale: Default::default(), locale: None,
}; };
let response = self.request::<request::Initialize>(params).await?; let response = self.request::<request::Initialize>(params).await?;

View file

@ -2641,8 +2641,9 @@ impl Project {
}); });
for (adapter, server) in servers { for (adapter, server) in servers {
let workspace_config = let workspace_config = cx
cx.update(|cx| adapter.workspace_configuration(cx)).await; .update(|cx| adapter.workspace_configuration(server.root_path(), cx))
.await;
server server
.notify::<lsp::notification::DidChangeConfiguration>( .notify::<lsp::notification::DidChangeConfiguration>(
lsp::DidChangeConfigurationParams { lsp::DidChangeConfigurationParams {
@ -2753,7 +2754,7 @@ impl Project {
stderr_capture.clone(), stderr_capture.clone(),
language.clone(), language.clone(),
adapter.clone(), adapter.clone(),
worktree_path, Arc::clone(&worktree_path),
ProjectLspAdapterDelegate::new(self, cx), ProjectLspAdapterDelegate::new(self, cx),
cx, cx,
) { ) {
@ -2776,6 +2777,7 @@ impl Project {
cx.spawn_weak(|this, mut cx| async move { cx.spawn_weak(|this, mut cx| async move {
let result = Self::setup_and_insert_language_server( let result = Self::setup_and_insert_language_server(
this, this,
&worktree_path,
override_options, override_options,
pending_server, pending_server,
adapter.clone(), adapter.clone(),
@ -2891,6 +2893,7 @@ impl Project {
async fn setup_and_insert_language_server( async fn setup_and_insert_language_server(
this: WeakModelHandle<Self>, this: WeakModelHandle<Self>,
worktree_path: &Path,
override_initialization_options: Option<serde_json::Value>, override_initialization_options: Option<serde_json::Value>,
pending_server: PendingLanguageServer, pending_server: PendingLanguageServer,
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
@ -2903,6 +2906,7 @@ impl Project {
this, this,
override_initialization_options, override_initialization_options,
pending_server, pending_server,
worktree_path,
adapter.clone(), adapter.clone(),
server_id, server_id,
cx, cx,
@ -2932,11 +2936,14 @@ impl Project {
this: WeakModelHandle<Self>, this: WeakModelHandle<Self>,
override_options: Option<serde_json::Value>, override_options: Option<serde_json::Value>,
pending_server: PendingLanguageServer, pending_server: PendingLanguageServer,
worktree_path: &Path,
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
server_id: LanguageServerId, server_id: LanguageServerId,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Result<Arc<LanguageServer>> { ) -> Result<Arc<LanguageServer>> {
let workspace_config = cx.update(|cx| adapter.workspace_configuration(cx)).await; let workspace_config = cx
.update(|cx| adapter.workspace_configuration(worktree_path, cx))
.await;
let language_server = pending_server.task.await?; let language_server = pending_server.task.await?;
language_server language_server
@ -2964,11 +2971,14 @@ impl Project {
language_server language_server
.on_request::<lsp::request::WorkspaceConfiguration, _, _>({ .on_request::<lsp::request::WorkspaceConfiguration, _, _>({
let adapter = adapter.clone(); let adapter = adapter.clone();
let worktree_path = worktree_path.to_path_buf();
move |params, mut cx| { move |params, mut cx| {
let adapter = adapter.clone(); let adapter = adapter.clone();
let worktree_path = worktree_path.clone();
async move { async move {
let workspace_config = let workspace_config = cx
cx.update(|cx| adapter.workspace_configuration(cx)).await; .update(|cx| adapter.workspace_configuration(&worktree_path, cx))
.await;
Ok(params Ok(params
.items .items
.into_iter() .into_iter()
@ -6523,9 +6533,15 @@ impl Project {
}) })
} }
pub fn diagnostic_summary(&self, cx: &AppContext) -> DiagnosticSummary { pub fn diagnostic_summary(&self, include_ignored: bool, cx: &AppContext) -> DiagnosticSummary {
let mut summary = DiagnosticSummary::default(); let mut summary = DiagnosticSummary::default();
for (_, _, path_summary) in self.diagnostic_summaries(cx) { for (_, _, path_summary) in
self.diagnostic_summaries(include_ignored, cx)
.filter(|(path, _, _)| {
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
include_ignored || worktree == Some(false)
})
{
summary.error_count += path_summary.error_count; summary.error_count += path_summary.error_count;
summary.warning_count += path_summary.warning_count; summary.warning_count += path_summary.warning_count;
} }
@ -6534,6 +6550,7 @@ impl Project {
pub fn diagnostic_summaries<'a>( pub fn diagnostic_summaries<'a>(
&'a self, &'a self,
include_ignored: bool,
cx: &'a AppContext, cx: &'a AppContext,
) -> impl Iterator<Item = (ProjectPath, LanguageServerId, DiagnosticSummary)> + 'a { ) -> impl Iterator<Item = (ProjectPath, LanguageServerId, DiagnosticSummary)> + 'a {
self.visible_worktrees(cx).flat_map(move |worktree| { self.visible_worktrees(cx).flat_map(move |worktree| {
@ -6544,6 +6561,10 @@ impl Project {
.map(move |(path, server_id, summary)| { .map(move |(path, server_id, summary)| {
(ProjectPath { worktree_id, path }, server_id, summary) (ProjectPath { worktree_id, path }, server_id, summary)
}) })
.filter(move |(path, _, _)| {
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
include_ignored || worktree == Some(false)
})
}) })
} }

View file

@ -806,7 +806,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) { async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
init_test(cx); init_test(cx);
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
@ -814,7 +814,12 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
"/root", "/root",
json!({ json!({
"dir": { "dir": {
".git": {
"HEAD": "ref: refs/heads/main",
},
".gitignore": "b.rs",
"a.rs": "let a = 1;", "a.rs": "let a = 1;",
"b.rs": "let b = 2;",
}, },
"other.rs": "let b = c;" "other.rs": "let b = c;"
}), }),
@ -822,6 +827,13 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
.await; .await;
let project = Project::test(fs, ["/root/dir".as_ref()], cx).await; let project = Project::test(fs, ["/root/dir".as_ref()], cx).await;
let (worktree, _) = project
.update(cx, |project, cx| {
project.find_or_create_local_worktree("/root/dir", true, cx)
})
.await
.unwrap();
let main_worktree_id = worktree.read_with(cx, |tree, _| tree.id());
let (worktree, _) = project let (worktree, _) = project
.update(cx, |project, cx| { .update(cx, |project, cx| {
@ -829,12 +841,30 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree.read_with(cx, |tree, _| tree.id()); let other_worktree_id = worktree.read_with(cx, |tree, _| tree.id());
let server_id = LanguageServerId(0);
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
project project
.update_diagnostics( .update_diagnostics(
LanguageServerId(0), server_id,
lsp::PublishDiagnosticsParams {
uri: Url::from_file_path("/root/dir/b.rs").unwrap(),
version: None,
diagnostics: vec![lsp::Diagnostic {
range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),
severity: Some(lsp::DiagnosticSeverity::ERROR),
message: "unused variable 'b'".to_string(),
..Default::default()
}],
},
&[],
cx,
)
.unwrap();
project
.update_diagnostics(
server_id,
lsp::PublishDiagnosticsParams { lsp::PublishDiagnosticsParams {
uri: Url::from_file_path("/root/other.rs").unwrap(), uri: Url::from_file_path("/root/other.rs").unwrap(),
version: None, version: None,
@ -851,11 +881,34 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
.unwrap(); .unwrap();
}); });
let buffer = project let main_ignored_buffer = project
.update(cx, |project, cx| project.open_buffer((worktree_id, ""), cx)) .update(cx, |project, cx| {
project.open_buffer((main_worktree_id, "b.rs"), cx)
})
.await .await
.unwrap(); .unwrap();
buffer.read_with(cx, |buffer, _| { main_ignored_buffer.read_with(cx, |buffer, _| {
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
assert_eq!(
chunks
.iter()
.map(|(s, d)| (s.as_str(), *d))
.collect::<Vec<_>>(),
&[
("let ", None),
("b", Some(DiagnosticSeverity::ERROR)),
(" = 2;", None),
],
"Gigitnored buffers should still get in-buffer diagnostics",
);
});
let other_buffer = project
.update(cx, |project, cx| {
project.open_buffer((other_worktree_id, ""), cx)
})
.await
.unwrap();
other_buffer.read_with(cx, |buffer, _| {
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len()); let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
assert_eq!( assert_eq!(
chunks chunks
@ -866,13 +919,29 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
("let b = ", None), ("let b = ", None),
("c", Some(DiagnosticSeverity::ERROR)), ("c", Some(DiagnosticSeverity::ERROR)),
(";", None), (";", None),
] ],
"Buffers from hidden projects should still get in-buffer diagnostics"
); );
}); });
project.read_with(cx, |project, cx| { project.read_with(cx, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).next(), None); assert_eq!(project.diagnostic_summaries(false, cx).next(), None);
assert_eq!(project.diagnostic_summary(cx).error_count, 0); assert_eq!(
project.diagnostic_summaries(true, cx).collect::<Vec<_>>(),
vec![(
ProjectPath {
worktree_id: main_worktree_id,
path: Arc::from(Path::new("b.rs")),
},
server_id,
DiagnosticSummary {
error_count: 1,
warning_count: 0,
}
)]
);
assert_eq!(project.diagnostic_summary(false, cx).error_count, 0);
assert_eq!(project.diagnostic_summary(true, cx).error_count, 1);
}); });
} }
@ -1145,7 +1214,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
}); });
project.read_with(cx, |project, cx| { project.read_with(cx, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 1, error_count: 1,
warning_count: 0, warning_count: 0,
@ -1171,7 +1240,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
}); });
project.read_with(cx, |project, cx| { project.read_with(cx, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 0, error_count: 0,
warning_count: 0, warning_count: 0,
@ -1763,7 +1832,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 2, error_count: 2,
warning_count: 0, warning_count: 0,

View file

@ -2677,8 +2677,9 @@ impl Project {
})?; })?;
for (adapter, server) in servers { for (adapter, server) in servers {
let workspace_config = let workspace_config = cx
cx.update(|cx| adapter.workspace_configuration(cx))?.await; .update(|cx| adapter.workspace_configuration(server.root_path(), cx))?
.await;
server server
.notify::<lsp::notification::DidChangeConfiguration>( .notify::<lsp::notification::DidChangeConfiguration>(
lsp::DidChangeConfigurationParams { lsp::DidChangeConfigurationParams {
@ -2790,7 +2791,7 @@ impl Project {
stderr_capture.clone(), stderr_capture.clone(),
language.clone(), language.clone(),
adapter.clone(), adapter.clone(),
worktree_path, Arc::clone(&worktree_path),
ProjectLspAdapterDelegate::new(self, cx), ProjectLspAdapterDelegate::new(self, cx),
cx, cx,
) { ) {
@ -2822,6 +2823,7 @@ impl Project {
cx.spawn(move |this, mut cx| async move { cx.spawn(move |this, mut cx| async move {
let result = Self::setup_and_insert_language_server( let result = Self::setup_and_insert_language_server(
this.clone(), this.clone(),
&worktree_path,
initialization_options, initialization_options,
pending_server, pending_server,
adapter.clone(), adapter.clone(),
@ -2942,6 +2944,7 @@ impl Project {
async fn setup_and_insert_language_server( async fn setup_and_insert_language_server(
this: WeakModel<Self>, this: WeakModel<Self>,
worktree_path: &Path,
initialization_options: Option<serde_json::Value>, initialization_options: Option<serde_json::Value>,
pending_server: PendingLanguageServer, pending_server: PendingLanguageServer,
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
@ -2954,6 +2957,7 @@ impl Project {
this.clone(), this.clone(),
initialization_options, initialization_options,
pending_server, pending_server,
worktree_path,
adapter.clone(), adapter.clone(),
server_id, server_id,
cx, cx,
@ -2983,11 +2987,14 @@ impl Project {
this: WeakModel<Self>, this: WeakModel<Self>,
initialization_options: Option<serde_json::Value>, initialization_options: Option<serde_json::Value>,
pending_server: PendingLanguageServer, pending_server: PendingLanguageServer,
worktree_path: &Path,
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
server_id: LanguageServerId, server_id: LanguageServerId,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Result<Arc<LanguageServer>> { ) -> Result<Arc<LanguageServer>> {
let workspace_config = cx.update(|cx| adapter.workspace_configuration(cx))?.await; let workspace_config = cx
.update(|cx| adapter.workspace_configuration(worktree_path, cx))?
.await;
let language_server = pending_server.task.await?; let language_server = pending_server.task.await?;
language_server language_server
@ -3016,11 +3023,14 @@ impl Project {
language_server language_server
.on_request::<lsp::request::WorkspaceConfiguration, _, _>({ .on_request::<lsp::request::WorkspaceConfiguration, _, _>({
let adapter = adapter.clone(); let adapter = adapter.clone();
let worktree_path = worktree_path.to_path_buf();
move |params, cx| { move |params, cx| {
let adapter = adapter.clone(); let adapter = adapter.clone();
let worktree_path = worktree_path.clone();
async move { async move {
let workspace_config = let workspace_config = cx
cx.update(|cx| adapter.workspace_configuration(cx))?.await; .update(|cx| adapter.workspace_configuration(&worktree_path, cx))?
.await;
Ok(params Ok(params
.items .items
.into_iter() .into_iter()
@ -6596,9 +6606,15 @@ impl Project {
}) })
} }
pub fn diagnostic_summary(&self, cx: &AppContext) -> DiagnosticSummary { pub fn diagnostic_summary(&self, include_ignored: bool, cx: &AppContext) -> DiagnosticSummary {
let mut summary = DiagnosticSummary::default(); let mut summary = DiagnosticSummary::default();
for (_, _, path_summary) in self.diagnostic_summaries(cx) { for (_, _, path_summary) in
self.diagnostic_summaries(include_ignored, cx)
.filter(|(path, _, _)| {
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
include_ignored || worktree == Some(false)
})
{
summary.error_count += path_summary.error_count; summary.error_count += path_summary.error_count;
summary.warning_count += path_summary.warning_count; summary.warning_count += path_summary.warning_count;
} }
@ -6607,9 +6623,11 @@ impl Project {
pub fn diagnostic_summaries<'a>( pub fn diagnostic_summaries<'a>(
&'a self, &'a self,
include_ignored: bool,
cx: &'a AppContext, cx: &'a AppContext,
) -> impl Iterator<Item = (ProjectPath, LanguageServerId, DiagnosticSummary)> + 'a { ) -> impl Iterator<Item = (ProjectPath, LanguageServerId, DiagnosticSummary)> + 'a {
self.visible_worktrees(cx).flat_map(move |worktree| { self.visible_worktrees(cx)
.flat_map(move |worktree| {
let worktree = worktree.read(cx); let worktree = worktree.read(cx);
let worktree_id = worktree.id(); let worktree_id = worktree.id();
worktree worktree
@ -6618,6 +6636,10 @@ impl Project {
(ProjectPath { worktree_id, path }, server_id, summary) (ProjectPath { worktree_id, path }, server_id, summary)
}) })
}) })
.filter(move |(path, _, _)| {
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
include_ignored || worktree == Some(false)
})
} }
pub fn disk_based_diagnostics_started( pub fn disk_based_diagnostics_started(

View file

@ -823,7 +823,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) { async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
init_test(cx); init_test(cx);
let fs = FakeFs::new(cx.executor()); let fs = FakeFs::new(cx.executor());
@ -831,7 +831,12 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
"/root", "/root",
json!({ json!({
"dir": { "dir": {
".git": {
"HEAD": "ref: refs/heads/main",
},
".gitignore": "b.rs",
"a.rs": "let a = 1;", "a.rs": "let a = 1;",
"b.rs": "let b = 2;",
}, },
"other.rs": "let b = c;" "other.rs": "let b = c;"
}), }),
@ -839,6 +844,13 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
.await; .await;
let project = Project::test(fs, ["/root/dir".as_ref()], cx).await; let project = Project::test(fs, ["/root/dir".as_ref()], cx).await;
let (worktree, _) = project
.update(cx, |project, cx| {
project.find_or_create_local_worktree("/root/dir", true, cx)
})
.await
.unwrap();
let main_worktree_id = worktree.read_with(cx, |tree, _| tree.id());
let (worktree, _) = project let (worktree, _) = project
.update(cx, |project, cx| { .update(cx, |project, cx| {
@ -846,12 +858,30 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
}) })
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree.update(cx, |tree, _| tree.id()); let other_worktree_id = worktree.update(cx, |tree, _| tree.id());
let server_id = LanguageServerId(0);
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
project project
.update_diagnostics( .update_diagnostics(
LanguageServerId(0), server_id,
lsp::PublishDiagnosticsParams {
uri: Url::from_file_path("/root/dir/b.rs").unwrap(),
version: None,
diagnostics: vec![lsp::Diagnostic {
range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),
severity: Some(lsp::DiagnosticSeverity::ERROR),
message: "unused variable 'b'".to_string(),
..Default::default()
}],
},
&[],
cx,
)
.unwrap();
project
.update_diagnostics(
server_id,
lsp::PublishDiagnosticsParams { lsp::PublishDiagnosticsParams {
uri: Url::from_file_path("/root/other.rs").unwrap(), uri: Url::from_file_path("/root/other.rs").unwrap(),
version: None, version: None,
@ -868,11 +898,34 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
.unwrap(); .unwrap();
}); });
let buffer = project let main_ignored_buffer = project
.update(cx, |project, cx| project.open_buffer((worktree_id, ""), cx)) .update(cx, |project, cx| {
project.open_buffer((main_worktree_id, "b.rs"), cx)
})
.await .await
.unwrap(); .unwrap();
buffer.update(cx, |buffer, _| { main_ignored_buffer.update(cx, |buffer, _| {
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
assert_eq!(
chunks
.iter()
.map(|(s, d)| (s.as_str(), *d))
.collect::<Vec<_>>(),
&[
("let ", None),
("b", Some(DiagnosticSeverity::ERROR)),
(" = 2;", None),
],
"Gigitnored buffers should still get in-buffer diagnostics",
);
});
let other_buffer = project
.update(cx, |project, cx| {
project.open_buffer((other_worktree_id, ""), cx)
})
.await
.unwrap();
other_buffer.update(cx, |buffer, _| {
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len()); let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
assert_eq!( assert_eq!(
chunks chunks
@ -883,13 +936,29 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
("let b = ", None), ("let b = ", None),
("c", Some(DiagnosticSeverity::ERROR)), ("c", Some(DiagnosticSeverity::ERROR)),
(";", None), (";", None),
] ],
"Buffers from hidden projects should still get in-buffer diagnostics"
); );
}); });
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
assert_eq!(project.diagnostic_summaries(cx).next(), None); assert_eq!(project.diagnostic_summaries(false, cx).next(), None);
assert_eq!(project.diagnostic_summary(cx).error_count, 0); assert_eq!(
project.diagnostic_summaries(true, cx).collect::<Vec<_>>(),
vec![(
ProjectPath {
worktree_id: main_worktree_id,
path: Arc::from(Path::new("b.rs")),
},
server_id,
DiagnosticSummary {
error_count: 1,
warning_count: 0,
}
)]
);
assert_eq!(project.diagnostic_summary(false, cx).error_count, 0);
assert_eq!(project.diagnostic_summary(true, cx).error_count, 1);
}); });
} }
@ -1162,7 +1231,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
}); });
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 1, error_count: 1,
warning_count: 0, warning_count: 0,
@ -1188,7 +1257,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
}); });
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 0, error_count: 0,
warning_count: 0, warning_count: 0,
@ -1777,7 +1846,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
project.diagnostic_summary(cx), project.diagnostic_summary(false, cx),
DiagnosticSummary { DiagnosticSummary {
error_count: 2, error_count: 2,
warning_count: 0, warning_count: 0,

View file

@ -1627,9 +1627,21 @@ impl View for ProjectPanel {
} }
} }
fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) { fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext) {
Self::reset_to_default_keymap_context(keymap); Self::reset_to_default_keymap_context(keymap);
keymap.add_identifier("menu"); keymap.add_identifier("menu");
if let Some(window) = cx.active_window() {
window.read_with(cx, |cx| {
let identifier = if self.filename_editor.is_focused(cx) {
"editing"
} else {
"not_editing"
};
keymap.add_identifier(identifier);
});
}
} }
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {

View file

@ -10,9 +10,9 @@ use anyhow::{anyhow, Result};
use gpui::{ use gpui::{
actions, div, overlay, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext, actions, div, overlay, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext,
ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, Focusable, FocusableView, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, Focusable, FocusableView,
InteractiveElement, Model, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, InteractiveElement, KeyContext, Model, MouseButton, MouseDownEvent, ParentElement, Pixels,
PromptLevel, Render, Stateful, Styled, Subscription, Task, UniformListScrollHandle, View, Point, PromptLevel, Render, Stateful, Styled, Subscription, Task, UniformListScrollHandle,
ViewContext, VisualContext as _, WeakView, WindowContext, View, ViewContext, VisualContext as _, WeakView, WindowContext,
}; };
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
use project::{ use project::{
@ -29,8 +29,7 @@ use std::{
path::Path, path::Path,
sync::Arc, sync::Arc,
}; };
use theme::ActiveTheme as _; use ui::{prelude::*, v_stack, ContextMenu, IconElement, Label, ListItem};
use ui::{v_stack, ContextMenu, IconElement, Label, ListItem};
use unicase::UniCase; use unicase::UniCase;
use util::{maybe, ResultExt, TryFutureExt}; use util::{maybe, ResultExt, TryFutureExt};
use workspace::{ use workspace::{
@ -1421,6 +1420,22 @@ impl ProjectPanel {
// ); // );
// }) // })
} }
fn dispatch_context(&self, cx: &ViewContext<Self>) -> KeyContext {
let mut dispatch_context = KeyContext::default();
dispatch_context.add("ProjectPanel");
dispatch_context.add("menu");
let identifier = if self.filename_editor.focus_handle(cx).is_focused(cx) {
"editing"
} else {
"not_editing"
};
dispatch_context.add(identifier);
dispatch_context
}
} }
impl Render for ProjectPanel { impl Render for ProjectPanel {
@ -1434,7 +1449,7 @@ impl Render for ProjectPanel {
.id("project-panel") .id("project-panel")
.size_full() .size_full()
.relative() .relative()
.key_context("ProjectPanel") .key_context(self.dispatch_context(cx))
.on_action(cx.listener(Self::select_next)) .on_action(cx.listener(Self::select_next))
.on_action(cx.listener(Self::select_prev)) .on_action(cx.listener(Self::select_prev))
.on_action(cx.listener(Self::expand_selected_entry)) .on_action(cx.listener(Self::expand_selected_entry))
@ -2845,7 +2860,7 @@ mod tests {
let worktree = worktree.read(cx); let worktree = worktree.read(cx);
if let Ok(relative_path) = path.strip_prefix(worktree.root_name()) { if let Ok(relative_path) = path.strip_prefix(worktree.root_name()) {
let entry_id = worktree.entry_for_path(relative_path).unwrap().id; let entry_id = worktree.entry_for_path(relative_path).unwrap().id;
panel.selection = Some(Selection { panel.selection = Some(crate::Selection {
worktree_id: worktree.id(), worktree_id: worktree.id(),
entry_id, entry_id,
}); });

View file

@ -4,7 +4,7 @@ use gpui::{actions, Action, AppContext, IntoElement};
pub use mode::SearchMode; pub use mode::SearchMode;
use project::search::SearchQuery; use project::search::SearchQuery;
use ui::prelude::*; use ui::prelude::*;
use ui::{ButtonStyle2, Icon, IconButton}; use ui::{ButtonStyle, Icon, IconButton};
//pub use project_search::{ProjectSearchBar, ProjectSearchView}; //pub use project_search::{ProjectSearchBar, ProjectSearchView};
// use theme::components::{ // use theme::components::{
// action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle, // action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle,
@ -91,8 +91,8 @@ impl SearchOptions {
cx.dispatch_action(action.boxed_clone()); cx.dispatch_action(action.boxed_clone());
} }
}) })
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.when(active, |button| button.style(ButtonStyle2::Filled)) .when(active, |button| button.style(ButtonStyle::Filled))
} }
} }
@ -103,8 +103,8 @@ fn toggle_replace_button(active: bool) -> impl IntoElement {
cx.dispatch_action(Box::new(ToggleReplace)); cx.dispatch_action(Box::new(ToggleReplace));
cx.notify(); cx.notify();
}) })
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.when(active, |button| button.style(ButtonStyle2::Filled)) .when(active, |button| button.style(ButtonStyle::Filled))
} }
fn render_replace_button( fn render_replace_button(

View file

@ -1,3 +1,4 @@
mod auto_height_editor;
mod focus; mod focus;
mod kitchen_sink; mod kitchen_sink;
mod picker; mod picker;
@ -5,6 +6,7 @@ mod scroll;
mod text; mod text;
mod z_index; mod z_index;
pub use auto_height_editor::*;
pub use focus::*; pub use focus::*;
pub use kitchen_sink::*; pub use kitchen_sink::*;
pub use picker::*; pub use picker::*;

View file

@ -0,0 +1,34 @@
use editor::Editor;
use gpui::{
div, white, Div, KeyBinding, ParentElement, Render, Styled, View, ViewContext, VisualContext,
WindowContext,
};
pub struct AutoHeightEditorStory {
editor: View<Editor>,
}
impl AutoHeightEditorStory {
pub fn new(cx: &mut WindowContext) -> View<Self> {
cx.bind_keys([KeyBinding::new("enter", editor::Newline, Some("Editor"))]);
cx.build_view(|cx| Self {
editor: cx.build_view(|cx| {
let mut editor = Editor::auto_height(3, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor
}),
})
}
}
impl Render for AutoHeightEditorStory {
type Element = Div;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
div()
.size_full()
.bg(white())
.text_sm()
.child(div().w_32().bg(gpui::black()).child(self.editor.clone()))
}
}

View file

@ -12,6 +12,7 @@ use ui::prelude::*;
#[derive(Debug, PartialEq, Eq, Clone, Copy, strum::Display, EnumString, EnumIter)] #[derive(Debug, PartialEq, Eq, Clone, Copy, strum::Display, EnumString, EnumIter)]
#[strum(serialize_all = "snake_case")] #[strum(serialize_all = "snake_case")]
pub enum ComponentStory { pub enum ComponentStory {
AutoHeightEditor,
Avatar, Avatar,
Button, Button,
Checkbox, Checkbox,
@ -23,6 +24,7 @@ pub enum ComponentStory {
Keybinding, Keybinding,
Label, Label,
List, List,
ListHeader,
ListItem, ListItem,
Scroll, Scroll,
Text, Text,
@ -33,6 +35,7 @@ pub enum ComponentStory {
impl ComponentStory { impl ComponentStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView { pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self { match self {
Self::AutoHeightEditor => AutoHeightEditorStory::new(cx).into(),
Self::Avatar => cx.build_view(|_| ui::AvatarStory).into(), Self::Avatar => cx.build_view(|_| ui::AvatarStory).into(),
Self::Button => cx.build_view(|_| ui::ButtonStory).into(), Self::Button => cx.build_view(|_| ui::ButtonStory).into(),
Self::Checkbox => cx.build_view(|_| ui::CheckboxStory).into(), Self::Checkbox => cx.build_view(|_| ui::CheckboxStory).into(),
@ -44,6 +47,7 @@ impl ComponentStory {
Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(), Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(),
Self::Label => cx.build_view(|_| ui::LabelStory).into(), Self::Label => cx.build_view(|_| ui::LabelStory).into(),
Self::List => cx.build_view(|_| ui::ListStory).into(), Self::List => cx.build_view(|_| ui::ListStory).into(),
Self::ListHeader => cx.build_view(|_| ui::ListHeaderStory).into(),
Self::ListItem => cx.build_view(|_| ui::ListItemStory).into(), Self::ListItem => cx.build_view(|_| ui::ListItemStory).into(),
Self::Scroll => ScrollStory::view(cx).into(), Self::Scroll => ScrollStory::view(cx).into(),
Self::Text => TextStory::view(cx).into(), Self::Text => TextStory::view(cx).into(),

View file

@ -55,9 +55,8 @@ impl Render for PlayerStory {
.border_2() .border_2()
.border_color(player.cursor) .border_color(player.cursor)
.child( .child(
img() img("https://avatars.githubusercontent.com/u/1714999?v=4")
.rounded_full() .rounded_full()
.uri("https://avatars.githubusercontent.com/u/1714999?v=4")
.size_6() .size_6()
.bg(gpui::red()), .bg(gpui::red()),
) )
@ -76,38 +75,49 @@ impl Render for PlayerStory {
.px_1p5() .px_1p5()
.bg(player.background) .bg(player.background)
.child( .child(
div().relative().neg_mx_1().rounded_full().z_index(3) div()
.relative()
.neg_mx_1()
.rounded_full()
.z_index(3)
.border_2() .border_2()
.border_color(player.background) .border_color(player.background)
.size(px(28.)) .size(px(28.))
.child( .child(
img() img("https://avatars.githubusercontent.com/u/1714999?v=4")
.rounded_full() .rounded_full()
.uri("https://avatars.githubusercontent.com/u/1714999?v=4")
.size(px(24.)) .size(px(24.))
.bg(gpui::red()), .bg(gpui::red()),
), ),
).child( )
div().relative().neg_mx_1().rounded_full().z_index(2) .child(
div()
.relative()
.neg_mx_1()
.rounded_full()
.z_index(2)
.border_2() .border_2()
.border_color(player.background) .border_color(player.background)
.size(px(28.)) .size(px(28.))
.child( .child(
img() img("https://avatars.githubusercontent.com/u/1714999?v=4")
.rounded_full() .rounded_full()
.uri("https://avatars.githubusercontent.com/u/1714999?v=4")
.size(px(24.)) .size(px(24.))
.bg(gpui::red()), .bg(gpui::red()),
), ),
).child( )
div().relative().neg_mx_1().rounded_full().z_index(1) .child(
div()
.relative()
.neg_mx_1()
.rounded_full()
.z_index(1)
.border_2() .border_2()
.border_color(player.background) .border_color(player.background)
.size(px(28.)) .size(px(28.))
.child( .child(
img() img("https://avatars.githubusercontent.com/u/1714999?v=4")
.rounded_full() .rounded_full()
.uri("https://avatars.githubusercontent.com/u/1714999?v=4")
.size(px(24.)) .size(px(24.))
.bg(gpui::red()), .bg(gpui::red()),
), ),

View file

@ -2,14 +2,14 @@ use feature_flags::FeatureFlagAppExt;
use fs::Fs; use fs::Fs;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render, actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, SharedString, View,
SharedString, View, ViewContext, VisualContext, WeakView, ViewContext, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::{update_settings_file, SettingsStore}; use settings::{update_settings_file, SettingsStore};
use std::sync::Arc; use std::sync::Arc;
use theme::{ActiveTheme, Theme, ThemeRegistry, ThemeSettings}; use theme::{Theme, ThemeRegistry, ThemeSettings};
use ui::ListItem; use ui::{prelude::*, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ui::HighlightedLabel, Workspace}; use workspace::{ui::HighlightedLabel, Workspace};

View file

@ -21,7 +21,7 @@ impl RenderOnce for Avatar {
type Rendered = Div; type Rendered = Div;
fn render(self, cx: &mut WindowContext) -> Self::Rendered { fn render(self, cx: &mut WindowContext) -> Self::Rendered {
let mut img = img(); let mut img = img(self.src);
if self.shape == Shape::Circle { if self.shape == Shape::Circle {
img = img.rounded_full(); img = img.rounded_full();
@ -34,8 +34,7 @@ impl RenderOnce for Avatar {
div() div()
.size(size) .size(size)
.child( .child(
img.source(self.src.clone()) img.size(size)
.size(size)
// todo!(Pull the avatar fallback background from the theme.) // todo!(Pull the avatar fallback background from the theme.)
.bg(gpui::red()), .bg(gpui::red()),
) )

View file

@ -1,7 +1,7 @@
use gpui::AnyView; use gpui::AnyView;
use crate::prelude::*; use crate::prelude::*;
use crate::{ButtonCommon, ButtonLike, ButtonSize2, ButtonStyle2, Label, LineHeightStyle}; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Label, LineHeightStyle};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Button { pub struct Button {
@ -54,12 +54,12 @@ impl ButtonCommon for Button {
self.base.id() self.base.id()
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.base = self.base.style(style); self.base = self.base.style(style);
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.base = self.base.size(size); self.base = self.base.size(size);
self self
} }
@ -79,7 +79,7 @@ impl RenderOnce for Button {
} else if self.base.selected { } else if self.base.selected {
Color::Selected Color::Selected
} else { } else {
Color::Default self.label_color.unwrap_or_default()
}; };
self.base.child( self.base.child(

View file

@ -1,4 +1,4 @@
use gpui::{rems, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful}; use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::h_stack; use crate::h_stack;
@ -6,13 +6,13 @@ use crate::prelude::*;
pub trait ButtonCommon: Clickable + Disableable { pub trait ButtonCommon: Clickable + Disableable {
fn id(&self) -> &ElementId; fn id(&self) -> &ElementId;
fn style(self, style: ButtonStyle2) -> Self; fn style(self, style: ButtonStyle) -> Self;
fn size(self, size: ButtonSize2) -> Self; fn size(self, size: ButtonSize) -> Self;
fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self; fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self;
} }
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum ButtonStyle2 { pub enum ButtonStyle {
#[default] #[default]
Filled, Filled,
// Tinted, // Tinted,
@ -21,54 +21,57 @@ pub enum ButtonStyle2 {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ButtonStyle { pub(crate) struct ButtonLikeStyles {
pub background: Hsla, pub background: Hsla,
#[allow(unused)]
pub border_color: Hsla, pub border_color: Hsla,
#[allow(unused)]
pub label_color: Hsla, pub label_color: Hsla,
#[allow(unused)]
pub icon_color: Hsla, pub icon_color: Hsla,
} }
impl ButtonStyle2 { impl ButtonStyle {
pub fn enabled(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn enabled(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_background, background: cx.theme().colors().element_background,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_background, background: cx.theme().colors().ghost_element_background,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
} }
} }
pub fn hovered(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn hovered(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_hover, background: cx.theme().colors().element_hover,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_hover, background: cx.theme().colors().ghost_element_hover,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
// TODO: These are not great // TODO: These are not great
label_color: Color::Muted.color(cx), label_color: Color::Muted.color(cx),
// TODO: These are not great // TODO: These are not great
@ -77,23 +80,23 @@ impl ButtonStyle2 {
} }
} }
pub fn active(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn active(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_active, background: cx.theme().colors().element_active,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_active, background: cx.theme().colors().ghost_element_active,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
// TODO: These are not great // TODO: These are not great
label_color: Color::Muted.color(cx), label_color: Color::Muted.color(cx),
// TODO: These are not great // TODO: These are not great
@ -102,22 +105,23 @@ impl ButtonStyle2 {
} }
} }
pub fn focused(self, cx: &mut WindowContext) -> ButtonStyle { #[allow(unused)]
pub(crate) fn focused(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_background, background: cx.theme().colors().element_background,
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_background, background: cx.theme().colors().ghost_element_background,
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Accent.color(cx), label_color: Color::Accent.color(cx),
icon_color: Color::Accent.color(cx), icon_color: Color::Accent.color(cx),
@ -125,23 +129,23 @@ impl ButtonStyle2 {
} }
} }
pub fn disabled(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn disabled(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_disabled, background: cx.theme().colors().element_disabled,
border_color: cx.theme().colors().border_disabled, border_color: cx.theme().colors().border_disabled,
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_disabled, background: cx.theme().colors().ghost_element_disabled,
border_color: cx.theme().colors().border_disabled, border_color: cx.theme().colors().border_disabled,
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
@ -150,19 +154,19 @@ impl ButtonStyle2 {
} }
#[derive(Default, PartialEq, Clone, Copy)] #[derive(Default, PartialEq, Clone, Copy)]
pub enum ButtonSize2 { pub enum ButtonSize {
#[default] #[default]
Default, Default,
Compact, Compact,
None, None,
} }
impl ButtonSize2 { impl ButtonSize {
fn height(self) -> Rems { fn height(self) -> Rems {
match self { match self {
ButtonSize2::Default => rems(22. / 16.), ButtonSize::Default => rems(22. / 16.),
ButtonSize2::Compact => rems(18. / 16.), ButtonSize::Compact => rems(18. / 16.),
ButtonSize2::None => rems(16. / 16.), ButtonSize::None => rems(16. / 16.),
} }
} }
} }
@ -170,10 +174,10 @@ impl ButtonSize2 {
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct ButtonLike { pub struct ButtonLike {
id: ElementId, id: ElementId,
pub(super) style: ButtonStyle2, pub(super) style: ButtonStyle,
pub(super) disabled: bool, pub(super) disabled: bool,
pub(super) selected: bool, pub(super) selected: bool,
size: ButtonSize2, size: ButtonSize,
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>, tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>, on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
children: SmallVec<[AnyElement; 2]>, children: SmallVec<[AnyElement; 2]>,
@ -183,10 +187,10 @@ impl ButtonLike {
pub fn new(id: impl Into<ElementId>) -> Self { pub fn new(id: impl Into<ElementId>) -> Self {
Self { Self {
id: id.into(), id: id.into(),
style: ButtonStyle2::default(), style: ButtonStyle::default(),
disabled: false, disabled: false,
selected: false, selected: false,
size: ButtonSize2::Default, size: ButtonSize::Default,
tooltip: None, tooltip: None,
children: SmallVec::new(), children: SmallVec::new(),
on_click: None, on_click: None,
@ -220,12 +224,12 @@ impl ButtonCommon for ButtonLike {
&self.id &self.id
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.style = style; self.style = style;
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.size = size; self.size = size;
self self
} }
@ -258,7 +262,12 @@ impl RenderOnce for ButtonLike {
.active(|active| active.bg(self.style.active(cx).background)) .active(|active| active.bg(self.style.active(cx).background))
.when_some( .when_some(
self.on_click.filter(|_| !self.disabled), self.on_click.filter(|_| !self.disabled),
|this, on_click| this.on_click(move |event, cx| (on_click)(event, cx)), |this, on_click| {
this.on_click(move |event, cx| {
cx.stop_propagation();
(on_click)(event, cx)
})
},
) )
.when_some(self.tooltip, |this, tooltip| { .when_some(self.tooltip, |this, tooltip| {
if !self.selected { if !self.selected {

View file

@ -1,7 +1,7 @@
use gpui::{Action, AnyView}; use gpui::{Action, AnyView};
use crate::prelude::*; use crate::prelude::*;
use crate::{ButtonCommon, ButtonLike, ButtonSize2, ButtonStyle2, Icon, IconElement, IconSize}; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconElement, IconSize};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct IconButton { pub struct IconButton {
@ -65,12 +65,12 @@ impl ButtonCommon for IconButton {
self.base.id() self.base.id()
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.base = self.base.style(style); self.base = self.base.style(style);
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.base = self.base.size(size); self.base = self.base.size(size);
self self
} }

View file

@ -1,73 +1,11 @@
mod list;
mod list_header; mod list_header;
mod list_item; mod list_item;
mod list_separator; mod list_separator;
mod list_sub_header; mod list_sub_header;
use gpui::{AnyElement, Div}; pub use list::*;
use smallvec::SmallVec;
use crate::prelude::*;
use crate::{v_stack, Label};
pub use list_header::*; pub use list_header::*;
pub use list_item::*; pub use list_item::*;
pub use list_separator::*; pub use list_separator::*;
pub use list_sub_header::*; pub use list_sub_header::*;
#[derive(IntoElement)]
pub struct List {
/// Message to display when the list is empty
/// Defaults to "No items"
empty_message: SharedString,
header: Option<ListHeader>,
toggle: Option<bool>,
children: SmallVec<[AnyElement; 2]>,
}
impl List {
pub fn new() -> Self {
Self {
empty_message: "No items".into(),
header: None,
toggle: None,
children: SmallVec::new(),
}
}
pub fn empty_message(mut self, empty_message: impl Into<SharedString>) -> Self {
self.empty_message = empty_message.into();
self
}
pub fn header(mut self, header: ListHeader) -> Self {
self.header = Some(header);
self
}
pub fn toggle(mut self, toggle: impl Into<Option<bool>>) -> Self {
self.toggle = toggle.into();
self
}
}
impl ParentElement for List {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
&mut self.children
}
}
impl RenderOnce for List {
type Rendered = Div;
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
v_stack()
.w_full()
.py_1()
.children(self.header.map(|header| header))
.map(|this| match (self.children.is_empty(), self.toggle) {
(false, _) => this.children(self.children),
(true, Some(false)) => this,
(true, _) => this.child(Label::new(self.empty_message.clone()).color(Color::Muted)),
})
}
}

View file

@ -0,0 +1,60 @@
use gpui::{AnyElement, Div};
use smallvec::SmallVec;
use crate::{prelude::*, v_stack, Label, ListHeader};
#[derive(IntoElement)]
pub struct List {
/// Message to display when the list is empty
/// Defaults to "No items"
empty_message: SharedString,
header: Option<ListHeader>,
toggle: Option<bool>,
children: SmallVec<[AnyElement; 2]>,
}
impl List {
pub fn new() -> Self {
Self {
empty_message: "No items".into(),
header: None,
toggle: None,
children: SmallVec::new(),
}
}
pub fn empty_message(mut self, empty_message: impl Into<SharedString>) -> Self {
self.empty_message = empty_message.into();
self
}
pub fn header(mut self, header: impl Into<Option<ListHeader>>) -> Self {
self.header = header.into();
self
}
pub fn toggle(mut self, toggle: impl Into<Option<bool>>) -> Self {
self.toggle = toggle.into();
self
}
}
impl ParentElement for List {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
&mut self.children
}
}
impl RenderOnce for List {
type Rendered = Div;
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
v_stack().w_full().py_1().children(self.header).map(|this| {
match (self.children.is_empty(), self.toggle) {
(false, _) => this.children(self.children),
(true, Some(false)) => this,
(true, _) => this.child(Label::new(self.empty_message.clone()).color(Color::Muted)),
}
})
}
}

View file

@ -1,22 +1,16 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::{ClickEvent, Div}; use gpui::{AnyElement, ClickEvent, Div};
use smallvec::SmallVec;
use crate::prelude::*; use crate::prelude::*;
use crate::{h_stack, Disclosure, Icon, IconButton, IconElement, IconSize, Label}; use crate::{h_stack, Disclosure, Icon, IconElement, IconSize, Label};
pub enum ListHeaderMeta {
Tools(Vec<IconButton>),
// TODO: This should be a button
Button(Label),
Text(Label),
}
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct ListHeader { pub struct ListHeader {
label: SharedString, label: SharedString,
left_icon: Option<Icon>, left_icon: Option<Icon>,
meta: Option<ListHeaderMeta>, meta: SmallVec<[AnyElement; 2]>,
toggle: Option<bool>, toggle: Option<bool>,
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>, on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
inset: bool, inset: bool,
@ -28,7 +22,7 @@ impl ListHeader {
Self { Self {
label: label.into(), label: label.into(),
left_icon: None, left_icon: None,
meta: None, meta: SmallVec::new(),
inset: false, inset: false,
toggle: None, toggle: None,
on_toggle: None, on_toggle: None,
@ -49,21 +43,19 @@ impl ListHeader {
self self
} }
pub fn left_icon(mut self, left_icon: Option<Icon>) -> Self { pub fn left_icon(mut self, left_icon: impl Into<Option<Icon>>) -> Self {
self.left_icon = left_icon; self.left_icon = left_icon.into();
self self
} }
pub fn right_button(self, button: IconButton) -> Self { pub fn meta(mut self, meta: impl IntoElement) -> Self {
self.meta(Some(ListHeaderMeta::Tools(vec![button]))) self.meta.push(meta.into_any_element());
}
pub fn meta(mut self, meta: Option<ListHeaderMeta>) -> Self {
self.meta = meta;
self self
} }
}
pub fn selected(mut self, selected: bool) -> Self { impl Selectable for ListHeader {
fn selected(mut self, selected: bool) -> Self {
self.selected = selected; self.selected = selected;
self self
} }
@ -73,18 +65,6 @@ impl RenderOnce for ListHeader {
type Rendered = Div; type Rendered = Div;
fn render(self, cx: &mut WindowContext) -> Self::Rendered { fn render(self, cx: &mut WindowContext) -> Self::Rendered {
let meta = match self.meta {
Some(ListHeaderMeta::Tools(icons)) => div().child(
h_stack()
.gap_2()
.items_center()
.children(icons.into_iter().map(|i| i.icon_color(Color::Muted))),
),
Some(ListHeaderMeta::Button(label)) => div().child(label),
Some(ListHeaderMeta::Text(label)) => div().child(label),
None => div(),
};
h_stack().w_full().relative().child( h_stack().w_full().relative().child(
div() div()
.h_5() .h_5()
@ -118,7 +98,7 @@ impl RenderOnce for ListHeader {
.map(|is_open| Disclosure::new(is_open).on_toggle(self.on_toggle)), .map(|is_open| Disclosure::new(is_open).on_toggle(self.on_toggle)),
), ),
) )
.child(meta), .child(h_stack().gap_2().items_center().children(self.meta)),
) )
} }
} }

View file

@ -83,11 +83,6 @@ impl ListItem {
self self
} }
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
pub fn left_child(mut self, left_content: impl IntoElement) -> Self { pub fn left_child(mut self, left_content: impl IntoElement) -> Self {
self.left_slot = Some(left_content.into_any_element()); self.left_slot = Some(left_content.into_any_element());
self self
@ -109,6 +104,13 @@ impl ListItem {
} }
} }
impl Selectable for ListItem {
fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
}
impl ParentElement for ListItem { impl ParentElement for ListItem {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
&mut self.children &mut self.children

View file

@ -8,6 +8,7 @@ mod icon_button;
mod keybinding; mod keybinding;
mod label; mod label;
mod list; mod list;
mod list_header;
mod list_item; mod list_item;
pub use avatar::*; pub use avatar::*;
@ -20,4 +21,5 @@ pub use icon_button::*;
pub use keybinding::*; pub use keybinding::*;
pub use label::*; pub use label::*;
pub use list::*; pub use list::*;
pub use list_header::*;
pub use list_item::*; pub use list_item::*;

View file

@ -2,7 +2,7 @@ use gpui::{Div, Render};
use story::Story; use story::Story;
use crate::prelude::*; use crate::prelude::*;
use crate::{Button, ButtonStyle2}; use crate::{Button, ButtonStyle};
pub struct ButtonStory; pub struct ButtonStory;
@ -14,9 +14,13 @@ impl Render for ButtonStory {
.child(Story::title_for::<Button>()) .child(Story::title_for::<Button>())
.child(Story::label("Default")) .child(Story::label("Default"))
.child(Button::new("default_filled", "Click me")) .child(Button::new("default_filled", "Click me"))
.child(Story::label("Selected"))
.child(Button::new("selected_filled", "Click me").selected(true))
.child(Story::label("With `label_color`"))
.child(Button::new("filled_with_label_color", "Click me").color(Color::Created))
.child(Story::label("Default (Subtle)")) .child(Story::label("Default (Subtle)"))
.child(Button::new("default_subtle", "Click me").style(ButtonStyle2::Subtle)) .child(Button::new("default_subtle", "Click me").style(ButtonStyle::Subtle))
.child(Story::label("Default (Transparent)")) .child(Story::label("Default (Transparent)"))
.child(Button::new("default_transparent", "Click me").style(ButtonStyle2::Transparent)) .child(Button::new("default_transparent", "Click me").style(ButtonStyle::Transparent))
} }
} }

View file

@ -22,12 +22,12 @@ impl Render for ListStory {
.child(Story::label("With sections")) .child(Story::label("With sections"))
.child( .child(
List::new() List::new()
.child(ListHeader::new("Fruits")) .header(ListHeader::new("Produce"))
.child(ListSubHeader::new("Fruits"))
.child(ListItem::new("apple").child("Apple")) .child(ListItem::new("apple").child("Apple"))
.child(ListItem::new("banana").child("Banana")) .child(ListItem::new("banana").child("Banana"))
.child(ListItem::new("cherry").child("Cherry")) .child(ListItem::new("cherry").child("Cherry"))
.child(ListSeparator) .child(ListSeparator)
.child(ListHeader::new("Vegetables"))
.child(ListSubHeader::new("Root Vegetables")) .child(ListSubHeader::new("Root Vegetables"))
.child(ListItem::new("carrot").child("Carrot")) .child(ListItem::new("carrot").child("Carrot"))
.child(ListItem::new("potato").child("Potato")) .child(ListItem::new("potato").child("Potato"))

View file

@ -0,0 +1,33 @@
use gpui::{Div, Render};
use story::Story;
use crate::{prelude::*, IconButton};
use crate::{Icon, ListHeader};
pub struct ListHeaderStory;
impl Render for ListHeaderStory {
type Element = Div;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
Story::container()
.child(Story::title_for::<ListHeader>())
.child(Story::label("Default"))
.child(ListHeader::new("Section 1"))
.child(Story::label("With left icon"))
.child(ListHeader::new("Section 2").left_icon(Icon::Bell))
.child(Story::label("With left icon and meta"))
.child(
ListHeader::new("Section 3")
.left_icon(Icon::BellOff)
.meta(IconButton::new("action_1", Icon::Bolt)),
)
.child(Story::label("With multiple meta"))
.child(
ListHeader::new("Section 4")
.meta(IconButton::new("action_1", Icon::Bolt))
.meta(IconButton::new("action_2", Icon::ExclamationTriangle))
.meta(IconButton::new("action_3", Icon::Plus)),
)
}
}

View file

@ -1,12 +0,0 @@
use gpui::{ImageSource, SharedString};
use crate::Icon;
/// A slot utility that provides a way to to pass either
/// an icon or an image to a component.
#[derive(Debug, Clone)]
pub enum GraphicSlot {
Icon(Icon),
Avatar(ImageSource),
PublicActor(SharedString),
}

View file

@ -18,7 +18,6 @@ mod disableable;
mod fixed; mod fixed;
pub mod prelude; pub mod prelude;
mod selectable; mod selectable;
mod slot;
mod styled_ext; mod styled_ext;
mod styles; mod styles;
pub mod utils; pub mod utils;
@ -29,6 +28,5 @@ pub use disableable::*;
pub use fixed::*; pub use fixed::*;
pub use prelude::*; pub use prelude::*;
pub use selectable::*; pub use selectable::*;
pub use slot::*;
pub use styled_ext::*; pub use styled_ext::*;
pub use styles::*; pub use styles::*;

View file

@ -1,14 +1,14 @@
use super::base_keymap_setting::BaseKeymap; use super::base_keymap_setting::BaseKeymap;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render, Task, actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, Task, View,
View, ViewContext, VisualContext, WeakView, ViewContext, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use project::Fs; use project::Fs;
use settings::{update_settings_file, Settings}; use settings::{update_settings_file, Settings};
use std::sync::Arc; use std::sync::Arc;
use ui::ListItem; use ui::{prelude::*, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ui::HighlightedLabel, Workspace}; use workspace::{ui::HighlightedLabel, Workspace};

View file

@ -10,29 +10,29 @@ doctest = false
[features] [features]
test-support = [ test-support = [
"call2/test-support", "call/test-support",
"client2/test-support", "client/test-support",
"project2/test-support", "project/test-support",
"settings2/test-support", "settings/test-support",
"gpui/test-support", "gpui/test-support",
"fs2/test-support" "fs/test-support"
] ]
[dependencies] [dependencies]
db2 = { path = "../db2" } db = { path = "../db2", package = "db2" }
client2 = { path = "../client2" } client = { path = "../client2", package = "client2" }
collections = { path = "../collections" } collections = { path = "../collections" }
# context_menu = { path = "../context_menu" } # context_menu = { path = "../context_menu" }
fs2 = { path = "../fs2" } fs = { path = "../fs2", package = "fs2" }
gpui = { package = "gpui2", path = "../gpui2" } gpui = { package = "gpui2", path = "../gpui2" }
install_cli2 = { path = "../install_cli2" } install_cli = { path = "../install_cli2", package = "install_cli2" }
language2 = { path = "../language2" } language = { path = "../language2", package = "language2" }
#menu = { path = "../menu" } #menu = { path = "../menu" }
node_runtime = { path = "../node_runtime" } node_runtime = { path = "../node_runtime" }
project2 = { path = "../project2" } project = { path = "../project2", package = "project2" }
settings2 = { path = "../settings2" } settings = { path = "../settings2", package = "settings2" }
terminal2 = { path = "../terminal2" } terminal = { path = "../terminal2", package = "terminal2" }
theme2 = { path = "../theme2" } theme = { path = "../theme2", package = "theme2" }
util = { path = "../util" } util = { path = "../util" }
ui = { package = "ui2", path = "../ui2" } ui = { package = "ui2", path = "../ui2" }
@ -54,13 +54,13 @@ smallvec.workspace = true
uuid.workspace = true uuid.workspace = true
[dev-dependencies] [dev-dependencies]
call2 = { path = "../call2", features = ["test-support"] } call = { path = "../call2", package = "call2", features = ["test-support"] }
client2 = { path = "../client2", features = ["test-support"] } client = { path = "../client2", package = "client2", features = ["test-support"] }
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] } gpui = { path = "../gpui2", package = "gpui2", features = ["test-support"] }
project2 = { path = "../project2", features = ["test-support"] } project = { path = "../project2", package = "project2", features = ["test-support"] }
settings2 = { path = "../settings2", features = ["test-support"] } settings = { path = "../settings2", package = "settings2", features = ["test-support"] }
fs2 = { path = "../fs2", features = ["test-support"] } fs = { path = "../fs2", package = "fs2", features = ["test-support"] }
db2 = { path = "../db2", features = ["test-support"] } db = { path = "../db2", package = "db2", features = ["test-support"] }
indoc.workspace = true indoc.workspace = true
env_logger.workspace = true env_logger.workspace = true

View file

@ -7,7 +7,7 @@ use crate::{
ViewId, Workspace, WorkspaceId, ViewId, Workspace, WorkspaceId,
}; };
use anyhow::Result; use anyhow::Result;
use client2::{ use client::{
proto::{self, PeerId}, proto::{self, PeerId},
Client, Client,
}; };
@ -16,10 +16,10 @@ use gpui::{
HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView, HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView,
WindowContext, WindowContext,
}; };
use project2::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings2::Settings; use settings::Settings;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
@ -33,7 +33,7 @@ use std::{
}, },
time::Duration, time::Duration,
}; };
use theme2::Theme; use theme::Theme;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct ItemSettings { pub struct ItemSettings {
@ -110,7 +110,7 @@ pub trait Item: FocusableView + EventEmitter<ItemEvent> {
fn for_each_project_item( fn for_each_project_item(
&self, &self,
_: &AppContext, _: &AppContext,
_: &mut dyn FnMut(EntityId, &dyn project2::Item), _: &mut dyn FnMut(EntityId, &dyn project::Item),
) { ) {
} }
fn is_singleton(&self, _cx: &AppContext) -> bool { fn is_singleton(&self, _cx: &AppContext) -> bool {
@ -222,7 +222,7 @@ pub trait ItemHandle: 'static + Send {
fn for_each_project_item( fn for_each_project_item(
&self, &self,
_: &AppContext, _: &AppContext,
_: &mut dyn FnMut(EntityId, &dyn project2::Item), _: &mut dyn FnMut(EntityId, &dyn project::Item),
); );
fn is_singleton(&self, cx: &AppContext) -> bool; fn is_singleton(&self, cx: &AppContext) -> bool;
fn boxed_clone(&self) -> Box<dyn ItemHandle>; fn boxed_clone(&self) -> Box<dyn ItemHandle>;
@ -347,7 +347,7 @@ impl<T: Item> ItemHandle for View<T> {
fn for_each_project_item( fn for_each_project_item(
&self, &self,
cx: &AppContext, cx: &AppContext,
f: &mut dyn FnMut(EntityId, &dyn project2::Item), f: &mut dyn FnMut(EntityId, &dyn project::Item),
) { ) {
self.read(cx).for_each_project_item(cx, f) self.read(cx).for_each_project_item(cx, f)
} }
@ -375,6 +375,7 @@ impl<T: Item> ItemHandle for View<T> {
pane: View<Pane>, pane: View<Pane>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) { ) {
let weak_item = self.downgrade();
let history = pane.read(cx).nav_history_for_item(self); let history = pane.read(cx).nav_history_for_item(self);
self.update(cx, |this, cx| { self.update(cx, |this, cx| {
this.set_nav_history(history, cx); this.set_nav_history(history, cx);
@ -491,16 +492,15 @@ impl<T: Item> ItemHandle for View<T> {
} }
})); }));
// todo!() cx.on_blur(&self.focus_handle(cx), move |workspace, cx| {
// cx.observe_focus(self, move |workspace, item, focused, cx| { if WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange {
// if !focused if let Some(item) = weak_item.upgrade() {
// && WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange Pane::autosave_item(&item, workspace.project.clone(), cx)
// { .detach_and_log_err(cx);
// Pane::autosave_item(&item, workspace.project.clone(), cx) }
// .detach_and_log_err(cx); }
// } })
// }) .detach();
// .detach();
let item_id = self.item_id(); let item_id = self.item_id();
cx.observe_release(self, move |workspace, _, _| { cx.observe_release(self, move |workspace, _, _| {
@ -640,7 +640,7 @@ impl<T: Item> WeakItemHandle for WeakView<T> {
} }
pub trait ProjectItem: Item { pub trait ProjectItem: Item {
type Item: project2::Item; type Item: project::Item;
fn for_project_item( fn for_project_item(
project: Model<Project>, project: Model<Project>,
@ -662,19 +662,19 @@ pub trait FollowableEvents {
pub trait FollowableItem: Item { pub trait FollowableItem: Item {
type FollowableEvent: FollowableEvents; type FollowableEvent: FollowableEvents;
fn remote_id(&self) -> Option<ViewId>; fn remote_id(&self) -> Option<ViewId>;
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>; fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant>;
fn from_state_proto( fn from_state_proto(
pane: View<Pane>, pane: View<Pane>,
project: View<Workspace>, project: View<Workspace>,
id: ViewId, id: ViewId,
state: &mut Option<proto::view::Variant>, state: &mut Option<proto::view::Variant>,
cx: &mut AppContext, cx: &mut WindowContext,
) -> Option<Task<Result<View<Self>>>>; ) -> Option<Task<Result<View<Self>>>>;
fn add_event_to_update_proto( fn add_event_to_update_proto(
&self, &self,
event: &Self::FollowableEvent, event: &Self::FollowableEvent,
update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
cx: &AppContext, cx: &WindowContext,
) -> bool; ) -> bool;
fn apply_update_proto( fn apply_update_proto(
&mut self, &mut self,
@ -682,20 +682,20 @@ pub trait FollowableItem: Item {
message: proto::update_view::Variant, message: proto::update_view::Variant,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Task<Result<()>>; ) -> Task<Result<()>>;
fn is_project_item(&self, cx: &AppContext) -> bool; fn is_project_item(&self, cx: &WindowContext) -> bool;
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>); fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
} }
pub trait FollowableItemHandle: ItemHandle { pub trait FollowableItemHandle: ItemHandle {
fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId>; fn remote_id(&self, client: &Arc<Client>, cx: &WindowContext) -> Option<ViewId>;
fn set_leader_peer_id(&self, leader_peer_id: Option<PeerId>, cx: &mut WindowContext); fn set_leader_peer_id(&self, leader_peer_id: Option<PeerId>, cx: &mut WindowContext);
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>; fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant>;
fn add_event_to_update_proto( fn add_event_to_update_proto(
&self, &self,
event: &dyn Any, event: &dyn Any,
update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
cx: &AppContext, cx: &WindowContext,
) -> bool; ) -> bool;
fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent>; fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent>;
fn apply_update_proto( fn apply_update_proto(
@ -704,11 +704,11 @@ pub trait FollowableItemHandle: ItemHandle {
message: proto::update_view::Variant, message: proto::update_view::Variant,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> Task<Result<()>>; ) -> Task<Result<()>>;
fn is_project_item(&self, cx: &AppContext) -> bool; fn is_project_item(&self, cx: &WindowContext) -> bool;
} }
impl<T: FollowableItem> FollowableItemHandle for View<T> { impl<T: FollowableItem> FollowableItemHandle for View<T> {
fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId> { fn remote_id(&self, client: &Arc<Client>, cx: &WindowContext) -> Option<ViewId> {
self.read(cx).remote_id().or_else(|| { self.read(cx).remote_id().or_else(|| {
client.peer_id().map(|creator| ViewId { client.peer_id().map(|creator| ViewId {
creator, creator,
@ -721,7 +721,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
self.update(cx, |this, cx| this.set_leader_peer_id(leader_peer_id, cx)) self.update(cx, |this, cx| this.set_leader_peer_id(leader_peer_id, cx))
} }
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant> { fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant> {
self.read(cx).to_state_proto(cx) self.read(cx).to_state_proto(cx)
} }
@ -729,7 +729,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
&self, &self,
event: &dyn Any, event: &dyn Any,
update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
cx: &AppContext, cx: &WindowContext,
) -> bool { ) -> bool {
if let Some(event) = event.downcast_ref() { if let Some(event) = event.downcast_ref() {
self.read(cx).add_event_to_update_proto(event, update, cx) self.read(cx).add_event_to_update_proto(event, update, cx)
@ -754,61 +754,57 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx)) self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
} }
fn is_project_item(&self, cx: &AppContext) -> bool { fn is_project_item(&self, cx: &WindowContext) -> bool {
self.read(cx).is_project_item(cx) self.read(cx).is_project_item(cx)
} }
} }
// #[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
// pub mod test { pub mod test {
// use super::{Item, ItemEvent}; use super::{Item, ItemEvent};
// use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId}; use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
// use gpui::{ use gpui::{
// elements::Empty, AnyElement, AppContext, Element, Entity, Model, Task, View, AnyElement, AppContext, Context as _, Div, EntityId, EventEmitter, FocusableView,
// ViewContext, View, WeakViewHandle, IntoElement, Model, Render, SharedString, Task, View, ViewContext, VisualContext, WeakView,
// }; };
// use project2::{Project, ProjectEntryId, ProjectPath, WorktreeId}; use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
// use smallvec::SmallVec; use std::{any::Any, cell::Cell, path::Path};
// use std::{any::Any, borrow::Cow, cell::Cell, path::Path};
// pub struct TestProjectItem { pub struct TestProjectItem {
// pub entry_id: Option<ProjectEntryId>, pub entry_id: Option<ProjectEntryId>,
// pub project_path: Option<ProjectPath>, pub project_path: Option<ProjectPath>,
// } }
// pub struct TestItem { pub struct TestItem {
// pub workspace_id: WorkspaceId, pub workspace_id: WorkspaceId,
// pub state: String, pub state: String,
// pub label: String, pub label: String,
// pub save_count: usize, pub save_count: usize,
// pub save_as_count: usize, pub save_as_count: usize,
// pub reload_count: usize, pub reload_count: usize,
// pub is_dirty: bool, pub is_dirty: bool,
// pub is_singleton: bool, pub is_singleton: bool,
// pub has_conflict: bool, pub has_conflict: bool,
// pub project_items: Vec<Model<TestProjectItem>>, pub project_items: Vec<Model<TestProjectItem>>,
// pub nav_history: Option<ItemNavHistory>, pub nav_history: Option<ItemNavHistory>,
// pub tab_descriptions: Option<Vec<&'static str>>, pub tab_descriptions: Option<Vec<&'static str>>,
// pub tab_detail: Cell<Option<usize>>, pub tab_detail: Cell<Option<usize>>,
// } focus_handle: gpui::FocusHandle,
}
// impl Entity for TestProjectItem { impl project::Item for TestProjectItem {
// type Event = (); fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
// } self.entry_id
}
// impl project2::Item for TestProjectItem { fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
// fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> { self.project_path.clone()
// self.entry_id }
// } }
// fn project_path(&self, _: &AppContext) -> Option<ProjectPath> { pub enum TestItemEvent {
// self.project_path.clone() Edit,
// } }
// }
// pub enum TestItemEvent {
// Edit,
// }
// impl Clone for TestItem { // impl Clone for TestItem {
// fn clone(&self) -> Self { // fn clone(&self) -> Self {
@ -826,233 +822,247 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
// tab_descriptions: None, // tab_descriptions: None,
// tab_detail: Default::default(), // tab_detail: Default::default(),
// workspace_id: self.workspace_id, // workspace_id: self.workspace_id,
// focus_handle: self.focus_handle.clone(),
// } // }
// } // }
// } // }
// impl TestProjectItem { impl TestProjectItem {
// pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> { pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> {
// let entry_id = Some(ProjectEntryId::from_proto(id)); let entry_id = Some(ProjectEntryId::from_proto(id));
// let project_path = Some(ProjectPath { let project_path = Some(ProjectPath {
// worktree_id: WorktreeId::from_usize(0), worktree_id: WorktreeId::from_usize(0),
// path: Path::new(path).into(), path: Path::new(path).into(),
// }); });
// cx.add_model(|_| Self { cx.build_model(|_| Self {
// entry_id, entry_id,
// project_path, project_path,
// }) })
// } }
// pub fn new_untitled(cx: &mut AppContext) -> Model<Self> { pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
// cx.add_model(|_| Self { cx.build_model(|_| Self {
// project_path: None, project_path: None,
// entry_id: None, entry_id: None,
// }) })
// } }
// } }
// impl TestItem { impl TestItem {
// pub fn new() -> Self { pub fn new(cx: &mut ViewContext<Self>) -> Self {
// Self { Self {
// state: String::new(), state: String::new(),
// label: String::new(), label: String::new(),
// save_count: 0, save_count: 0,
// save_as_count: 0, save_as_count: 0,
// reload_count: 0, reload_count: 0,
// is_dirty: false, is_dirty: false,
// has_conflict: false, has_conflict: false,
// project_items: Vec::new(), project_items: Vec::new(),
// is_singleton: true, is_singleton: true,
// nav_history: None, nav_history: None,
// tab_descriptions: None, tab_descriptions: None,
// tab_detail: Default::default(), tab_detail: Default::default(),
// workspace_id: 0, workspace_id: 0,
// } focus_handle: cx.focus_handle(),
// } }
}
// pub fn new_deserialized(id: WorkspaceId) -> Self { pub fn new_deserialized(id: WorkspaceId, cx: &mut ViewContext<Self>) -> Self {
// let mut this = Self::new(); let mut this = Self::new(cx);
// this.workspace_id = id; this.workspace_id = id;
// this this
// } }
// pub fn with_label(mut self, state: &str) -> Self { pub fn with_label(mut self, state: &str) -> Self {
// self.label = state.to_string(); self.label = state.to_string();
// self self
// } }
// pub fn with_singleton(mut self, singleton: bool) -> Self { pub fn with_singleton(mut self, singleton: bool) -> Self {
// self.is_singleton = singleton; self.is_singleton = singleton;
// self self
// } }
// pub fn with_dirty(mut self, dirty: bool) -> Self { pub fn with_dirty(mut self, dirty: bool) -> Self {
// self.is_dirty = dirty; self.is_dirty = dirty;
// self self
// } }
// pub fn with_conflict(mut self, has_conflict: bool) -> Self { pub fn with_conflict(mut self, has_conflict: bool) -> Self {
// self.has_conflict = has_conflict; self.has_conflict = has_conflict;
// self self
// } }
// pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self { pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self {
// self.project_items.clear(); self.project_items.clear();
// self.project_items.extend(items.iter().cloned()); self.project_items.extend(items.iter().cloned());
// self self
// } }
// pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) { pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) {
// self.push_to_nav_history(cx); self.push_to_nav_history(cx);
// self.state = state; self.state = state;
// } }
// fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) { fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) {
// if let Some(history) = &mut self.nav_history { if let Some(history) = &mut self.nav_history {
// history.push(Some(Box::new(self.state.clone())), cx); history.push(Some(Box::new(self.state.clone())), cx);
// } }
// } }
// } }
// impl Entity for TestItem { impl Render for TestItem {
// type Event = TestItemEvent; type Element = Div;
// }
// impl View for TestItem { fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element {
// fn ui_name() -> &'static str { gpui::div()
// "TestItem" }
// } }
// fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> { impl EventEmitter<ItemEvent> for TestItem {}
// Empty::new().into_any()
// }
// }
// impl Item for TestItem { impl FocusableView for TestItem {
// fn tab_description(&self, detail: usize, _: &AppContext) -> Option<Cow<str>> { fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
// self.tab_descriptions.as_ref().and_then(|descriptions| { self.focus_handle.clone()
// let description = *descriptions.get(detail).or_else(|| descriptions.last())?; }
// Some(description.into()) }
// })
// }
// fn tab_content<V: 'static>( impl Item for TestItem {
// &self, fn tab_description(&self, detail: usize, _: &AppContext) -> Option<SharedString> {
// detail: Option<usize>, self.tab_descriptions.as_ref().and_then(|descriptions| {
// _: &theme2::Tab, let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
// _: &AppContext, Some(description.into())
// ) -> AnyElement<V> { })
// self.tab_detail.set(detail); }
// Empty::new().into_any()
// }
// fn for_each_project_item( fn tab_content(
// &self, &self,
// cx: &AppContext, detail: Option<usize>,
// f: &mut dyn FnMut(usize, &dyn project2::Item), cx: &ui::prelude::WindowContext,
// ) { ) -> AnyElement {
// self.project_items self.tab_detail.set(detail);
// .iter() gpui::div().into_any_element()
// .for_each(|item| f(item.id(), item.read(cx))) }
// }
// fn is_singleton(&self, _: &AppContext) -> bool { fn for_each_project_item(
// self.is_singleton &self,
// } cx: &AppContext,
f: &mut dyn FnMut(EntityId, &dyn project::Item),
) {
self.project_items
.iter()
.for_each(|item| f(item.entity_id(), item.read(cx)))
}
// fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) { fn is_singleton(&self, _: &AppContext) -> bool {
// self.nav_history = Some(history); self.is_singleton
// } }
// fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool { fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
// let state = *state.downcast::<String>().unwrap_or_default(); self.nav_history = Some(history);
// if state != self.state { }
// self.state = state;
// true
// } else {
// false
// }
// }
// fn deactivated(&mut self, cx: &mut ViewContext<Self>) { fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
// self.push_to_nav_history(cx); let state = *state.downcast::<String>().unwrap_or_default();
// } if state != self.state {
self.state = state;
true
} else {
false
}
}
// fn clone_on_split( fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
// &self, self.push_to_nav_history(cx);
// _workspace_id: WorkspaceId, }
// _: &mut ViewContext<Self>,
// ) -> Option<Self>
// where
// Self: Sized,
// {
// Some(self.clone())
// }
// fn is_dirty(&self, _: &AppContext) -> bool { fn clone_on_split(
// self.is_dirty &self,
// } _workspace_id: WorkspaceId,
cx: &mut ViewContext<Self>,
) -> Option<View<Self>>
where
Self: Sized,
{
Some(cx.build_view(|cx| Self {
state: self.state.clone(),
label: self.label.clone(),
save_count: self.save_count,
save_as_count: self.save_as_count,
reload_count: self.reload_count,
is_dirty: self.is_dirty,
is_singleton: self.is_singleton,
has_conflict: self.has_conflict,
project_items: self.project_items.clone(),
nav_history: None,
tab_descriptions: None,
tab_detail: Default::default(),
workspace_id: self.workspace_id,
focus_handle: cx.focus_handle(),
}))
}
// fn has_conflict(&self, _: &AppContext) -> bool { fn is_dirty(&self, _: &AppContext) -> bool {
// self.has_conflict self.is_dirty
// } }
// fn can_save(&self, cx: &AppContext) -> bool { fn has_conflict(&self, _: &AppContext) -> bool {
// !self.project_items.is_empty() self.has_conflict
// && self }
// .project_items
// .iter()
// .all(|item| item.read(cx).entry_id.is_some())
// }
// fn save( fn can_save(&self, cx: &AppContext) -> bool {
// &mut self, !self.project_items.is_empty()
// _: Model<Project>, && self
// _: &mut ViewContext<Self>, .project_items
// ) -> Task<anyhow::Result<()>> { .iter()
// self.save_count += 1; .all(|item| item.read(cx).entry_id.is_some())
// self.is_dirty = false; }
// Task::ready(Ok(()))
// }
// fn save_as( fn save(
// &mut self, &mut self,
// _: Model<Project>, _: Model<Project>,
// _: std::path::PathBuf, _: &mut ViewContext<Self>,
// _: &mut ViewContext<Self>, ) -> Task<anyhow::Result<()>> {
// ) -> Task<anyhow::Result<()>> { self.save_count += 1;
// self.save_as_count += 1; self.is_dirty = false;
// self.is_dirty = false; Task::ready(Ok(()))
// Task::ready(Ok(())) }
// }
// fn reload( fn save_as(
// &mut self, &mut self,
// _: Model<Project>, _: Model<Project>,
// _: &mut ViewContext<Self>, _: std::path::PathBuf,
// ) -> Task<anyhow::Result<()>> { _: &mut ViewContext<Self>,
// self.reload_count += 1; ) -> Task<anyhow::Result<()>> {
// self.is_dirty = false; self.save_as_count += 1;
// Task::ready(Ok(())) self.is_dirty = false;
// } Task::ready(Ok(()))
}
// fn to_item_events(_: &Self::Event) -> SmallVec<[ItemEvent; 2]> { fn reload(
// [ItemEvent::UpdateTab, ItemEvent::Edit].into() &mut self,
// } _: Model<Project>,
_: &mut ViewContext<Self>,
) -> Task<anyhow::Result<()>> {
self.reload_count += 1;
self.is_dirty = false;
Task::ready(Ok(()))
}
// fn serialized_item_kind() -> Option<&'static str> { fn serialized_item_kind() -> Option<&'static str> {
// Some("TestItem") Some("TestItem")
// } }
// fn deserialize( fn deserialize(
// _project: Model<Project>, _project: Model<Project>,
// _workspace: WeakViewHandle<Workspace>, _workspace: WeakView<Workspace>,
// workspace_id: WorkspaceId, workspace_id: WorkspaceId,
// _item_id: ItemId, _item_id: ItemId,
// cx: &mut ViewContext<Pane>, cx: &mut ViewContext<Pane>,
// ) -> Task<anyhow::Result<View<Self>>> { ) -> Task<anyhow::Result<View<Self>>> {
// let view = cx.add_view(|_cx| Self::new_deserialized(workspace_id)); let view = cx.build_view(|cx| Self::new_deserialized(workspace_id, cx));
// Task::Ready(Some(anyhow::Ok(view))) Task::Ready(Some(anyhow::Ok(view)))
// } }
// } }
// } }

View file

@ -12,9 +12,9 @@ use gpui::{
ViewContext, VisualContext, WeakView, WindowContext, ViewContext, VisualContext, WeakView, WindowContext,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use project2::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize; use serde::Deserialize;
use settings2::Settings; use settings::Settings;
use std::{ use std::{
any::Any, any::Any,
cmp, fmt, mem, cmp, fmt, mem,
@ -457,6 +457,28 @@ impl Pane {
!self.nav_history.0.lock().forward_stack.is_empty() !self.nav_history.0.lock().forward_stack.is_empty()
} }
fn navigate_backward(&mut self, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade() {
let pane = cx.view().downgrade();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace.go_back(pane, cx).detach_and_log_err(cx)
})
})
}
}
fn navigate_forward(&mut self, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade() {
let pane = cx.view().downgrade();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace.go_forward(pane, cx).detach_and_log_err(cx)
})
})
}
}
fn history_updated(&mut self, cx: &mut ViewContext<Self>) { fn history_updated(&mut self, cx: &mut ViewContext<Self>) {
self.toolbar.update(cx, |_, cx| cx.notify()); self.toolbar.update(cx, |_, cx| cx.notify());
} }
@ -1483,12 +1505,20 @@ impl Pane {
.child( .child(
div().border().border_color(gpui::red()).child( div().border().border_color(gpui::red()).child(
IconButton::new("navigate_backward", Icon::ArrowLeft) IconButton::new("navigate_backward", Icon::ArrowLeft)
.on_click({
let view = cx.view().clone();
move |_, cx| view.update(cx, Self::navigate_backward)
})
.disabled(!self.can_navigate_backward()), .disabled(!self.can_navigate_backward()),
), ),
) )
.child( .child(
div().border().border_color(gpui::red()).child( div().border().border_color(gpui::red()).child(
IconButton::new("navigate_forward", Icon::ArrowRight) IconButton::new("navigate_forward", Icon::ArrowRight)
.on_click({
let view = cx.view().clone();
move |_, cx| view.update(cx, Self::navigate_backward)
})
.disabled(!self.can_navigate_forward()), .disabled(!self.can_navigate_forward()),
), ),
), ),
@ -1935,18 +1965,14 @@ impl Render for Pane {
v_stack() v_stack()
.key_context("Pane") .key_context("Pane")
.track_focus(&self.focus_handle) .track_focus(&self.focus_handle)
.on_action(cx.listener(|pane: &mut Pane, _: &SplitLeft, cx| { .on_action(cx.listener(|pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx)))
pane.split(SplitDirection::Left, cx) .on_action(cx.listener(|pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)))
}))
.on_action( .on_action(
cx.listener(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)), cx.listener(|pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)),
) )
.on_action(cx.listener(|pane: &mut Pane, _: &SplitRight, cx| { .on_action(cx.listener(|pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)))
pane.split(SplitDirection::Right, cx) .on_action(cx.listener(|pane, _: &GoBack, cx| pane.navigate_backward(cx)))
})) .on_action(cx.listener(|pane, _: &GoForward, cx| pane.navigate_forward(cx)))
.on_action(cx.listener(|pane: &mut Pane, _: &SplitDown, cx| {
pane.split(SplitDirection::Down, cx)
}))
// cx.add_action(Pane::toggle_zoom); // cx.add_action(Pane::toggle_zoom);
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| { // cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
// pane.activate_item(action.0, true, true, cx); // pane.activate_item(action.0, true, true, cx);

View file

@ -1,7 +1,7 @@
use crate::{AppState, FollowerState, Pane, Workspace}; use crate::{AppState, FollowerState, Pane, Workspace};
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use collections::HashMap; use collections::HashMap;
use db2::sqlez::{ use db::sqlez::{
bindable::{Bind, Column, StaticColumnCount}, bindable::{Bind, Column, StaticColumnCount},
statement::Statement, statement::Statement,
}; };
@ -9,7 +9,7 @@ use gpui::{
point, size, AnyWeakView, Bounds, Div, IntoElement, Model, Pixels, Point, View, ViewContext, point, size, AnyWeakView, Bounds, Div, IntoElement, Model, Pixels, Point, View, ViewContext,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use project2::Project; use project::Project;
use serde::Deserialize; use serde::Deserialize;
use std::sync::Arc; use std::sync::Arc;
use ui::prelude::*; use ui::prelude::*;

View file

@ -5,7 +5,7 @@ pub mod model;
use std::path::Path; use std::path::Path;
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use db2::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql}; use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
use gpui::WindowBounds; use gpui::WindowBounds;
use util::{unzip_option, ResultExt}; use util::{unzip_option, ResultExt};
@ -552,7 +552,7 @@ impl WorkspaceDb {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use db2::open_test_db; use db::open_test_db;
use gpui; use gpui;
#[gpui::test] #[gpui::test]

View file

@ -3,12 +3,12 @@ use crate::{
}; };
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use async_recursion::async_recursion; use async_recursion::async_recursion;
use db2::sqlez::{ use db::sqlez::{
bindable::{Bind, Column, StaticColumnCount}, bindable::{Bind, Column, StaticColumnCount},
statement::Statement, statement::Statement,
}; };
use gpui::{AsyncWindowContext, Model, Task, View, WeakView, WindowBounds}; use gpui::{AsyncWindowContext, Model, Task, View, WeakView, WindowBounds};
use project2::Project; use project::Project;
use std::{ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,

View file

@ -4,7 +4,7 @@ use gpui::{
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView, AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView,
WindowContext, WindowContext,
}; };
use project2::search::SearchQuery; use project::search::SearchQuery;
use crate::{ use crate::{
item::{Item, WeakItemHandle}, item::{Item, WeakItemHandle},

View file

@ -52,16 +52,7 @@ impl Render for StatusBar {
h_stack() h_stack()
.gap_4() .gap_4()
.child( .child(
h_stack() h_stack().gap_1().child(
.gap_1()
.child(
// TODO: Line / column numbers
div()
.border()
.border_color(gpui::red())
.child(Button::new("status_line_column_numbers", "15:22")),
)
.child(
// TODO: Language picker // TODO: Language picker
div() div()
.border() .border()
@ -133,7 +124,7 @@ impl StatusBar {
h_stack() h_stack()
.items_center() .items_center()
.gap_2() .gap_2()
.children(self.right_items.iter().map(|item| item.to_any())) .children(self.right_items.iter().rev().map(|item| item.to_any()))
} }
} }

View file

@ -80,7 +80,6 @@ impl Render for Toolbar {
type Element = Div; type Element = Div;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
//dbg!(&self.items.len());
v_stack() v_stack()
.border_b() .border_b()
.border_color(cx.theme().colors().border_variant) .border_color(cx.theme().colors().border_variant)

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings2::Settings; use settings::Settings;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct WorkspaceSettings { pub struct WorkspaceSettings {

View file

@ -105,6 +105,7 @@ impl LspAdapter for JsonLspAdapter {
fn workspace_configuration( fn workspace_configuration(
&self, &self,
_workspace_root: &Path,
cx: &mut AppContext, cx: &mut AppContext,
) -> BoxFuture<'static, serde_json::Value> { ) -> BoxFuture<'static, serde_json::Value> {
let action_names = cx.all_action_names().collect::<Vec<_>>(); let action_names = cx.all_action_names().collect::<Vec<_>>();

View file

@ -29,7 +29,6 @@ pub struct IntelephenseLspAdapter {
impl IntelephenseLspAdapter { impl IntelephenseLspAdapter {
const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js"; const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js";
#[allow(unused)]
pub fn new(node: Arc<dyn NodeRuntime>) -> Self { pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
Self { node } Self { node }
} }

View file

@ -107,7 +107,11 @@ impl LspAdapter for TailwindLspAdapter {
})) }))
} }
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
_workspace_root: &Path,
_: &mut AppContext,
) -> BoxFuture<'static, Value> {
future::ready(json!({ future::ready(json!({
"tailwindCSS": { "tailwindCSS": {
"emmetCompletions": true, "emmetCompletions": true,

View file

@ -205,7 +205,6 @@ pub struct EsLintLspAdapter {
impl EsLintLspAdapter { impl EsLintLspAdapter {
const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js"; const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js";
#[allow(unused)]
pub fn new(node: Arc<dyn NodeRuntime>) -> Self { pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
EsLintLspAdapter { node } EsLintLspAdapter { node }
} }
@ -213,13 +212,23 @@ impl EsLintLspAdapter {
#[async_trait] #[async_trait]
impl LspAdapter for EsLintLspAdapter { impl LspAdapter for EsLintLspAdapter {
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
workspace_root: &Path,
_: &mut AppContext,
) -> BoxFuture<'static, Value> {
future::ready(json!({ future::ready(json!({
"": { "": {
"validate": "on", "validate": "on",
"rulesCustomizations": [], "rulesCustomizations": [],
"run": "onType", "run": "onType",
"nodePath": null, "nodePath": null,
"workingDirectory": {"mode": "auto"},
"workspaceFolder": {
"uri": workspace_root,
"name": workspace_root.file_name()
.unwrap_or_else(|| workspace_root.as_os_str()),
},
} }
})) }))
.boxed() .boxed()

View file

@ -93,7 +93,11 @@ impl LspAdapter for YamlLspAdapter {
) -> Option<LanguageServerBinary> { ) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &*self.node).await get_cached_server_binary(container_dir, &*self.node).await
} }
fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
_workspace_root: &Path,
cx: &mut AppContext,
) -> BoxFuture<'static, Value> {
let tab_size = all_language_settings(None, cx) let tab_size = all_language_settings(None, cx)
.language(Some("YAML")) .language(Some("YAML"))
.tab_size; .tab_size;

View file

@ -105,6 +105,7 @@ impl LspAdapter for JsonLspAdapter {
fn workspace_configuration( fn workspace_configuration(
&self, &self,
_workspace_root: &Path,
cx: &mut AppContext, cx: &mut AppContext,
) -> BoxFuture<'static, serde_json::Value> { ) -> BoxFuture<'static, serde_json::Value> {
let action_names = cx.all_action_names(); let action_names = cx.all_action_names();

View file

@ -29,7 +29,6 @@ pub struct IntelephenseLspAdapter {
impl IntelephenseLspAdapter { impl IntelephenseLspAdapter {
const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js"; const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js";
#[allow(unused)]
pub fn new(node: Arc<dyn NodeRuntime>) -> Self { pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
Self { node } Self { node }
} }

View file

@ -107,7 +107,11 @@ impl LspAdapter for TailwindLspAdapter {
})) }))
} }
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
_workspace_root: &Path,
_: &mut AppContext,
) -> BoxFuture<'static, Value> {
future::ready(json!({ future::ready(json!({
"tailwindCSS": { "tailwindCSS": {
"emmetCompletions": true, "emmetCompletions": true,

View file

@ -205,7 +205,6 @@ pub struct EsLintLspAdapter {
impl EsLintLspAdapter { impl EsLintLspAdapter {
const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js"; const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js";
#[allow(unused)]
pub fn new(node: Arc<dyn NodeRuntime>) -> Self { pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
EsLintLspAdapter { node } EsLintLspAdapter { node }
} }
@ -213,13 +212,23 @@ impl EsLintLspAdapter {
#[async_trait] #[async_trait]
impl LspAdapter for EsLintLspAdapter { impl LspAdapter for EsLintLspAdapter {
fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
workspace_root: &Path,
_: &mut AppContext,
) -> BoxFuture<'static, Value> {
future::ready(json!({ future::ready(json!({
"": { "": {
"validate": "on", "validate": "on",
"rulesCustomizations": [], "rulesCustomizations": [],
"run": "onType", "run": "onType",
"nodePath": null, "nodePath": null,
"workingDirectory": {"mode": "auto"},
"workspaceFolder": {
"uri": workspace_root,
"name": workspace_root.file_name()
.unwrap_or_else(|| workspace_root.as_os_str()),
},
} }
})) }))
.boxed() .boxed()

View file

@ -93,7 +93,11 @@ impl LspAdapter for YamlLspAdapter {
) -> Option<LanguageServerBinary> { ) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &*self.node).await get_cached_server_binary(container_dir, &*self.node).await
} }
fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { fn workspace_configuration(
&self,
_workspace_root: &Path,
cx: &mut AppContext,
) -> BoxFuture<'static, Value> {
let tab_size = all_language_settings(None, cx) let tab_size = all_language_settings(None, cx)
.language(Some("YAML")) .language(Some("YAML"))
.tab_size; .tab_size;

View file

@ -746,9 +746,9 @@ fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
} }
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
async fn watch_languages(_: Arc<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()> { async fn watch_languages(_: Arc<dyn fs::Fs>, _: Arc<LanguageRegistry>) -> Option<()> {
None None
} }
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
fn watch_file_types(_fs: Arc<dyn Fs>, _cx: &mut AppContext) {} fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut AppContext) {}

View file

@ -147,7 +147,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
// let feedback_button = cx.add_view(|_| { // let feedback_button = cx.add_view(|_| {
// feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace) // feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)
// }); // });
// let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new()); let cursor_position = cx.build_view(|_| editor::items::CursorPosition::new());
workspace.status_bar().update(cx, |status_bar, cx| { workspace.status_bar().update(cx, |status_bar, cx| {
status_bar.add_left_item(diagnostic_summary, cx); status_bar.add_left_item(diagnostic_summary, cx);
status_bar.add_left_item(activity_indicator, cx); status_bar.add_left_item(activity_indicator, cx);
@ -156,7 +156,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
// status_bar.add_right_item(copilot, cx); // status_bar.add_right_item(copilot, cx);
// status_bar.add_right_item(active_buffer_language, cx); // status_bar.add_right_item(active_buffer_language, cx);
// status_bar.add_right_item(vim_mode_indicator, cx); // status_bar.add_right_item(vim_mode_indicator, cx);
// status_bar.add_right_item(cursor_position, cx); status_bar.add_right_item(cursor_position, cx);
}); });
auto_update::notify_of_any_new_update(cx); auto_update::notify_of_any_new_update(cx);