Detailed changes
@@ -12,7 +12,7 @@ use gpui::{
AppContext, Entity, ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View,
ViewContext, ViewHandle,
};
-use postage::{prelude::Stream, watch};
+use postage::prelude::Stream;
use std::sync::Arc;
use time::{OffsetDateTime, UtcOffset};
use util::{ResultExt, TryFutureExt};
@@ -27,7 +27,6 @@ pub struct ChatPanel {
message_list: ListState,
input_editor: ViewHandle<Editor>,
channel_select: ViewHandle<Select>,
- settings: watch::Receiver<Settings>,
local_timezone: UtcOffset,
_observe_status: Task<()>,
}
@@ -48,42 +47,33 @@ impl ChatPanel {
pub fn new(
rpc: Arc<Client>,
channel_list: ModelHandle<ChannelList>,
- settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let input_editor = cx.add_view(|cx| {
- let mut editor = Editor::auto_height(
- 4,
- settings.clone(),
- Some(|theme| theme.chat_panel.input_editor.clone()),
- cx,
- );
+ let mut editor =
+ Editor::auto_height(4, Some(|theme| theme.chat_panel.input_editor.clone()), cx);
editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx);
editor
});
let channel_select = cx.add_view(|cx| {
let channel_list = channel_list.clone();
Select::new(0, cx, {
- let settings = settings.clone();
move |ix, item_type, is_hovered, cx| {
Self::render_channel_name(
&channel_list,
ix,
item_type,
is_hovered,
- &settings.borrow().theme.chat_panel.channel_select,
+ &cx.app_state::<Settings>().theme.chat_panel.channel_select,
cx,
)
}
})
- .with_style({
- let settings = settings.clone();
- move |_| {
- let theme = &settings.borrow().theme.chat_panel.channel_select;
- SelectStyle {
- header: theme.header.container.clone(),
- menu: theme.menu.clone(),
- }
+ .with_style(move |cx| {
+ let theme = &cx.app_state::<Settings>().theme.chat_panel.channel_select;
+ SelectStyle {
+ header: theme.header.container.clone(),
+ menu: theme.menu.clone(),
}
})
});
@@ -93,7 +83,7 @@ impl ChatPanel {
move |ix, cx| {
let this = this.upgrade(cx).unwrap().read(cx);
let message = this.active_channel.as_ref().unwrap().0.read(cx).message(ix);
- this.render_message(message)
+ this.render_message(message, cx)
}
});
message_list.set_scroll_handler(|visible_range, cx| {
@@ -121,7 +111,6 @@ impl ChatPanel {
message_list,
input_editor,
channel_select,
- settings,
local_timezone: cx.platform().local_timezone(),
_observe_status,
};
@@ -210,8 +199,8 @@ impl ChatPanel {
cx.notify();
}
- fn render_channel(&self) -> ElementBox {
- let theme = &self.settings.borrow().theme;
+ fn render_channel(&self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let theme = &cx.app_state::<Settings>().theme;
Flex::column()
.with_child(
Container::new(ChildView::new(&self.channel_select).boxed())
@@ -219,7 +208,7 @@ impl ChatPanel {
.boxed(),
)
.with_child(self.render_active_channel_messages())
- .with_child(self.render_input_box())
+ .with_child(self.render_input_box(cx))
.boxed()
}
@@ -233,9 +222,9 @@ impl ChatPanel {
Flexible::new(1., true, messages).boxed()
}
- fn render_message(&self, message: &ChannelMessage) -> ElementBox {
+ fn render_message(&self, message: &ChannelMessage, cx: &AppContext) -> ElementBox {
let now = OffsetDateTime::now_utc();
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
let theme = if message.is_pending() {
&settings.theme.chat_panel.pending_message
} else {
@@ -277,8 +266,8 @@ impl ChatPanel {
.boxed()
}
- fn render_input_box(&self) -> ElementBox {
- let theme = &self.settings.borrow().theme;
+ fn render_input_box(&self, cx: &AppContext) -> ElementBox {
+ let theme = &cx.app_state::<Settings>().theme;
Container::new(ChildView::new(&self.input_editor).boxed())
.with_style(theme.chat_panel.input_editor.container)
.boxed()
@@ -315,7 +304,7 @@ impl ChatPanel {
}
fn render_sign_in_prompt(&self, cx: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme;
+ let theme = cx.app_state::<Settings>().theme.clone();
let rpc = self.rpc.clone();
let this = cx.handle();
@@ -391,12 +380,12 @@ impl View for ChatPanel {
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme;
let element = if self.rpc.user_id().is_some() {
- self.render_channel()
+ self.render_channel(cx)
} else {
self.render_sign_in_prompt(cx)
};
+ let theme = &cx.app_state::<Settings>().theme;
ConstrainedBox::new(
Container::new(element)
.with_style(theme.chat_panel.container)
@@ -8,13 +8,11 @@ use gpui::{
Element, ElementBox, Entity, LayoutContext, ModelHandle, RenderContext, Subscription, View,
ViewContext,
};
-use postage::watch;
use workspace::{AppState, JoinProject, JoinProjectParams, Settings};
pub struct ContactsPanel {
contacts: ListState,
user_store: ModelHandle<UserStore>,
- settings: watch::Receiver<Settings>,
_maintain_contacts: Subscription,
}
@@ -42,7 +40,6 @@ impl ContactsPanel {
),
_maintain_contacts: cx.observe(&app_state.user_store, Self::update_contacts),
user_store: app_state.user_store.clone(),
- settings: app_state.settings.clone(),
}
}
@@ -58,7 +55,8 @@ impl ContactsPanel {
app_state: Arc<AppState>,
cx: &mut LayoutContext,
) -> ElementBox {
- let theme = &app_state.settings.borrow().theme.contacts_panel;
+ let theme = cx.app_state::<Settings>().theme.clone();
+ let theme = &theme.contacts_panel;
let project_count = collaborator.projects.len();
let font_cache = cx.font_cache();
let line_height = theme.unshared_project.name.text.line_height(font_cache);
@@ -237,8 +235,8 @@ impl View for ContactsPanel {
"ContactsPanel"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme.contacts_panel;
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let theme = &cx.app_state::<Settings>().theme.contacts_panel;
Container::new(List::new(self.contacts.clone()).boxed())
.with_style(theme.container)
.boxed()
@@ -15,7 +15,6 @@ use gpui::{
use language::{
Bias, Buffer, Diagnostic, DiagnosticEntry, DiagnosticSeverity, Point, Selection, SelectionGoal,
};
-use postage::watch;
use project::{DiagnosticSummary, Project, ProjectPath};
use std::{
any::{Any, TypeId},
@@ -26,7 +25,7 @@ use std::{
sync::Arc,
};
use util::TryFutureExt;
-use workspace::{ItemHandle, ItemNavHistory, ItemViewHandle as _, Workspace};
+use workspace::{ItemHandle, ItemNavHistory, ItemViewHandle as _, Settings, Workspace};
action!(Deploy);
@@ -51,7 +50,6 @@ struct ProjectDiagnosticsEditor {
excerpts: ModelHandle<MultiBuffer>,
path_states: Vec<PathState>,
paths_to_update: BTreeSet<ProjectPath>,
- settings: watch::Receiver<workspace::Settings>,
}
struct PathState {
@@ -86,9 +84,9 @@ impl View for ProjectDiagnosticsEditor {
"ProjectDiagnosticsEditor"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
if self.path_states.is_empty() {
- let theme = &self.settings.borrow().theme.project_diagnostics;
+ let theme = &cx.app_state::<Settings>().theme.project_diagnostics;
Label::new(
"No problems in workspace".to_string(),
theme.empty_message.clone(),
@@ -113,7 +111,6 @@ impl ProjectDiagnosticsEditor {
fn new(
model: ModelHandle<ProjectDiagnostics>,
workspace: WeakViewHandle<Workspace>,
- settings: watch::Receiver<workspace::Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let project = model.read(cx).project.clone();
@@ -131,12 +128,7 @@ impl ProjectDiagnosticsEditor {
let excerpts = cx.add_model(|cx| MultiBuffer::new(project.read(cx).replica_id()));
let editor = cx.add_view(|cx| {
- let mut editor = Editor::for_buffer(
- excerpts.clone(),
- Some(project.clone()),
- settings.clone(),
- cx,
- );
+ let mut editor = Editor::for_buffer(excerpts.clone(), Some(project.clone()), cx);
editor.set_vertical_scroll_margin(5, cx);
editor
});
@@ -151,7 +143,6 @@ impl ProjectDiagnosticsEditor {
workspace,
excerpts,
editor,
- settings,
path_states: Default::default(),
paths_to_update,
};
@@ -303,10 +294,7 @@ impl ProjectDiagnosticsEditor {
blocks_to_add.push(BlockProperties {
position: header_position,
height: 2,
- render: diagnostic_header_renderer(
- primary,
- self.settings.clone(),
- ),
+ render: diagnostic_header_renderer(primary),
disposition: BlockDisposition::Above,
});
}
@@ -324,11 +312,7 @@ impl ProjectDiagnosticsEditor {
blocks_to_add.push(BlockProperties {
position: (excerpt_id.clone(), entry.range.start.clone()),
height: diagnostic.message.matches('\n').count() as u8 + 1,
- render: diagnostic_block_renderer(
- diagnostic,
- true,
- self.settings.clone(),
- ),
+ render: diagnostic_block_renderer(diagnostic, true),
disposition: BlockDisposition::Below,
});
}
@@ -466,12 +450,7 @@ impl workspace::Item for ProjectDiagnostics {
nav_history: ItemNavHistory,
cx: &mut ViewContext<Self::View>,
) -> Self::View {
- let diagnostics = ProjectDiagnosticsEditor::new(
- handle,
- workspace.weak_handle(),
- workspace.settings(),
- cx,
- );
+ let diagnostics = ProjectDiagnosticsEditor::new(handle, workspace.weak_handle(), cx);
diagnostics
.editor
.update(cx, |editor, _| editor.set_nav_history(Some(nav_history)));
@@ -488,11 +467,11 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
Box::new(self.model.clone())
}
- fn tab_content(&self, style: &theme::Tab, _: &AppContext) -> ElementBox {
+ fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox {
render_summary(
&self.summary,
&style.label.text,
- &self.settings.borrow().theme.project_diagnostics,
+ &cx.app_state::<Settings>().theme.project_diagnostics,
)
}
@@ -554,12 +533,8 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
where
Self: Sized,
{
- let diagnostics = ProjectDiagnosticsEditor::new(
- self.model.clone(),
- self.workspace.clone(),
- self.settings.clone(),
- cx,
- );
+ let diagnostics =
+ ProjectDiagnosticsEditor::new(self.model.clone(), self.workspace.clone(), cx);
diagnostics.editor.update(cx, |editor, _| {
editor.set_nav_history(Some(nav_history));
});
@@ -586,13 +561,10 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
}
}
-fn diagnostic_header_renderer(
- diagnostic: Diagnostic,
- settings: watch::Receiver<workspace::Settings>,
-) -> RenderBlock {
+fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let (message, highlights) = highlight_diagnostic_message(&diagnostic.message);
Arc::new(move |cx| {
- let settings = settings.borrow();
+ let settings = cx.app_state::<Settings>();
let theme = &settings.theme.editor;
let style = &theme.diagnostic_header;
let font_size = (style.text_scale_factor * settings.buffer_font_size).round();
@@ -852,7 +824,7 @@ mod tests {
// Open the project diagnostics view while there are already diagnostics.
let model = cx.add_model(|_| ProjectDiagnostics::new(project.clone()));
let view = cx.add_view(0, |cx| {
- ProjectDiagnosticsEditor::new(model, workspace.downgrade(), params.settings, cx)
+ ProjectDiagnosticsEditor::new(model, workspace.downgrade(), cx)
});
view.next_notification(&cx).await;
@@ -2,22 +2,16 @@ use crate::render_summary;
use gpui::{
elements::*, platform::CursorStyle, Entity, ModelHandle, RenderContext, View, ViewContext,
};
-use postage::watch;
use project::Project;
use workspace::{Settings, StatusItemView};
pub struct DiagnosticSummary {
- settings: watch::Receiver<Settings>,
summary: project::DiagnosticSummary,
in_progress: bool,
}
impl DiagnosticSummary {
- pub fn new(
- project: &ModelHandle<Project>,
- settings: watch::Receiver<Settings>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ pub fn new(project: &ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
cx.subscribe(project, |this, project, event, cx| match event {
project::Event::DiskBasedDiagnosticsUpdated => {
cx.notify();
@@ -35,7 +29,6 @@ impl DiagnosticSummary {
})
.detach();
Self {
- settings,
summary: project.read(cx).diagnostic_summary(cx),
in_progress: project.read(cx).is_running_disk_based_diagnostics(),
}
@@ -54,10 +47,9 @@ impl View for DiagnosticSummary {
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
enum Tag {}
- let theme = &self.settings.borrow().theme.project_diagnostics;
-
let in_progress = self.in_progress;
- MouseEventHandler::new::<Tag, _, _>(0, cx, |_, _| {
+ MouseEventHandler::new::<Tag, _, _>(0, cx, |_, cx| {
+ let theme = &cx.app_state::<Settings>().theme.project_diagnostics;
if in_progress {
Label::new(
"Checking... ".to_string(),
@@ -40,7 +40,6 @@ pub use multi_buffer::{
Anchor, AnchorRangeExt, ExcerptId, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
};
use ordered_float::OrderedFloat;
-use postage::watch;
use project::{Project, ProjectTransaction};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
@@ -428,7 +427,6 @@ pub struct Editor {
scroll_position: Vector2F,
scroll_top_anchor: Option<Anchor>,
autoscroll_request: Option<Autoscroll>,
- settings: watch::Receiver<Settings>,
soft_wrap_mode_override: Option<settings::SoftWrap>,
get_field_editor_theme: Option<GetFieldEditorTheme>,
project: Option<ModelHandle<Project>>,
@@ -795,25 +793,16 @@ pub struct NavigationData {
impl Editor {
pub fn single_line(
- settings: watch::Receiver<Settings>,
field_editor_style: Option<GetFieldEditorTheme>,
cx: &mut ViewContext<Self>,
) -> Self {
let buffer = cx.add_model(|cx| Buffer::new(0, String::new(), cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- Self::new(
- EditorMode::SingleLine,
- buffer,
- None,
- settings,
- field_editor_style,
- cx,
- )
+ Self::new(EditorMode::SingleLine, buffer, None, field_editor_style, cx)
}
pub fn auto_height(
max_lines: usize,
- settings: watch::Receiver<Settings>,
field_editor_style: Option<GetFieldEditorTheme>,
cx: &mut ViewContext<Self>,
) -> Self {
@@ -823,7 +812,6 @@ impl Editor {
EditorMode::AutoHeight { max_lines },
buffer,
None,
- settings,
field_editor_style,
cx,
)
@@ -832,10 +820,9 @@ impl Editor {
pub fn for_buffer(
buffer: ModelHandle<MultiBuffer>,
project: Option<ModelHandle<Project>>,
- settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
- Self::new(EditorMode::Full, buffer, project, settings, None, cx)
+ Self::new(EditorMode::Full, buffer, project, None, cx)
}
pub fn clone(&self, nav_history: ItemNavHistory, cx: &mut ViewContext<Self>) -> Self {
@@ -843,7 +830,6 @@ impl Editor {
self.mode,
self.buffer.clone(),
self.project.clone(),
- self.settings.clone(),
self.get_field_editor_theme,
cx,
);
@@ -858,13 +844,12 @@ impl Editor {
mode: EditorMode,
buffer: ModelHandle<MultiBuffer>,
project: Option<ModelHandle<Project>>,
- settings: watch::Receiver<Settings>,
get_field_editor_theme: Option<GetFieldEditorTheme>,
cx: &mut ViewContext<Self>,
) -> Self {
let display_map = cx.add_model(|cx| {
- let settings = settings.borrow();
- let style = build_style(&*settings, get_field_editor_theme, cx);
+ let settings = cx.app_state::<Settings>();
+ let style = build_style(settings, get_field_editor_theme, cx);
DisplayMap::new(
buffer.clone(),
settings.tab_size,
@@ -905,7 +890,6 @@ impl Editor {
snippet_stack: Default::default(),
select_larger_syntax_node_stack: Vec::new(),
active_diagnostics: None,
- settings,
soft_wrap_mode_override: None,
get_field_editor_theme,
project,
@@ -982,7 +966,7 @@ impl Editor {
}
fn style(&self, cx: &AppContext) -> EditorStyle {
- build_style(&*self.settings.borrow(), self.get_field_editor_theme, cx)
+ build_style(cx.app_state::<Settings>(), self.get_field_editor_theme, cx)
}
pub fn set_placeholder_text(
@@ -2691,7 +2675,7 @@ impl Editor {
}
self.start_transaction(cx);
- let tab_size = self.settings.borrow().tab_size;
+ let tab_size = cx.app_state::<Settings>().tab_size;
let mut selections = self.local_selections::<Point>(cx);
let mut last_indent = None;
self.buffer.update(cx, |buffer, cx| {
@@ -2768,7 +2752,7 @@ impl Editor {
}
self.start_transaction(cx);
- let tab_size = self.settings.borrow().tab_size;
+ let tab_size = cx.app_state::<Settings>().tab_size;
let selections = self.local_selections::<Point>(cx);
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let mut deletion_ranges = Vec::new();
@@ -4404,7 +4388,7 @@ impl Editor {
// Position the selection in the rename editor so that it matches the current selection.
let rename_editor = cx.add_view(|cx| {
- let mut editor = Editor::single_line(this.settings.clone(), None, cx);
+ let mut editor = Editor::single_line(None, cx);
editor
.buffer
.update(cx, |buffer, cx| buffer.edit([0..0], &old_name, cx));
@@ -4588,11 +4572,7 @@ impl Editor {
for (block_id, diagnostic) in &active_diagnostics.blocks {
new_styles.insert(
*block_id,
- diagnostic_block_renderer(
- diagnostic.clone(),
- is_valid,
- self.settings.clone(),
- ),
+ diagnostic_block_renderer(diagnostic.clone(), is_valid),
);
}
self.display_map
@@ -4635,11 +4615,7 @@ impl Editor {
BlockProperties {
position: buffer.anchor_after(entry.range.start),
height: message_height,
- render: diagnostic_block_renderer(
- diagnostic,
- true,
- self.settings.clone(),
- ),
+ render: diagnostic_block_renderer(diagnostic, true),
disposition: BlockDisposition::Below,
}
}),
@@ -5257,7 +5233,7 @@ impl Editor {
pub fn soft_wrap_mode(&self, cx: &AppContext) -> SoftWrap {
let language = self.language(cx);
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
let mode = self
.soft_wrap_mode_override
.unwrap_or_else(|| settings.soft_wrap(language));
@@ -5799,18 +5775,14 @@ impl Deref for EditorStyle {
}
}
-pub fn diagnostic_block_renderer(
- diagnostic: Diagnostic,
- is_valid: bool,
- settings: watch::Receiver<Settings>,
-) -> RenderBlock {
+pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock {
let mut highlighted_lines = Vec::new();
for line in diagnostic.message.lines() {
highlighted_lines.push(highlight_diagnostic_message(line));
}
Arc::new(move |cx: &BlockContext| {
- let settings = settings.borrow();
+ let settings = cx.app_state::<Settings>();
let theme = &settings.theme.editor;
let style = diagnostic_style(diagnostic.severity, is_valid, theme);
let font_size = (style.text_scale_factor * settings.buffer_font_size).round();
@@ -6005,14 +5977,12 @@ mod tests {
#[gpui::test]
fn test_undo_redo_with_selection_restoration(cx: &mut MutableAppContext) {
+ populate_settings(cx);
let mut now = Instant::now();
let buffer = cx.add_model(|cx| language::Buffer::new(0, "123456", cx));
let group_interval = buffer.read(cx).transaction_group_interval();
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let settings = Settings::test(cx);
- let (_, editor) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, editor) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
editor.update(cx, |editor, cx| {
editor.start_transaction_at(now, cx);
@@ -6076,10 +6046,9 @@ mod tests {
#[gpui::test]
fn test_selection_with_mouse(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);
- let settings = Settings::test(cx);
- let (_, editor) =
- cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, editor) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
editor.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(2, 2), false, 1, cx);
@@ -6143,9 +6112,9 @@ mod tests {
#[gpui::test]
fn test_canceling_pending_selection(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);
- let settings = Settings::test(cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(2, 2), false, 1, cx);
@@ -6175,12 +6144,13 @@ mod tests {
#[gpui::test]
fn test_navigation_history(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
+ use workspace::ItemView;
+ let nav_history = Rc::new(RefCell::new(workspace::NavHistory::default()));
+ let buffer = MultiBuffer::build_simple(&sample_text(30, 5, 'a'), cx);
+
cx.add_window(Default::default(), |cx| {
- use workspace::ItemView;
- let nav_history = Rc::new(RefCell::new(workspace::NavHistory::default()));
- let settings = Settings::test(&cx);
- let buffer = MultiBuffer::build_simple(&sample_text(30, 5, 'a'), cx);
- let mut editor = build_editor(buffer.clone(), settings, cx);
+ let mut editor = build_editor(buffer.clone(), cx);
editor.nav_history = Some(ItemNavHistory::new(nav_history.clone(), &cx.handle()));
// Move the cursor a small distance.
@@ -6232,9 +6202,9 @@ mod tests {
#[gpui::test]
fn test_cancel(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);
- let settings = Settings::test(cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.begin_selection(DisplayPoint::new(3, 4), false, 1, cx);
@@ -6272,6 +6242,7 @@ mod tests {
#[gpui::test]
fn test_fold(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(
&"
impl Foo {
@@ -6293,10 +6264,7 @@ mod tests {
.unindent(),
cx,
);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(8, 0)..DisplayPoint::new(12, 0)], cx);
@@ -6359,11 +6327,9 @@ mod tests {
#[gpui::test]
fn test_move_cursor(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
buffer.update(cx, |buffer, cx| {
buffer.edit(
@@ -6435,11 +6401,9 @@ mod tests {
#[gpui::test]
fn test_move_cursor_multibyte(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("βββββ\nabcde\nαβγδΡ\n", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
assert_eq!('β'.len_utf8(), 3);
assert_eq!('Ξ±'.len_utf8(), 2);
@@ -6538,11 +6502,9 @@ mod tests {
#[gpui::test]
fn test_move_cursor_different_line_lengths(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("βββββ\nabcd\nΞ±Ξ²Ξ³\nabcd\nβββββ\n", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
view.select_display_ranges(&[empty_range(0, "βββββ".len())], cx);
view.move_down(&MoveDown, cx);
@@ -6585,9 +6547,9 @@ mod tests {
#[gpui::test]
fn test_beginning_end_of_line(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\n def", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -6726,9 +6688,9 @@ mod tests {
#[gpui::test]
fn test_prev_next_word_boundary(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("use std::str::{foo, bar}\n\n {baz.qux()}", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -6864,9 +6826,9 @@ mod tests {
#[gpui::test]
fn test_prev_next_word_bounds_with_soft_wrap(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("use one::{\n two::three::four::five\n};", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.set_wrap_width(Some(140.), cx);
@@ -6917,11 +6879,9 @@ mod tests {
#[gpui::test]
fn test_delete_to_word_boundary(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("one two three four", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
@@ -6956,11 +6916,9 @@ mod tests {
#[gpui::test]
fn test_newline(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("aaaa\n bbbb\n", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
@@ -6979,6 +6937,7 @@ mod tests {
#[gpui::test]
fn test_newline_with_old_selections(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(
"
a
@@ -6994,9 +6953,8 @@ mod tests {
cx,
);
- let settings = Settings::test(&cx);
let (_, editor) = cx.add_window(Default::default(), |cx| {
- let mut editor = build_editor(buffer.clone(), settings, cx);
+ let mut editor = build_editor(buffer.clone(), cx);
editor.select_ranges(
[
Point::new(2, 4)..Point::new(2, 5),
@@ -7064,11 +7022,10 @@ mod tests {
#[gpui::test]
fn test_insert_with_old_selections(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx);
-
- let settings = Settings::test(&cx);
let (_, editor) = cx.add_window(Default::default(), |cx| {
- let mut editor = build_editor(buffer.clone(), settings, cx);
+ let mut editor = build_editor(buffer.clone(), cx);
editor.select_ranges([3..4, 11..12, 19..20], None, cx);
editor
});
@@ -7092,11 +7049,9 @@ mod tests {
#[gpui::test]
fn test_indent_outdent(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(" one two\nthree\n four", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
// two selections on the same line
@@ -7168,9 +7123,9 @@ mod tests {
#[gpui::test]
fn test_backspace(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(MultiBuffer::build_simple("", cx), settings, cx)
+ build_editor(MultiBuffer::build_simple("", cx), cx)
});
view.update(cx, |view, cx| {
@@ -7213,12 +7168,10 @@ mod tests {
#[gpui::test]
fn test_delete(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer =
MultiBuffer::build_simple("one two three\nfour five six\nseven eight nine\nten\n", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
@@ -7243,9 +7196,9 @@ mod tests {
#[gpui::test]
fn test_delete_line(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -7266,9 +7219,9 @@ mod tests {
);
});
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(2, 0)..DisplayPoint::new(0, 1)], cx);
view.delete_line(&DeleteLine, cx);
@@ -7282,9 +7235,9 @@ mod tests {
#[gpui::test]
fn test_duplicate_line(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -7308,9 +7261,8 @@ mod tests {
);
});
- let settings = Settings::test(&cx);
let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -7333,9 +7285,9 @@ mod tests {
#[gpui::test]
fn test_move_line_up_down(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.fold_ranges(
vec![
@@ -7429,11 +7381,10 @@ mod tests {
#[gpui::test]
fn test_move_line_up_down_with_blocks(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);
let snapshot = buffer.read(cx).snapshot(cx);
- let (_, editor) =
- cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, editor) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
editor.update(cx, |editor, cx| {
editor.insert_blocks(
[BlockProperties {
@@ -7451,12 +7402,10 @@ mod tests {
#[gpui::test]
fn test_clipboard(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("oneβ
two three four five six ", cx);
- let settings = Settings::test(&cx);
let view = cx
- .add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- })
+ .add_window(Default::default(), |cx| build_editor(buffer.clone(), cx))
.1;
// Cut with three selections. Clipboard text is divided into three slices.
@@ -7582,9 +7531,9 @@ mod tests {
#[gpui::test]
fn test_select_all(cx: &mut gpui::MutableAppContext) {
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\nde\nfgh", cx);
- let settings = Settings::test(&cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_all(&SelectAll, cx);
assert_eq!(
@@ -7596,9 +7545,9 @@ mod tests {
#[gpui::test]
fn test_select_line(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(&sample_text(6, 5, 'a'), cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
@@ -7641,9 +7590,9 @@ mod tests {
#[gpui::test]
fn test_split_selection_into_lines(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple(&sample_text(9, 5, 'a'), cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.fold_ranges(
vec![
@@ -7707,9 +7656,9 @@ mod tests {
#[gpui::test]
fn test_add_selection_above_below(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(&cx);
+ populate_settings(cx);
let buffer = MultiBuffer::build_simple("abc\ndefghi\n\njk\nlmno\n", cx);
- let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(buffer, cx));
view.update(cx, |view, cx| {
view.select_display_ranges(&[DisplayPoint::new(1, 3)..DisplayPoint::new(1, 3)], cx);
@@ -7876,7 +7825,7 @@ mod tests {
#[gpui::test]
async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let language = Arc::new(Language::new(
LanguageConfig::default(),
Some(tree_sitter_rust::language()),
@@ -7893,7 +7842,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
@@ -8017,7 +7966,7 @@ mod tests {
#[gpui::test]
async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let language = Arc::new(
Language::new(
LanguageConfig {
@@ -8052,7 +8001,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));
editor
.condition(&cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx))
.await;
@@ -8074,7 +8023,7 @@ mod tests {
#[gpui::test]
async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let language = Arc::new(Language::new(
LanguageConfig {
brackets: vec![
@@ -8106,7 +8055,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
@@ -8217,7 +8166,7 @@ mod tests {
#[gpui::test]
async fn test_snippets(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let text = "
a. b
@@ -8226,7 +8175,7 @@ mod tests {
"
.unindent();
let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));
- let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));
editor.update(cx, |editor, cx| {
let buffer = &editor.snapshot(cx).buffer_snapshot;
@@ -8324,7 +8273,7 @@ mod tests {
#[gpui::test]
async fn test_completion(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let (mut language_server_config, mut fake_servers) = LanguageServerConfig::fake();
language_server_config.set_fake_capabilities(lsp::ServerCapabilities {
@@ -8372,7 +8321,7 @@ mod tests {
let mut fake_server = fake_servers.next().await.unwrap();
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, editor) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));
editor.update(cx, |editor, cx| {
editor.project = Some(project);
@@ -8558,7 +8507,7 @@ mod tests {
#[gpui::test]
async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let language = Arc::new(Language::new(
LanguageConfig {
line_comment: Some("// ".to_string()),
@@ -8578,7 +8527,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.update(cx, |editor, cx| {
// If multiple selections intersect a line, the line is only
@@ -8638,7 +8587,7 @@ mod tests {
#[gpui::test]
fn test_editing_disjoint_excerpts(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(cx);
+ populate_settings(cx);
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(3, 4, 'a'), cx));
let multibuffer = cx.add_model(|cx| {
let mut multibuffer = MultiBuffer::new(0);
@@ -8655,9 +8604,7 @@ mod tests {
assert_eq!(multibuffer.read(cx).read(cx).text(), "aaaa\nbbbb");
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(multibuffer, settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(multibuffer, cx));
view.update(cx, |view, cx| {
assert_eq!(view.text(cx), "aaaa\nbbbb");
view.select_ranges(
@@ -8683,7 +8630,7 @@ mod tests {
#[gpui::test]
fn test_editing_overlapping_excerpts(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(cx);
+ populate_settings(cx);
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(3, 4, 'a'), cx));
let multibuffer = cx.add_model(|cx| {
let mut multibuffer = MultiBuffer::new(0);
@@ -8703,9 +8650,7 @@ mod tests {
"aaaa\nbbbb\nbbbb\ncccc"
);
- let (_, view) = cx.add_window(Default::default(), |cx| {
- build_editor(multibuffer, settings, cx)
- });
+ let (_, view) = cx.add_window(Default::default(), |cx| build_editor(multibuffer, cx));
view.update(cx, |view, cx| {
view.select_ranges(
[
@@ -8740,7 +8685,7 @@ mod tests {
#[gpui::test]
fn test_refresh_selections(cx: &mut gpui::MutableAppContext) {
- let settings = Settings::test(cx);
+ populate_settings(cx);
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(3, 4, 'a'), cx));
let mut excerpt1_id = None;
let multibuffer = cx.add_model(|cx| {
@@ -8763,7 +8708,7 @@ mod tests {
"aaaa\nbbbb\nbbbb\ncccc"
);
let (_, editor) = cx.add_window(Default::default(), |cx| {
- let mut editor = build_editor(multibuffer.clone(), settings, cx);
+ let mut editor = build_editor(multibuffer.clone(), cx);
editor.select_ranges(
[
Point::new(1, 3)..Point::new(1, 3),
@@ -8815,7 +8760,7 @@ mod tests {
#[gpui::test]
async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {
- let settings = cx.read(Settings::test);
+ cx.update(populate_settings);
let language = Arc::new(Language::new(
LanguageConfig {
brackets: vec![
@@ -8847,7 +8792,7 @@ mod tests {
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
- let (_, view) = cx.add_window(|cx| build_editor(buffer, settings, cx));
+ let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
view.condition(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await;
@@ -8883,10 +8828,8 @@ mod tests {
#[gpui::test]
fn test_highlighted_ranges(cx: &mut gpui::MutableAppContext) {
let buffer = MultiBuffer::build_simple(&sample_text(16, 8, 'a'), cx);
- let settings = Settings::test(&cx);
- let (_, editor) = cx.add_window(Default::default(), |cx| {
- build_editor(buffer.clone(), settings, cx)
- });
+ populate_settings(cx);
+ let (_, editor) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
editor.update(cx, |editor, cx| {
struct Type1;
@@ -9036,13 +8979,13 @@ mod tests {
point..point
}
- fn build_editor(
- buffer: ModelHandle<MultiBuffer>,
- settings: Settings,
- cx: &mut ViewContext<Editor>,
- ) -> Editor {
- let settings = watch::channel_with(settings);
- Editor::new(EditorMode::Full, buffer, None, settings.1, None, cx)
+ fn build_editor(buffer: ModelHandle<MultiBuffer>, cx: &mut ViewContext<Editor>) -> Editor {
+ Editor::new(EditorMode::Full, buffer, None, None, cx)
+ }
+
+ fn populate_settings(cx: &mut gpui::MutableAppContext) {
+ let settings = Settings::test(cx);
+ cx.add_app_state(settings);
}
}
@@ -1378,16 +1378,15 @@ fn scale_horizontal_mouse_autoscroll_delta(delta: f32) -> f32 {
mod tests {
use super::*;
use crate::{Editor, MultiBuffer};
- use postage::watch;
use util::test::sample_text;
use workspace::Settings;
#[gpui::test]
fn test_layout_line_numbers(cx: &mut gpui::MutableAppContext) {
- let settings = watch::channel_with(Settings::test(cx));
+ cx.add_app_state(Settings::test(cx));
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
let (window_id, editor) = cx.add_window(Default::default(), |cx| {
- Editor::new(EditorMode::Full, buffer, None, settings.1, None, cx)
+ Editor::new(EditorMode::Full, buffer, None, None, cx)
});
let element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx));
@@ -5,7 +5,6 @@ use gpui::{
Subscription, Task, View, ViewContext, ViewHandle, WeakModelHandle,
};
use language::{Bias, Buffer, Diagnostic, File as _};
-use postage::watch;
use project::{File, Project, ProjectPath};
use std::path::PathBuf;
use std::rc::Rc;
@@ -57,12 +56,7 @@ impl ItemHandle for BufferItemHandle {
) -> Box<dyn ItemViewHandle> {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(self.0.clone(), cx));
Box::new(cx.add_view(window_id, |cx| {
- let mut editor = Editor::for_buffer(
- buffer,
- Some(workspace.project().clone()),
- workspace.settings(),
- cx,
- );
+ let mut editor = Editor::for_buffer(buffer, Some(workspace.project().clone()), cx);
editor.nav_history = Some(ItemNavHistory::new(nav_history, &cx.handle()));
editor
}))
@@ -101,12 +95,8 @@ impl ItemHandle for MultiBufferItemHandle {
cx: &mut MutableAppContext,
) -> Box<dyn ItemViewHandle> {
Box::new(cx.add_view(window_id, |cx| {
- let mut editor = Editor::for_buffer(
- self.0.clone(),
- Some(workspace.project().clone()),
- workspace.settings(),
- cx,
- );
+ let mut editor =
+ Editor::for_buffer(self.0.clone(), Some(workspace.project().clone()), cx);
editor.nav_history = Some(ItemNavHistory::new(nav_history, &cx.handle()));
editor
}))
@@ -288,16 +278,14 @@ impl ItemView for Editor {
pub struct CursorPosition {
position: Option<Point>,
selected_count: usize,
- settings: watch::Receiver<Settings>,
_observe_active_editor: Option<Subscription>,
}
impl CursorPosition {
- pub fn new(settings: watch::Receiver<Settings>) -> Self {
+ pub fn new() -> Self {
Self {
position: None,
selected_count: 0,
- settings,
_observe_active_editor: None,
}
}
@@ -332,9 +320,9 @@ impl View for CursorPosition {
"CursorPosition"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
if let Some(position) = self.position {
- let theme = &self.settings.borrow().theme.workspace.status_bar;
+ let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
let mut text = format!("{},{}", position.row + 1, position.column + 1);
if self.selected_count > 0 {
write!(text, " ({} selected)", self.selected_count).unwrap();
@@ -365,16 +353,14 @@ impl StatusItemView for CursorPosition {
}
pub struct DiagnosticMessage {
- settings: watch::Receiver<Settings>,
diagnostic: Option<Diagnostic>,
_observe_active_editor: Option<Subscription>,
}
impl DiagnosticMessage {
- pub fn new(settings: watch::Receiver<Settings>) -> Self {
+ pub fn new() -> Self {
Self {
diagnostic: None,
- settings,
_observe_active_editor: None,
}
}
@@ -407,9 +393,9 @@ impl View for DiagnosticMessage {
"DiagnosticMessage"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
if let Some(diagnostic) = &self.diagnostic {
- let theme = &self.settings.borrow().theme.workspace.status_bar;
+ let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
Label::new(
diagnostic.message.split('\n').next().unwrap().to_string(),
theme.diagnostic_message.clone(),
@@ -7,7 +7,6 @@ use gpui::{
AppContext, Axis, Entity, ModelHandle, MutableAppContext, RenderContext, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
};
-use postage::watch;
use project::{Project, ProjectPath, WorktreeId};
use std::{
cmp,
@@ -25,7 +24,6 @@ use workspace::{
pub struct FileFinder {
handle: WeakViewHandle<Self>,
- settings: watch::Receiver<Settings>,
project: ModelHandle<Project>,
query_editor: ViewHandle<Editor>,
search_count: usize,
@@ -68,9 +66,8 @@ impl View for FileFinder {
"FileFinder"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
-
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let settings = cx.app_state::<Settings>();
Align::new(
ConstrainedBox::new(
Container::new(
@@ -81,7 +78,7 @@ impl View for FileFinder {
.with_style(settings.theme.selector.input_editor.container)
.boxed(),
)
- .with_child(Flexible::new(1.0, false, self.render_matches()).boxed())
+ .with_child(Flexible::new(1.0, false, self.render_matches(cx)).boxed())
.boxed(),
)
.with_style(settings.theme.selector.container)
@@ -107,9 +104,9 @@ impl View for FileFinder {
}
impl FileFinder {
- fn render_matches(&self) -> ElementBox {
+ fn render_matches(&self, cx: &AppContext) -> ElementBox {
if self.matches.is_empty() {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
return Container::new(
Label::new(
"No matches".into(),
@@ -122,32 +119,30 @@ impl FileFinder {
}
let handle = self.handle.clone();
- let list = UniformList::new(
- self.list_state.clone(),
- self.matches.len(),
- move |mut range, items, cx| {
- let cx = cx.as_ref();
- let finder = handle.upgrade(cx).unwrap();
- let finder = finder.read(cx);
- let start = range.start;
- range.end = cmp::min(range.end, finder.matches.len());
- items.extend(
- finder.matches[range]
- .iter()
- .enumerate()
- .map(move |(i, path_match)| finder.render_match(path_match, start + i)),
- );
- },
- );
+ let list =
+ UniformList::new(
+ self.list_state.clone(),
+ self.matches.len(),
+ move |mut range, items, cx| {
+ let cx = cx.as_ref();
+ let finder = handle.upgrade(cx).unwrap();
+ let finder = finder.read(cx);
+ let start = range.start;
+ range.end = cmp::min(range.end, finder.matches.len());
+ items.extend(finder.matches[range].iter().enumerate().map(
+ move |(i, path_match)| finder.render_match(path_match, start + i, cx),
+ ));
+ },
+ );
Container::new(list.boxed())
.with_margin_top(6.0)
.named("matches")
}
- fn render_match(&self, path_match: &PathMatch, index: usize) -> ElementBox {
+ fn render_match(&self, path_match: &PathMatch, index: usize, cx: &AppContext) -> ElementBox {
let selected_index = self.selected_index();
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
let style = if index == selected_index {
&settings.theme.selector.active_item
} else {
@@ -233,7 +228,7 @@ impl FileFinder {
fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) {
workspace.toggle_modal(cx, |cx, workspace| {
let project = workspace.project().clone();
- let finder = cx.add_view(|cx| Self::new(workspace.settings.clone(), project, cx));
+ let finder = cx.add_view(|cx| Self::new(project, cx));
cx.subscribe(&finder, Self::on_event).detach();
finder
});
@@ -258,26 +253,17 @@ impl FileFinder {
}
}
- pub fn new(
- settings: watch::Receiver<Settings>,
- project: ModelHandle<Project>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ pub fn new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
cx.observe(&project, Self::project_updated).detach();
let query_editor = cx.add_view(|cx| {
- Editor::single_line(
- settings.clone(),
- Some(|theme| theme.selector.input_editor.clone()),
- cx,
- )
+ Editor::single_line(Some(|theme| theme.selector.input_editor.clone()), cx)
});
cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach();
Self {
handle: cx.weak_handle(),
- settings,
project,
query_editor,
search_count: 0,
@@ -524,13 +510,8 @@ mod tests {
.unwrap();
cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
.await;
- let (_, finder) = cx.add_window(|cx| {
- FileFinder::new(
- params.settings.clone(),
- workspace.read(cx).project().clone(),
- cx,
- )
- });
+ let (_, finder) =
+ cx.add_window(|cx| FileFinder::new(workspace.read(cx).project().clone(), cx));
let query = "hi".to_string();
finder
@@ -590,13 +571,8 @@ mod tests {
.unwrap();
cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
.await;
- let (_, finder) = cx.add_window(|cx| {
- FileFinder::new(
- params.settings.clone(),
- workspace.read(cx).project().clone(),
- cx,
- )
- });
+ let (_, finder) =
+ cx.add_window(|cx| FileFinder::new(workspace.read(cx).project().clone(), cx));
// Even though there is only one worktree, that worktree's filename
// is included in the matching, because the worktree is a single file.
@@ -653,13 +629,8 @@ mod tests {
cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
.await;
- let (_, finder) = cx.add_window(|cx| {
- FileFinder::new(
- params.settings.clone(),
- workspace.read(cx).project().clone(),
- cx,
- )
- });
+ let (_, finder) =
+ cx.add_window(|cx| FileFinder::new(workspace.read(cx).project().clone(), cx));
// Run a search that matches two files with the same relative path.
finder
@@ -3,7 +3,6 @@ use gpui::{
action, elements::*, geometry::vector::Vector2F, keymap::Binding, Axis, Entity,
MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
};
-use postage::watch;
use text::{Bias, Point};
use workspace::{Settings, Workspace};
@@ -21,7 +20,6 @@ pub fn init(cx: &mut MutableAppContext) {
}
pub struct GoToLine {
- settings: watch::Receiver<Settings>,
line_editor: ViewHandle<Editor>,
active_editor: ViewHandle<Editor>,
prev_scroll_position: Option<Vector2F>,
@@ -34,17 +32,9 @@ pub enum Event {
}
impl GoToLine {
- pub fn new(
- active_editor: ViewHandle<Editor>,
- settings: watch::Receiver<Settings>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ pub fn new(active_editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) -> Self {
let line_editor = cx.add_view(|cx| {
- Editor::single_line(
- settings.clone(),
- Some(|theme| theme.selector.input_editor.clone()),
- cx,
- )
+ Editor::single_line(Some(|theme| theme.selector.input_editor.clone()), cx)
});
cx.subscribe(&line_editor, Self::on_line_editor_event)
.detach();
@@ -60,7 +50,6 @@ impl GoToLine {
});
Self {
- settings: settings.clone(),
line_editor,
active_editor,
prev_scroll_position: scroll_position,
@@ -71,8 +60,8 @@ impl GoToLine {
fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) {
if let Some(editor) = workspace.active_item(cx).unwrap().downcast::<Editor>() {
- workspace.toggle_modal(cx, |cx, workspace| {
- let view = cx.add_view(|cx| GoToLine::new(editor, workspace.settings.clone(), cx));
+ workspace.toggle_modal(cx, |cx, _| {
+ let view = cx.add_view(|cx| GoToLine::new(editor, cx));
cx.subscribe(&view, Self::on_event).detach();
view
});
@@ -156,8 +145,8 @@ impl View for GoToLine {
"GoToLine"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme.selector;
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let theme = &cx.app_state::<Settings>().theme.selector;
let label = format!(
"{},{} of {} lines",
@@ -13,7 +13,6 @@ use gpui::{
};
use language::Outline;
use ordered_float::OrderedFloat;
-use postage::watch;
use std::cmp::{self, Reverse};
use workspace::{
menu::{Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev},
@@ -44,7 +43,6 @@ struct OutlineView {
matches: Vec<StringMatch>,
query_editor: ViewHandle<Editor>,
list_state: UniformListState,
- settings: watch::Receiver<Settings>,
}
pub enum Event {
@@ -70,8 +68,8 @@ impl View for OutlineView {
cx
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let settings = cx.app_state::<Settings>();
Flex::new(Axis::Vertical)
.with_child(
@@ -79,7 +77,7 @@ impl View for OutlineView {
.with_style(settings.theme.selector.input_editor.container)
.boxed(),
)
- .with_child(Flexible::new(1.0, false, self.render_matches()).boxed())
+ .with_child(Flexible::new(1.0, false, self.render_matches(cx)).boxed())
.contained()
.with_style(settings.theme.selector.container)
.constrained()
@@ -99,15 +97,10 @@ impl OutlineView {
fn new(
outline: Outline<Anchor>,
editor: ViewHandle<Editor>,
- settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let query_editor = cx.add_view(|cx| {
- Editor::single_line(
- settings.clone(),
- Some(|theme| theme.selector.input_editor.clone()),
- cx,
- )
+ Editor::single_line(Some(|theme| theme.selector.input_editor.clone()), cx)
});
cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach();
@@ -121,7 +114,6 @@ impl OutlineView {
outline,
query_editor,
list_state: Default::default(),
- settings,
};
this.update_matches(cx);
this
@@ -132,16 +124,12 @@ impl OutlineView {
.active_item(cx)
.and_then(|item| item.downcast::<Editor>())
{
- let settings = workspace.settings();
- let buffer = editor
- .read(cx)
- .buffer()
- .read(cx)
- .read(cx)
- .outline(Some(settings.borrow().theme.editor.syntax.as_ref()));
+ let buffer = editor.read(cx).buffer().read(cx).read(cx).outline(Some(
+ cx.app_state::<Settings>().theme.editor.syntax.as_ref(),
+ ));
if let Some(outline) = buffer {
workspace.toggle_modal(cx, |cx, _| {
- let view = cx.add_view(|cx| OutlineView::new(outline, editor, settings, cx));
+ let view = cx.add_view(|cx| OutlineView::new(outline, editor, cx));
cx.subscribe(&view, Self::on_event).detach();
view
});
@@ -298,9 +286,9 @@ impl OutlineView {
self.select(selected_index, navigate_to_selected_index, true, cx);
}
- fn render_matches(&self) -> ElementBox {
+ fn render_matches(&self, cx: &AppContext) -> ElementBox {
if self.matches.is_empty() {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
return Container::new(
Label::new(
"No matches".into(),
@@ -326,7 +314,7 @@ impl OutlineView {
view.matches[range]
.iter()
.enumerate()
- .map(move |(ix, m)| view.render_match(m, start + ix)),
+ .map(move |(ix, m)| view.render_match(m, start + ix, cx)),
);
},
);
@@ -336,8 +324,13 @@ impl OutlineView {
.named("matches")
}
- fn render_match(&self, string_match: &StringMatch, index: usize) -> ElementBox {
- let settings = self.settings.borrow();
+ fn render_match(
+ &self,
+ string_match: &StringMatch,
+ index: usize,
+ cx: &AppContext,
+ ) -> ElementBox {
+ let settings = cx.app_state::<Settings>();
let style = if index == self.selected_match_index {
&settings.theme.selector.active_item
} else {
@@ -9,7 +9,6 @@ use gpui::{
AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, View, ViewContext,
ViewHandle, WeakViewHandle,
};
-use postage::watch;
use project::{Project, ProjectEntry, ProjectPath, Worktree, WorktreeId};
use std::{
collections::{hash_map, HashMap},
@@ -27,7 +26,6 @@ pub struct ProjectPanel {
visible_entries: Vec<(WorktreeId, Vec<usize>)>,
expanded_dir_ids: HashMap<WorktreeId, Vec<usize>>,
selection: Option<Selection>,
- settings: watch::Receiver<Settings>,
handle: WeakViewHandle<Self>,
}
@@ -73,11 +71,7 @@ pub enum Event {
}
impl ProjectPanel {
- pub fn new(
- project: ModelHandle<Project>,
- settings: watch::Receiver<Settings>,
- cx: &mut ViewContext<Workspace>,
- ) -> ViewHandle<Self> {
+ pub fn new(project: ModelHandle<Project>, cx: &mut ViewContext<Workspace>) -> ViewHandle<Self> {
let project_panel = cx.add_view(|cx: &mut ViewContext<Self>| {
cx.observe(&project, |this, _, cx| {
this.update_visible_entries(None, cx);
@@ -105,7 +99,6 @@ impl ProjectPanel {
let mut this = Self {
project: project.clone(),
- settings,
list: Default::default(),
visible_entries: Default::default(),
expanded_dir_ids: Default::default(),
@@ -541,9 +534,9 @@ impl View for ProjectPanel {
"ProjectPanel"
}
- fn render(&mut self, _: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
- let settings = self.settings.clone();
- let mut container_style = settings.borrow().theme.project_panel.container;
+ fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
+ let theme = &cx.app_state::<Settings>().theme.project_panel;
+ let mut container_style = theme.container;
let padding = std::mem::take(&mut container_style.padding);
let handle = self.handle.clone();
UniformList::new(
@@ -553,11 +546,11 @@ impl View for ProjectPanel {
.map(|(_, worktree_entries)| worktree_entries.len())
.sum(),
move |range, items, cx| {
- let theme = &settings.borrow().theme.project_panel;
+ let theme = cx.app_state::<Settings>().theme.clone();
let this = handle.upgrade(cx).unwrap();
this.update(cx.app, |this, cx| {
this.for_each_visible_entry(range.clone(), cx, |entry, details, cx| {
- items.push(Self::render_entry(entry, details, theme, cx));
+ items.push(Self::render_entry(entry, details, &theme.project_panel, cx));
});
})
},
@@ -593,7 +586,6 @@ mod tests {
cx.foreground().forbid_parking();
let params = cx.update(WorkspaceParams::test);
- let settings = params.settings.clone();
let fs = params.fs.as_fake();
fs.insert_tree(
"/root1",
@@ -660,7 +652,7 @@ mod tests {
.await;
let (_, workspace) = cx.add_window(|cx| Workspace::new(¶ms, cx));
- let panel = workspace.update(cx, |_, cx| ProjectPanel::new(project, settings, cx));
+ let panel = workspace.update(cx, |_, cx| ProjectPanel::new(project, cx));
assert_eq!(
visible_entry_details(&panel, 0..50, cx),
&[
@@ -11,7 +11,6 @@ use gpui::{
ViewContext, ViewHandle, WeakViewHandle,
};
use ordered_float::OrderedFloat;
-use postage::watch;
use project::{Project, Symbol};
use std::{
borrow::Cow,
@@ -41,7 +40,6 @@ pub fn init(cx: &mut MutableAppContext) {
pub struct ProjectSymbolsView {
handle: WeakViewHandle<Self>,
project: ModelHandle<Project>,
- settings: watch::Receiver<Settings>,
selected_match_index: usize,
list_state: UniformListState,
symbols: Vec<Symbol>,
@@ -71,16 +69,15 @@ impl View for ProjectSymbolsView {
cx
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
-
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let settings = cx.app_state::<Settings>();
Flex::new(Axis::Vertical)
.with_child(
Container::new(ChildView::new(&self.query_editor).boxed())
.with_style(settings.theme.selector.input_editor.container)
.boxed(),
)
- .with_child(Flexible::new(1.0, false, self.render_matches()).boxed())
+ .with_child(Flexible::new(1.0, false, self.render_matches(cx)).boxed())
.contained()
.with_style(settings.theme.selector.container)
.constrained()
@@ -97,24 +94,15 @@ impl View for ProjectSymbolsView {
}
impl ProjectSymbolsView {
- fn new(
- project: ModelHandle<Project>,
- settings: watch::Receiver<Settings>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ fn new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
let query_editor = cx.add_view(|cx| {
- Editor::single_line(
- settings.clone(),
- Some(|theme| theme.selector.input_editor.clone()),
- cx,
- )
+ Editor::single_line(Some(|theme| theme.selector.input_editor.clone()), cx)
});
cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach();
let mut this = Self {
handle: cx.weak_handle(),
project,
- settings,
selected_match_index: 0,
list_state: Default::default(),
symbols: Default::default(),
@@ -130,7 +118,7 @@ impl ProjectSymbolsView {
fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) {
workspace.toggle_modal(cx, |cx, workspace| {
let project = workspace.project().clone();
- let symbols = cx.add_view(|cx| Self::new(project, workspace.settings.clone(), cx));
+ let symbols = cx.add_view(|cx| Self::new(project, cx));
cx.subscribe(&symbols, Self::on_event).detach();
symbols
});
@@ -244,9 +232,9 @@ impl ProjectSymbolsView {
cx.notify();
}
- fn render_matches(&self) -> ElementBox {
+ fn render_matches(&self, cx: &AppContext) -> ElementBox {
if self.matches.is_empty() {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
return Container::new(
Label::new(
"No matches".into(),
@@ -289,7 +277,7 @@ impl ProjectSymbolsView {
show_worktree_root_name: bool,
cx: &AppContext,
) -> ElementBox {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
let style = if index == self.selected_match_index {
&settings.theme.selector.active_item
} else {
@@ -6,7 +6,6 @@ use gpui::{
RenderContext, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use language::OffsetRangeExt;
-use postage::watch;
use project::search::SearchQuery;
use std::ops::Range;
use workspace::{ItemViewHandle, Pane, Settings, Toolbar, Workspace};
@@ -40,7 +39,6 @@ pub fn init(cx: &mut MutableAppContext) {
}
struct SearchBar {
- settings: watch::Receiver<Settings>,
query_editor: ViewHandle<Editor>,
active_editor: Option<ViewHandle<Editor>>,
active_match_index: Option<usize>,
@@ -68,7 +66,7 @@ impl View for SearchBar {
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme;
+ let theme = cx.app_state::<Settings>().theme.clone();
let editor_container = if self.query_contains_error {
theme.search.invalid_editor
} else {
@@ -158,14 +156,9 @@ impl Toolbar for SearchBar {
}
impl SearchBar {
- fn new(settings: watch::Receiver<Settings>, cx: &mut ViewContext<Self>) -> Self {
+ fn new(cx: &mut ViewContext<Self>) -> Self {
let query_editor = cx.add_view(|cx| {
- Editor::auto_height(
- 2,
- settings.clone(),
- Some(|theme| theme.search.editor.input.clone()),
- cx,
- )
+ Editor::auto_height(2, Some(|theme| theme.search.editor.input.clone()), cx)
});
cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach();
@@ -179,7 +172,6 @@ impl SearchBar {
case_sensitive: false,
whole_word: false,
regex: false,
- settings,
pending_search: None,
query_contains_error: false,
dismissed: false,
@@ -201,9 +193,9 @@ impl SearchBar {
search_option: SearchOption,
cx: &mut RenderContext<Self>,
) -> ElementBox {
- let theme = &self.settings.borrow().theme.search;
let is_active = self.is_search_option_enabled(search_option);
- MouseEventHandler::new::<Self, _, _>(search_option as usize, cx, |state, _| {
+ MouseEventHandler::new::<Self, _, _>(search_option as usize, cx, |state, cx| {
+ let theme = &cx.app_state::<Settings>().theme.search;
let style = match (is_active, state.hovered) {
(false, false) => &theme.option_button,
(false, true) => &theme.hovered_option_button,
@@ -226,9 +218,9 @@ impl SearchBar {
direction: Direction,
cx: &mut RenderContext<Self>,
) -> ElementBox {
- let theme = &self.settings.borrow().theme.search;
enum NavButton {}
- MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, _| {
+ MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
+ let theme = &cx.app_state::<Settings>().theme.search;
let style = if state.hovered {
&theme.hovered_option_button
} else {
@@ -245,9 +237,8 @@ impl SearchBar {
}
fn deploy(workspace: &mut Workspace, Deploy(focus): &Deploy, cx: &mut ViewContext<Workspace>) {
- let settings = workspace.settings();
workspace.active_pane().update(cx, |pane, cx| {
- pane.show_toolbar(cx, |cx| SearchBar::new(settings, cx));
+ pane.show_toolbar(cx, |cx| SearchBar::new(cx));
if let Some(search_bar) = pane
.active_toolbar()
@@ -468,8 +459,6 @@ impl SearchBar {
this.update_match_index(cx);
if !this.dismissed {
editor.update(cx, |editor, cx| {
- let theme = &this.settings.borrow().theme.search;
-
if select_closest_match {
if let Some(match_ix) = this.active_match_index {
editor.select_ranges(
@@ -480,6 +469,7 @@ impl SearchBar {
}
}
+ let theme = &cx.app_state::<Settings>().theme.search;
editor.highlight_ranges::<Self>(
ranges,
theme.match_background,
@@ -525,7 +515,7 @@ mod tests {
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
theme.search.match_background = Color::red();
let settings = Settings::new("Courier", &fonts, Arc::new(theme)).unwrap();
- let settings = watch::channel_with(settings).1;
+ cx.update(|cx| cx.add_app_state(settings));
let buffer = cx.update(|cx| {
MultiBuffer::build_simple(
@@ -540,11 +530,11 @@ mod tests {
)
});
let editor = cx.add_view(Default::default(), |cx| {
- Editor::for_buffer(buffer.clone(), None, settings.clone(), cx)
+ Editor::for_buffer(buffer.clone(), None, cx)
});
let search_bar = cx.add_view(Default::default(), |cx| {
- let mut search_bar = SearchBar::new(settings, cx);
+ let mut search_bar = SearchBar::new(cx);
search_bar.active_item_changed(Some(Box::new(editor.clone())), cx);
search_bar
});
@@ -9,7 +9,6 @@ use gpui::{
ModelContext, ModelHandle, MutableAppContext, RenderContext, Task, View, ViewContext,
ViewHandle, WeakModelHandle,
};
-use postage::watch;
use project::{search::SearchQuery, Project};
use std::{
any::{Any, TypeId},
@@ -74,7 +73,6 @@ struct ProjectSearchView {
regex: bool,
query_contains_error: bool,
active_match_index: Option<usize>,
- settings: watch::Receiver<Settings>,
}
impl Entity for ProjectSearch {
@@ -146,11 +144,11 @@ impl Item for ProjectSearch {
fn build_view(
model: ModelHandle<Self>,
- workspace: &Workspace,
+ _: &Workspace,
nav_history: ItemNavHistory,
cx: &mut gpui::ViewContext<Self::View>,
) -> Self::View {
- ProjectSearchView::new(model, Some(nav_history), workspace.settings(), cx)
+ ProjectSearchView::new(model, Some(nav_history), cx)
}
fn project_path(&self) -> Option<project::ProjectPath> {
@@ -174,7 +172,7 @@ impl View for ProjectSearchView {
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
let model = &self.model.read(cx);
let results = if model.match_ranges.is_empty() {
- let theme = &self.settings.borrow().theme;
+ let theme = &cx.app_state::<Settings>().theme;
let text = if self.query_editor.read(cx).text(cx).is_empty() {
""
} else if model.pending_search.is_some() {
@@ -242,7 +240,7 @@ impl ItemView for ProjectSearchView {
}
fn tab_content(&self, tab_theme: &theme::Tab, cx: &gpui::AppContext) -> ElementBox {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
let search_theme = &settings.theme.search;
Flex::row()
.with_child(
@@ -316,12 +314,7 @@ impl ItemView for ProjectSearchView {
Self: Sized,
{
let model = self.model.update(cx, |model, cx| model.clone(cx));
- Some(Self::new(
- model,
- Some(nav_history),
- self.settings.clone(),
- cx,
- ))
+ Some(Self::new(model, Some(nav_history), cx))
}
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) {
@@ -338,7 +331,6 @@ impl ProjectSearchView {
fn new(
model: ModelHandle<ProjectSearch>,
nav_history: Option<ItemNavHistory>,
- settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let project;
@@ -363,17 +355,14 @@ impl ProjectSearchView {
.detach();
let query_editor = cx.add_view(|cx| {
- let mut editor = Editor::single_line(
- settings.clone(),
- Some(|theme| theme.search.editor.input.clone()),
- cx,
- );
+ let mut editor =
+ Editor::single_line(Some(|theme| theme.search.editor.input.clone()), cx);
editor.set_text(query_text, cx);
editor
});
let results_editor = cx.add_view(|cx| {
- let mut editor = Editor::for_buffer(excerpts, Some(project), settings.clone(), cx);
+ let mut editor = Editor::for_buffer(excerpts, Some(project), cx);
editor.set_searchable(false);
editor.set_nav_history(nav_history);
editor
@@ -396,7 +385,6 @@ impl ProjectSearchView {
regex,
query_contains_error: false,
active_match_index: None,
- settings,
};
this.model_changed(false, cx);
this
@@ -560,11 +548,11 @@ impl ProjectSearchView {
if match_ranges.is_empty() {
self.active_match_index = None;
} else {
- let theme = &self.settings.borrow().theme.search;
self.results_editor.update(cx, |editor, cx| {
if reset_selections {
editor.select_ranges(match_ranges.first().cloned(), Some(Autoscroll::Fit), cx);
}
+ let theme = &cx.app_state::<Settings>().theme.search;
editor.highlight_ranges::<Self>(match_ranges, theme.match_background, cx);
});
if self.query_editor.is_focused(cx) {
@@ -590,7 +578,7 @@ impl ProjectSearchView {
}
fn render_query_editor(&self, cx: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme;
+ let theme = cx.app_state::<Settings>().theme.clone();
let editor_container = if self.query_contains_error {
theme.search.invalid_editor
} else {
@@ -652,9 +640,9 @@ impl ProjectSearchView {
option: SearchOption,
cx: &mut RenderContext<Self>,
) -> ElementBox {
- let theme = &self.settings.borrow().theme.search;
let is_active = self.is_option_enabled(option);
- MouseEventHandler::new::<Self, _, _>(option as usize, cx, |state, _| {
+ MouseEventHandler::new::<Self, _, _>(option as usize, cx, |state, cx| {
+ let theme = &cx.app_state::<Settings>().theme.search;
let style = match (is_active, state.hovered) {
(false, false) => &theme.option_button,
(false, true) => &theme.hovered_option_button,
@@ -685,9 +673,9 @@ impl ProjectSearchView {
direction: Direction,
cx: &mut RenderContext<Self>,
) -> ElementBox {
- let theme = &self.settings.borrow().theme.search;
enum NavButton {}
- MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, _| {
+ MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
+ let theme = &cx.app_state::<Settings>().theme.search;
let style = if state.hovered {
&theme.hovered_option_button
} else {
@@ -719,7 +707,7 @@ mod tests {
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
theme.search.match_background = Color::red();
let settings = Settings::new("Courier", &fonts, Arc::new(theme)).unwrap();
- let settings = watch::channel_with(settings).1;
+ cx.update(|cx| cx.add_app_state(settings));
let fs = FakeFs::new(cx.background());
fs.insert_tree(
@@ -744,7 +732,7 @@ mod tests {
let search = cx.add_model(|cx| ProjectSearch::new(project, cx));
let search_view = cx.add_view(Default::default(), |cx| {
- ProjectSearchView::new(search.clone(), None, settings, cx)
+ ProjectSearchView::new(search.clone(), None, cx)
});
search_view.update(cx, |search_view, cx| {
@@ -1023,7 +1023,7 @@ mod tests {
};
use lsp;
use parking_lot::Mutex;
- use postage::{barrier, watch};
+ use postage::barrier;
use project::{
fs::{FakeFs, Fs as _},
search::SearchQuery,
@@ -1152,14 +1152,7 @@ mod tests {
.await
.unwrap();
- let editor_b = cx_b.add_view(window_b, |cx| {
- Editor::for_buffer(
- buffer_b,
- None,
- watch::channel_with(Settings::test(cx)).1,
- cx,
- )
- });
+ let editor_b = cx_b.add_view(window_b, |cx| Editor::for_buffer(buffer_b, None, cx));
// TODO
// // Create a selection set as client B and see that selection set as client A.
@@ -2186,7 +2179,6 @@ mod tests {
Editor::for_buffer(
cx.add_model(|cx| MultiBuffer::singleton(buffer_b.clone(), cx)),
Some(project_b.clone()),
- watch::channel_with(Settings::test(cx)).1,
cx,
)
});
@@ -4424,6 +4416,11 @@ mod tests {
}
async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
+ cx.update(|cx| {
+ let settings = Settings::test(cx);
+ cx.add_app_state(settings);
+ });
+
let http = FakeHttpClient::with_404_response();
let user_id = self.app_state.db.create_user(name, false).await.unwrap();
let client_name = name.to_string();
@@ -7,25 +7,14 @@ use gpui::{
AppContext, Axis, Element, ElementBox, Entity, MutableAppContext, RenderContext, View,
ViewContext, ViewHandle,
};
-use parking_lot::Mutex;
-use postage::watch;
use std::{cmp, sync::Arc};
use theme::{Theme, ThemeRegistry};
use workspace::{
menu::{Confirm, SelectNext, SelectPrev},
- AppState, Settings, Workspace,
+ Settings, Workspace,
};
-#[derive(Clone)]
-pub struct ThemeSelectorParams {
- pub settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
- pub settings: watch::Receiver<Settings>,
- pub themes: Arc<ThemeRegistry>,
-}
-
pub struct ThemeSelector {
- settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
- settings: watch::Receiver<Settings>,
themes: Arc<ThemeRegistry>,
matches: Vec<StringMatch>,
query_editor: ViewHandle<Editor>,
@@ -35,10 +24,10 @@ pub struct ThemeSelector {
selection_completed: bool,
}
-action!(Toggle, ThemeSelectorParams);
-action!(Reload, ThemeSelectorParams);
+action!(Toggle, Arc<ThemeRegistry>);
+action!(Reload, Arc<ThemeRegistry>);
-pub fn init(params: ThemeSelectorParams, cx: &mut MutableAppContext) {
+pub fn init(themes: Arc<ThemeRegistry>, cx: &mut MutableAppContext) {
cx.add_action(ThemeSelector::confirm);
cx.add_action(ThemeSelector::select_prev);
cx.add_action(ThemeSelector::select_next);
@@ -46,9 +35,9 @@ pub fn init(params: ThemeSelectorParams, cx: &mut MutableAppContext) {
cx.add_action(ThemeSelector::reload);
cx.add_bindings(vec![
- Binding::new("cmd-k cmd-t", Toggle(params.clone()), None),
- Binding::new("cmd-k t", Reload(params.clone()), None),
- Binding::new("escape", Toggle(params.clone()), Some("ThemeSelector")),
+ Binding::new("cmd-k cmd-t", Toggle(themes.clone()), None),
+ Binding::new("cmd-k t", Reload(themes.clone()), None),
+ Binding::new("escape", Toggle(themes.clone()), Some("ThemeSelector")),
]);
}
@@ -57,28 +46,17 @@ pub enum Event {
}
impl ThemeSelector {
- fn new(
- settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
- settings: watch::Receiver<Settings>,
- registry: Arc<ThemeRegistry>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ fn new(registry: Arc<ThemeRegistry>, cx: &mut ViewContext<Self>) -> Self {
let query_editor = cx.add_view(|cx| {
- Editor::single_line(
- settings.clone(),
- Some(|theme| theme.selector.input_editor.clone()),
- cx,
- )
+ Editor::single_line(Some(|theme| theme.selector.input_editor.clone()), cx)
});
cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach();
- let original_theme = settings.borrow().theme.clone();
+ let original_theme = cx.app_state::<Settings>().theme.clone();
let mut this = Self {
- settings,
- settings_tx,
themes: registry,
query_editor,
matches: Vec::new(),
@@ -97,25 +75,18 @@ impl ThemeSelector {
fn toggle(workspace: &mut Workspace, action: &Toggle, cx: &mut ViewContext<Workspace>) {
workspace.toggle_modal(cx, |cx, _| {
- let selector = cx.add_view(|cx| {
- Self::new(
- action.0.settings_tx.clone(),
- action.0.settings.clone(),
- action.0.themes.clone(),
- cx,
- )
- });
+ let selector = cx.add_view(|cx| Self::new(action.0.clone(), cx));
cx.subscribe(&selector, Self::on_event).detach();
selector
});
}
- fn reload(_: &mut Workspace, action: &Reload, _: &mut ViewContext<Workspace>) {
- let current_theme_name = action.0.settings.borrow().theme.name.clone();
- action.0.themes.clear();
- match action.0.themes.get(¤t_theme_name) {
+ fn reload(_: &mut Workspace, action: &Reload, cx: &mut ViewContext<Workspace>) {
+ let current_theme_name = cx.app_state::<Settings>().theme.name.clone();
+ action.0.clear();
+ match action.0.get(¤t_theme_name) {
Ok(theme) => {
- action.0.settings_tx.lock().borrow_mut().theme = theme;
+ Self::set_theme(theme, cx);
log::info!("reloaded theme {}", current_theme_name);
}
Err(error) => {
@@ -136,7 +107,7 @@ impl ThemeSelector {
self.list_state
.scroll_to(ScrollTarget::Show(self.selected_index));
- self.show_selected_theme();
+ self.show_selected_theme(cx);
cx.notify();
}
@@ -147,14 +118,14 @@ impl ThemeSelector {
self.list_state
.scroll_to(ScrollTarget::Show(self.selected_index));
- self.show_selected_theme();
+ self.show_selected_theme(cx);
cx.notify();
}
- fn show_selected_theme(&mut self) {
+ fn show_selected_theme(&mut self, cx: &mut ViewContext<Self>) {
if let Some(mat) = self.matches.get(self.selected_index) {
match self.themes.get(&mat.string) {
- Ok(theme) => self.set_theme(theme),
+ Ok(theme) => Self::set_theme(theme, cx),
Err(error) => {
log::error!("error loading theme {}: {}", mat.string, error)
}
@@ -170,14 +141,6 @@ impl ThemeSelector {
.unwrap_or(self.selected_index);
}
- fn current_theme(&self) -> Arc<Theme> {
- self.settings_tx.lock().borrow().theme.clone()
- }
-
- fn set_theme(&self, theme: Arc<Theme>) {
- self.settings_tx.lock().borrow_mut().theme = theme;
- }
-
fn update_matches(&mut self, cx: &mut ViewContext<Self>) {
let background = cx.background().clone();
let candidates = self
@@ -243,8 +206,8 @@ impl ThemeSelector {
match event {
editor::Event::Edited => {
self.update_matches(cx);
- self.select_if_matching(&self.current_theme().name);
- self.show_selected_theme();
+ self.select_if_matching(&cx.app_state::<Settings>().theme.name);
+ self.show_selected_theme(cx);
}
editor::Event::Blurred => cx.emit(Event::Dismissed),
_ => {}
@@ -253,7 +216,7 @@ impl ThemeSelector {
fn render_matches(&self, cx: &mut RenderContext<Self>) -> ElementBox {
if self.matches.is_empty() {
- let settings = self.settings.borrow();
+ let settings = cx.app_state::<Settings>();
return Container::new(
Label::new(
"No matches".into(),
@@ -266,31 +229,29 @@ impl ThemeSelector {
}
let handle = cx.handle();
- let list = UniformList::new(
- self.list_state.clone(),
- self.matches.len(),
- move |mut range, items, cx| {
- let cx = cx.as_ref();
- let selector = handle.upgrade(cx).unwrap();
- let selector = selector.read(cx);
- let start = range.start;
- range.end = cmp::min(range.end, selector.matches.len());
- items.extend(
- selector.matches[range]
- .iter()
- .enumerate()
- .map(move |(i, path_match)| selector.render_match(path_match, start + i)),
- );
- },
- );
+ let list =
+ UniformList::new(
+ self.list_state.clone(),
+ self.matches.len(),
+ move |mut range, items, cx| {
+ let cx = cx.as_ref();
+ let selector = handle.upgrade(cx).unwrap();
+ let selector = selector.read(cx);
+ let start = range.start;
+ range.end = cmp::min(range.end, selector.matches.len());
+ items.extend(selector.matches[range].iter().enumerate().map(
+ move |(i, path_match)| selector.render_match(path_match, start + i, cx),
+ ));
+ },
+ );
Container::new(list.boxed())
.with_margin_top(6.0)
.named("matches")
}
- fn render_match(&self, theme_match: &StringMatch, index: usize) -> ElementBox {
- let settings = self.settings.borrow();
+ fn render_match(&self, theme_match: &StringMatch, index: usize, cx: &AppContext) -> ElementBox {
+ let settings = cx.app_state::<Settings>();
let theme = &settings.theme;
let container = Container::new(
@@ -313,14 +274,21 @@ impl ThemeSelector {
container.boxed()
}
+
+ fn set_theme(theme: Arc<Theme>, cx: &mut MutableAppContext) {
+ cx.update_app_state::<Settings, _, _>(|settings, cx| {
+ settings.theme = theme;
+ cx.refresh_windows();
+ });
+ }
}
impl Entity for ThemeSelector {
type Event = Event;
- fn release(&mut self, _: &mut MutableAppContext) {
+ fn release(&mut self, cx: &mut MutableAppContext) {
if !self.selection_completed {
- self.set_theme(self.original_theme.clone());
+ Self::set_theme(self.original_theme.clone(), cx);
}
}
}
@@ -331,8 +299,7 @@ impl View for ThemeSelector {
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
-
+ let theme = cx.app_state::<Settings>().theme.clone();
Align::new(
ConstrainedBox::new(
Container::new(
@@ -340,13 +307,13 @@ impl View for ThemeSelector {
.with_child(
ChildView::new(&self.query_editor)
.contained()
- .with_style(settings.theme.selector.input_editor.container)
+ .with_style(theme.selector.input_editor.container)
.boxed(),
)
.with_child(Flexible::new(1.0, false, self.render_matches(cx)).boxed())
.boxed(),
)
- .with_style(settings.theme.selector.container)
+ .with_style(theme.selector.container)
.boxed(),
)
.with_max_width(600.0)
@@ -367,13 +334,3 @@ impl View for ThemeSelector {
cx
}
}
-
-impl<'a> From<&'a AppState> for ThemeSelectorParams {
- fn from(state: &'a AppState) -> Self {
- Self {
- settings_tx: state.settings_tx.clone(),
- settings: state.settings.clone(),
- themes: state.themes.clone(),
- }
- }
-}
@@ -6,7 +6,6 @@ use gpui::{
RenderContext, View, ViewContext,
};
use language::{LanguageRegistry, LanguageServerBinaryStatus};
-use postage::watch;
use project::{LanguageServerProgress, Project};
use smallvec::SmallVec;
use std::cmp::Reverse;
@@ -16,7 +15,6 @@ use std::sync::Arc;
action!(DismissErrorMessage);
pub struct LspStatus {
- settings_rx: watch::Receiver<Settings>,
checking_for_update: Vec<String>,
downloading: Vec<String>,
failed: Vec<String>,
@@ -31,7 +29,6 @@ impl LspStatus {
pub fn new(
project: &ModelHandle<Project>,
languages: Arc<LanguageRegistry>,
- settings_rx: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let mut status_events = languages.language_server_binary_statuses();
@@ -72,7 +69,6 @@ impl LspStatus {
cx.observe(project, |_, _, cx| cx.notify()).detach();
Self {
- settings_rx,
checking_for_update: Default::default(),
downloading: Default::default(),
failed: Default::default(),
@@ -120,7 +116,7 @@ impl View for LspStatus {
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings_rx.borrow().theme;
+ let theme = &cx.app_state::<Settings>().theme;
let mut pending_work = self.pending_language_server_work(cx);
if let Some((lang_server_name, progress_token, progress)) = pending_work.next() {
@@ -169,7 +165,8 @@ impl View for LspStatus {
.boxed()
} else if !self.failed.is_empty() {
drop(pending_work);
- MouseEventHandler::new::<Self, _, _>(0, cx, |_, _| {
+ MouseEventHandler::new::<Self, _, _>(0, cx, |_, cx| {
+ let theme = &cx.app_state::<Settings>().theme;
Label::new(
format!(
"Failed to download {} language server{}. Click to dismiss.",
@@ -10,7 +10,6 @@ use gpui::{
AnyViewHandle, Entity, MutableAppContext, Quad, RenderContext, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
};
-use postage::watch;
use project::ProjectPath;
use std::{
any::{Any, TypeId},
@@ -100,7 +99,6 @@ pub enum Event {
pub struct Pane {
item_views: Vec<(usize, Box<dyn ItemViewHandle>)>,
active_item_index: usize,
- settings: watch::Receiver<Settings>,
nav_history: Rc<RefCell<NavHistory>>,
toolbars: HashMap<TypeId, Box<dyn ToolbarHandle>>,
active_toolbar_type: Option<TypeId>,
@@ -159,11 +157,10 @@ pub struct NavigationEntry {
}
impl Pane {
- pub fn new(settings: watch::Receiver<Settings>) -> Self {
+ pub fn new() -> Self {
Self {
item_views: Vec::new(),
active_item_index: 0,
- settings,
nav_history: Default::default(),
toolbars: Default::default(),
active_toolbar_type: Default::default(),
@@ -513,8 +510,7 @@ impl Pane {
}
fn render_tabs(&self, cx: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
- let theme = &settings.theme;
+ let theme = cx.app_state::<Settings>().theme.clone();
enum Tabs {}
let tabs = MouseEventHandler::new::<Tabs, _, _>(0, cx, |mouse_state, cx| {
@@ -5,7 +5,6 @@ use gpui::{
font_cache::{FamilyId, FontCache},
};
use language::Language;
-use parking_lot::Mutex;
use postage::{prelude::Stream, watch};
use project::Fs;
use schemars::{schema_for, JsonSchema};
@@ -66,8 +65,7 @@ impl SettingsFile {
let path = path.into();
let settings = Self::load(fs.clone(), &path).await.unwrap_or_default();
let mut events = fs.watch(&path, Duration::from_millis(500)).await;
- let (mut tx, mut rx) = watch::channel_with(settings);
- rx.recv().await;
+ let (mut tx, rx) = watch::channel_with(settings);
executor
.spawn(async move {
while events.next().await.is_some() {
@@ -103,30 +101,26 @@ impl Settings {
pub fn from_files(
defaults: Self,
sources: Vec<SettingsFile>,
- executor: Arc<executor::Background>,
theme_registry: Arc<ThemeRegistry>,
font_cache: Arc<FontCache>,
- ) -> (Arc<Mutex<watch::Sender<Self>>>, watch::Receiver<Self>) {
- let (tx, mut rx) = watch::channel_with(defaults.clone());
- let tx = Arc::new(Mutex::new(tx));
- executor
- .spawn({
- let tx = tx.clone();
- async move {
- let mut stream =
- stream::select_all(sources.iter().map(|source| source.0.clone()));
- while stream.next().await.is_some() {
- let mut settings = defaults.clone();
- for source in &sources {
- settings.merge(&*source.0.borrow(), &theme_registry, &font_cache);
- }
- *tx.lock().borrow_mut() = settings;
- }
- }
- })
- .detach();
- rx.try_recv().ok();
- (tx, rx)
+ ) -> impl futures::stream::Stream<Item = Self> {
+ stream::select_all(sources.iter().enumerate().map(|(i, source)| {
+ let mut rx = source.0.clone();
+ // Consume the initial item from all of the constituent file watches but one.
+ // This way, the stream will yield exactly one item for the files' initial
+ // state, and won't return any more items until the files change.
+ if i > 0 {
+ rx.try_recv().ok();
+ }
+ rx
+ }))
+ .map(move |_| {
+ let mut settings = defaults.clone();
+ for source in &sources {
+ settings.merge(&*source.0.borrow(), &theme_registry, &font_cache);
+ }
+ settings
+ })
}
pub fn new(
@@ -245,7 +239,6 @@ fn merge_option<T: Copy>(target: &mut Option<T>, value: Option<T>) {
#[cfg(test)]
mod tests {
use super::*;
- use postage::prelude::Stream;
use project::FakeFs;
#[gpui::test]
@@ -276,15 +269,14 @@ mod tests {
let source2 = SettingsFile::new(fs.clone(), &executor, "/settings2.json".as_ref()).await;
let source3 = SettingsFile::new(fs.clone(), &executor, "/settings3.json".as_ref()).await;
- let (_, mut settings_rx) = Settings::from_files(
+ let mut settings_rx = Settings::from_files(
cx.read(Settings::test),
vec![source1, source2, source3],
- cx.background(),
ThemeRegistry::new((), cx.font_cache()),
cx.font_cache(),
);
- let settings = settings_rx.recv().await.unwrap();
+ let settings = settings_rx.next().await.unwrap();
let md_settings = settings.language_overrides.get("Markdown").unwrap();
assert_eq!(settings.soft_wrap, SoftWrap::EditorWidth);
assert_eq!(settings.buffer_font_size, 24.0);
@@ -310,7 +302,7 @@ mod tests {
.await
.unwrap();
- let settings = settings_rx.recv().await.unwrap();
+ let settings = settings_rx.next().await.unwrap();
let md_settings = settings.language_overrides.get("Markdown").unwrap();
assert_eq!(settings.soft_wrap, SoftWrap::None);
assert_eq!(settings.buffer_font_size, 24.0);
@@ -322,7 +314,7 @@ mod tests {
.await
.unwrap();
- let settings = settings_rx.recv().await.unwrap();
+ let settings = settings_rx.next().await.unwrap();
assert_eq!(settings.tab_size, 4);
}
}
@@ -1,7 +1,7 @@
use super::Workspace;
-use crate::Settings;
use gpui::{action, elements::*, platform::CursorStyle, AnyViewHandle, RenderContext};
use std::{cell::RefCell, rc::Rc};
+use theme::Theme;
pub struct Sidebar {
side: Side,
@@ -62,16 +62,16 @@ impl Sidebar {
.map(|item| &item.view)
}
- fn theme<'a>(&self, settings: &'a Settings) -> &'a theme::Sidebar {
+ fn theme<'a>(&self, theme: &'a Theme) -> &'a theme::Sidebar {
match self.side {
- Side::Left => &settings.theme.workspace.left_sidebar,
- Side::Right => &settings.theme.workspace.right_sidebar,
+ Side::Left => &theme.workspace.left_sidebar,
+ Side::Right => &theme.workspace.right_sidebar,
}
}
- pub fn render(&self, settings: &Settings, cx: &mut RenderContext<Workspace>) -> ElementBox {
+ pub fn render(&self, theme: &Theme, cx: &mut RenderContext<Workspace>) -> ElementBox {
let side = self.side;
- let theme = self.theme(settings);
+ let theme = self.theme(theme);
ConstrainedBox::new(
Container::new(
@@ -119,13 +119,13 @@ impl Sidebar {
pub fn render_active_item(
&self,
- settings: &Settings,
+ theme: &Theme,
cx: &mut RenderContext<Workspace>,
) -> Option<ElementBox> {
if let Some(active_item) = self.active_item() {
let mut container = Flex::row();
if matches!(self.side, Side::Right) {
- container.add_child(self.render_resize_handle(settings, cx));
+ container.add_child(self.render_resize_handle(theme, cx));
}
container.add_child(
@@ -142,7 +142,7 @@ impl Sidebar {
.boxed(),
);
if matches!(self.side, Side::Left) {
- container.add_child(self.render_resize_handle(settings, cx));
+ container.add_child(self.render_resize_handle(theme, cx));
}
Some(container.boxed())
} else {
@@ -150,16 +150,12 @@ impl Sidebar {
}
}
- fn render_resize_handle(
- &self,
- settings: &Settings,
- cx: &mut RenderContext<Workspace>,
- ) -> ElementBox {
+ fn render_resize_handle(&self, theme: &Theme, cx: &mut RenderContext<Workspace>) -> ElementBox {
let width = self.width.clone();
let side = self.side;
MouseEventHandler::new::<Self, _, _>(side as usize, cx, |_, _| {
Container::new(Empty::new().boxed())
- .with_style(self.theme(settings).resize_handle)
+ .with_style(self.theme(theme).resize_handle)
.boxed()
})
.with_padding(Padding {
@@ -3,7 +3,6 @@ use gpui::{
elements::*, AnyViewHandle, ElementBox, Entity, MutableAppContext, RenderContext, Subscription,
View, ViewContext, ViewHandle,
};
-use postage::watch;
pub trait StatusItemView: View {
fn set_active_pane_item(
@@ -27,7 +26,6 @@ pub struct StatusBar {
right_items: Vec<Box<dyn StatusItemViewHandle>>,
active_pane: ViewHandle<Pane>,
_observe_active_pane: Subscription,
- settings: watch::Receiver<Settings>,
}
impl Entity for StatusBar {
@@ -39,8 +37,8 @@ impl View for StatusBar {
"StatusBar"
}
- fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
- let theme = &self.settings.borrow().theme.workspace.status_bar;
+ fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
+ let theme = &cx.app_state::<Settings>().theme.workspace.status_bar;
Flex::row()
.with_children(self.left_items.iter().map(|i| {
ChildView::new(i.as_ref())
@@ -66,18 +64,13 @@ impl View for StatusBar {
}
impl StatusBar {
- pub fn new(
- active_pane: &ViewHandle<Pane>,
- settings: watch::Receiver<Settings>,
- cx: &mut ViewContext<Self>,
- ) -> Self {
+ pub fn new(active_pane: &ViewHandle<Pane>, cx: &mut ViewContext<Self>) -> Self {
let mut this = Self {
left_items: Default::default(),
right_items: Default::default(),
active_pane: active_pane.clone(),
_observe_active_pane: cx
.observe(active_pane, |this, _, cx| this.update_active_pane_item(cx)),
- settings,
};
this.update_active_pane_item(cx);
this
@@ -26,8 +26,7 @@ use language::LanguageRegistry;
use log::error;
pub use pane::*;
pub use pane_group::*;
-use parking_lot::Mutex;
-use postage::{prelude::Stream, watch};
+use postage::prelude::Stream;
use project::{fs, Fs, Project, ProjectPath, Worktree};
pub use settings::Settings;
use sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus};
@@ -100,8 +99,6 @@ pub fn init(cx: &mut MutableAppContext) {
}
pub struct AppState {
- pub settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
- pub settings: watch::Receiver<Settings>,
pub languages: Arc<LanguageRegistry>,
pub themes: Arc<ThemeRegistry>,
pub client: Arc<client::Client>,
@@ -495,7 +492,6 @@ pub struct WorkspaceParams {
pub client: Arc<Client>,
pub fs: Arc<dyn Fs>,
pub languages: Arc<LanguageRegistry>,
- pub settings: watch::Receiver<Settings>,
pub user_store: ModelHandle<UserStore>,
pub channel_list: ModelHandle<ChannelList>,
pub path_openers: Arc<[Box<dyn PathOpener>]>,
@@ -504,15 +500,15 @@ pub struct WorkspaceParams {
impl WorkspaceParams {
#[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &mut MutableAppContext) -> Self {
+ let settings = Settings::test(cx);
+ cx.add_app_state(settings);
+
let fs = project::FakeFs::new(cx.background().clone());
let languages = Arc::new(LanguageRegistry::test());
let http_client = client::test::FakeHttpClient::new(|_| async move {
Ok(client::http::ServerResponse::new(404))
});
let client = Client::new(http_client.clone());
- let theme =
- gpui::fonts::with_font_cache(cx.font_cache().clone(), || theme::Theme::default());
- let settings = Settings::new("Courier", cx.font_cache(), Arc::new(theme)).unwrap();
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let project = Project::local(
client.clone(),
@@ -528,7 +524,6 @@ impl WorkspaceParams {
client,
fs,
languages,
- settings: watch::channel_with(settings).1,
user_store,
path_openers: Arc::from([]),
}
@@ -547,7 +542,6 @@ impl WorkspaceParams {
client: app_state.client.clone(),
fs: app_state.fs.clone(),
languages: app_state.languages.clone(),
- settings: app_state.settings.clone(),
user_store: app_state.user_store.clone(),
channel_list: app_state.channel_list.clone(),
path_openers: app_state.path_openers.clone(),
@@ -556,7 +550,6 @@ impl WorkspaceParams {
}
pub struct Workspace {
- pub settings: watch::Receiver<Settings>,
weak_self: WeakViewHandle<Self>,
client: Arc<Client>,
user_store: ModelHandle<client::UserStore>,
@@ -584,7 +577,7 @@ impl Workspace {
})
.detach();
- let pane = cx.add_view(|_| Pane::new(params.settings.clone()));
+ let pane = cx.add_view(|_| Pane::new());
let pane_id = pane.id();
cx.observe(&pane, move |me, _, cx| {
let active_entry = me.active_project_path(cx);
@@ -598,7 +591,7 @@ impl Workspace {
.detach();
cx.focus(&pane);
- let status_bar = cx.add_view(|cx| StatusBar::new(&pane, params.settings.clone(), cx));
+ let status_bar = cx.add_view(|cx| StatusBar::new(&pane, cx));
let mut current_user = params.user_store.read(cx).watch_current_user().clone();
let mut connection_status = params.client.status().clone();
let _observe_current_user = cx.spawn_weak(|this, mut cx| async move {
@@ -623,7 +616,6 @@ impl Workspace {
panes: vec![pane.clone()],
active_pane: pane.clone(),
status_bar,
- settings: params.settings.clone(),
client: params.client.clone(),
user_store: params.user_store.clone(),
fs: params.fs.clone(),
@@ -640,10 +632,6 @@ impl Workspace {
self.weak_self.clone()
}
- pub fn settings(&self) -> watch::Receiver<Settings> {
- self.settings.clone()
- }
-
pub fn left_sidebar_mut(&mut self) -> &mut Sidebar {
&mut self.left_sidebar
}
@@ -953,7 +941,7 @@ impl Workspace {
}
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> {
- let pane = cx.add_view(|_| Pane::new(self.settings.clone()));
+ let pane = cx.add_view(|_| Pane::new());
let pane_id = pane.id();
cx.observe(&pane, move |me, _, cx| {
let active_entry = me.active_project_path(cx);
@@ -1128,8 +1116,8 @@ impl Workspace {
});
}
- fn render_connection_status(&self) -> Option<ElementBox> {
- let theme = &self.settings.borrow().theme;
+ fn render_connection_status(&self, cx: &mut RenderContext<Self>) -> Option<ElementBox> {
+ let theme = &cx.app_state::<Settings>().theme;
match &*self.client.status().borrow() {
client::Status::ConnectionError
| client::Status::ConnectionLost
@@ -1187,7 +1175,7 @@ impl Workspace {
theme,
cx,
))
- .with_children(self.render_connection_status())
+ .with_children(self.render_connection_status(cx))
.boxed(),
)
.right()
@@ -1315,7 +1303,7 @@ impl Workspace {
fn render_disconnected_overlay(&self, cx: &AppContext) -> Option<ElementBox> {
if self.project.read(cx).is_read_only() {
- let theme = &self.settings.borrow().theme;
+ let theme = &cx.app_state::<Settings>().theme;
Some(
EventHandler::new(
Label::new(
@@ -1346,8 +1334,7 @@ impl View for Workspace {
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
- let settings = self.settings.borrow();
- let theme = &settings.theme;
+ let theme = cx.app_state::<Settings>().theme.clone();
Stack::new()
.with_child(
Flex::column()
@@ -1356,32 +1343,28 @@ impl View for Workspace {
Stack::new()
.with_child({
let mut content = Flex::row();
- content.add_child(self.left_sidebar.render(&settings, cx));
+ content.add_child(self.left_sidebar.render(&theme, cx));
if let Some(element) =
- self.left_sidebar.render_active_item(&settings, cx)
+ self.left_sidebar.render_active_item(&theme, cx)
{
content.add_child(Flexible::new(0.8, false, element).boxed());
}
content.add_child(
Flex::column()
.with_child(
- Flexible::new(
- 1.,
- true,
- self.center.render(&settings.theme),
- )
- .boxed(),
+ Flexible::new(1., true, self.center.render(&theme))
+ .boxed(),
)
.with_child(ChildView::new(&self.status_bar).boxed())
.flexible(1., true)
.boxed(),
);
if let Some(element) =
- self.right_sidebar.render_active_item(&settings, cx)
+ self.right_sidebar.render_active_item(&theme, cx)
{
content.add_child(Flexible::new(0.8, false, element).boxed());
}
- content.add_child(self.right_sidebar.render(&settings, cx));
+ content.add_child(self.right_sidebar.render(&theme, cx));
content.boxed()
})
.with_children(self.modal.as_ref().map(|m| ChildView::new(m).boxed()))
@@ -1389,7 +1372,7 @@ impl View for Workspace {
.boxed(),
)
.contained()
- .with_background_color(settings.theme.workspace.background)
+ .with_background_color(theme.workspace.background)
.boxed(),
)
.with_children(self.render_disconnected_overlay(cx))
@@ -8,7 +8,6 @@ use futures::{channel::oneshot, StreamExt};
use gpui::{App, AssetSource, Task};
use log::LevelFilter;
use parking_lot::Mutex;
-use postage::{prelude::Stream, watch};
use project::Fs;
use simplelog::SimpleLogger;
use smol::process::Command;
@@ -93,23 +92,29 @@ fn main() {
.detach_and_log_err(cx);
let settings_file = cx.background().block(settings_file).unwrap();
- let (settings_tx, settings) = Settings::from_files(
+ let mut settings_rx = Settings::from_files(
default_settings,
vec![settings_file],
- cx.background().clone(),
themes.clone(),
cx.font_cache().clone(),
);
-
- refresh_window_on_settings_change(settings.clone(), cx);
+ let settings = cx.background().block(settings_rx.next()).unwrap();
+ cx.spawn(|mut cx| async move {
+ while let Some(settings) = settings_rx.next().await {
+ cx.update(|cx| {
+ cx.update_app_state(|s, _| *s = settings);
+ cx.refresh_windows();
+ });
+ }
+ })
+ .detach();
languages.set_language_server_download_dir(zed::ROOT_PATH.clone());
- languages.set_theme(&settings.borrow().theme.editor.syntax);
+ languages.set_theme(&settings.theme.editor.syntax);
+ cx.add_app_state(settings);
let app_state = Arc::new(AppState {
languages: Arc::new(languages),
- settings_tx,
- settings,
themes,
channel_list,
client,
@@ -121,7 +126,7 @@ fn main() {
});
journal::init(app_state.clone(), cx);
zed::init(&app_state, cx);
- theme_selector::init(app_state.as_ref().into(), cx);
+ theme_selector::init(app_state.themes.clone(), cx);
cx.set_menus(menus::menus(&app_state.clone()));
@@ -242,16 +247,3 @@ fn load_settings_file(app: &App, fs: Arc<dyn Fs>) -> oneshot::Receiver<SettingsF
.detach();
rx
}
-
-fn refresh_window_on_settings_change(
- mut settings_rx: watch::Receiver<Settings>,
- cx: &mut gpui::MutableAppContext,
-) {
- settings_rx.try_recv().ok();
- cx.spawn(|mut cx| async move {
- while settings_rx.next().await.is_some() {
- cx.update(|cx| cx.refresh_windows());
- }
- })
- .detach();
-}
@@ -2,8 +2,6 @@ use crate::{assets::Assets, build_window_options, build_workspace, AppState};
use client::{test::FakeHttpClient, ChannelList, Client, UserStore};
use gpui::MutableAppContext;
use language::LanguageRegistry;
-use parking_lot::Mutex;
-use postage::watch;
use project::fs::FakeFs;
use std::sync::Arc;
use theme::ThemeRegistry;
@@ -18,9 +16,10 @@ fn init_logger() {
}
pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
+ let settings = Settings::test(cx);
let mut path_openers = Vec::new();
editor::init(cx, &mut path_openers);
- let (settings_tx, settings) = watch::channel_with(Settings::test(cx));
+ cx.add_app_state(settings);
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone());
@@ -35,8 +34,6 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
Some(tree_sitter_rust::language()),
)));
Arc::new(AppState {
- settings_tx: Arc::new(Mutex::new(settings_tx)),
- settings,
themes,
languages: Arc::new(languages),
channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
@@ -23,7 +23,7 @@ pub use project::{self, fs};
use project_panel::ProjectPanel;
use std::{path::PathBuf, sync::Arc};
pub use workspace;
-use workspace::{AppState, Workspace, WorkspaceParams};
+use workspace::{AppState, Settings, Workspace, WorkspaceParams};
action!(About);
action!(Quit);
@@ -42,11 +42,12 @@ lazy_static! {
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_global_action(quit);
cx.add_global_action({
- let settings_tx = app_state.settings_tx.clone();
- move |action: &AdjustBufferFontSize, _| {
- let mut settings_tx = settings_tx.lock();
- let new_size = (settings_tx.borrow().buffer_font_size + action.0).max(MIN_FONT_SIZE);
- settings_tx.borrow_mut().buffer_font_size = new_size;
+ move |action: &AdjustBufferFontSize, cx| {
+ cx.update_app_state::<Settings, _, _>(|settings, cx| {
+ settings.buffer_font_size =
+ (settings.buffer_font_size + action.0).max(MIN_FONT_SIZE);
+ cx.refresh_windows();
+ });
}
});
@@ -89,7 +90,6 @@ pub fn build_workspace(
client: app_state.client.clone(),
fs: app_state.fs.clone(),
languages: app_state.languages.clone(),
- settings: app_state.settings.clone(),
user_store: app_state.user_store.clone(),
channel_list: app_state.channel_list.clone(),
path_openers: app_state.path_openers.clone(),
@@ -98,7 +98,7 @@ pub fn build_workspace(
let project = workspace.project().clone();
workspace.left_sidebar_mut().add_item(
"icons/folder-tree-16.svg",
- ProjectPanel::new(project, app_state.settings.clone(), cx).into(),
+ ProjectPanel::new(project, cx).into(),
);
workspace.right_sidebar_mut().add_item(
"icons/user-16.svg",
@@ -108,35 +108,18 @@ pub fn build_workspace(
workspace.right_sidebar_mut().add_item(
"icons/comment-16.svg",
cx.add_view(|cx| {
- ChatPanel::new(
- app_state.client.clone(),
- app_state.channel_list.clone(),
- app_state.settings.clone(),
- cx,
- )
+ ChatPanel::new(app_state.client.clone(), app_state.channel_list.clone(), cx)
})
.into(),
);
- let diagnostic_message =
- cx.add_view(|_| editor::items::DiagnosticMessage::new(app_state.settings.clone()));
- let diagnostic_summary = cx.add_view(|cx| {
- diagnostics::items::DiagnosticSummary::new(
- workspace.project(),
- app_state.settings.clone(),
- cx,
- )
- });
+ let diagnostic_message = cx.add_view(|_| editor::items::DiagnosticMessage::new());
+ let diagnostic_summary =
+ cx.add_view(|cx| diagnostics::items::DiagnosticSummary::new(workspace.project(), cx));
let lsp_status = cx.add_view(|cx| {
- workspace::lsp_status::LspStatus::new(
- workspace.project(),
- app_state.languages.clone(),
- app_state.settings.clone(),
- cx,
- )
+ workspace::lsp_status::LspStatus::new(workspace.project(), app_state.languages.clone(), cx)
});
- let cursor_position =
- cx.add_view(|_| editor::items::CursorPosition::new(app_state.settings.clone()));
+ let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
workspace.status_bar().update(cx, |status_bar, cx| {
status_bar.add_left_item(diagnostic_summary, cx);
status_bar.add_left_item(diagnostic_message, cx);