mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-28 21:32:39 +00:00
Merge pull request #574 from zed-industries/settings-file
Read settings from a JSON file
This commit is contained in:
commit
e7d0bf1c36
32 changed files with 948 additions and 751 deletions
43
Cargo.lock
generated
43
Cargo.lock
generated
|
@ -1574,6 +1574,12 @@ dependencies = [
|
|||
"wio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf"
|
||||
|
||||
[[package]]
|
||||
name = "easy-parallel"
|
||||
version = "3.1.0"
|
||||
|
@ -4139,6 +4145,30 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schemars"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6b5a3c80cea1ab61f4260238409510e814e38b4b563c06044edf91e7dc070e3"
|
||||
dependencies = [
|
||||
"dyn-clone",
|
||||
"schemars_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schemars_derive"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41ae4dce13e8614c46ac3c38ef1c0d668b101df6ac39817aebdaa26642ddae9b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde_derive_internals",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped-tls"
|
||||
version = "1.0.0"
|
||||
|
@ -4260,6 +4290,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive_internals"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.64"
|
||||
|
@ -5851,6 +5892,8 @@ dependencies = [
|
|||
"parking_lot",
|
||||
"postage",
|
||||
"project",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"theme",
|
||||
|
|
|
@ -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;
|
||||
|
@ -433,7 +432,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>,
|
||||
override_text_style: Option<Box<OverrideTextStyle>>,
|
||||
|
@ -803,25 +801,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 {
|
||||
|
@ -831,7 +820,6 @@ impl Editor {
|
|||
EditorMode::AutoHeight { max_lines },
|
||||
buffer,
|
||||
None,
|
||||
settings,
|
||||
field_editor_style,
|
||||
cx,
|
||||
)
|
||||
|
@ -840,10 +828,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 {
|
||||
|
@ -851,7 +838,6 @@ impl Editor {
|
|||
self.mode,
|
||||
self.buffer.clone(),
|
||||
self.project.clone(),
|
||||
self.settings.clone(),
|
||||
self.get_field_editor_theme,
|
||||
cx,
|
||||
);
|
||||
|
@ -866,12 +852,11 @@ 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 settings = cx.app_state::<Settings>();
|
||||
let style = build_style(&*settings, get_field_editor_theme, None, cx);
|
||||
DisplayMap::new(
|
||||
buffer.clone(),
|
||||
|
@ -913,7 +898,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,
|
||||
|
@ -994,7 +978,7 @@ impl Editor {
|
|||
|
||||
fn style(&self, cx: &AppContext) -> EditorStyle {
|
||||
build_style(
|
||||
&*self.settings.borrow(),
|
||||
cx.app_state::<Settings>(),
|
||||
self.get_field_editor_theme,
|
||||
self.override_text_style.as_deref(),
|
||||
cx,
|
||||
|
@ -2717,7 +2701,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| {
|
||||
|
@ -2794,7 +2778,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();
|
||||
|
@ -4436,7 +4420,7 @@ impl Editor {
|
|||
// Position the selection in the rename editor so that it matches the current selection.
|
||||
this.show_local_selections = false;
|
||||
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);
|
||||
if let Some(old_highlight_id) = old_highlight_id {
|
||||
editor.override_text_style =
|
||||
Some(Box::new(move |style| old_highlight_id.style(&style.syntax)));
|
||||
|
@ -4629,11 +4613,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
|
||||
|
@ -4676,11 +4656,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,
|
||||
}
|
||||
}),
|
||||
|
@ -5298,7 +5274,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));
|
||||
|
@ -5876,18 +5852,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();
|
||||
|
@ -6082,14 +6054,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);
|
||||
|
@ -6153,10 +6123,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);
|
||||
|
@ -6220,9 +6189,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);
|
||||
|
@ -6252,12 +6221,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.
|
||||
|
@ -6309,9 +6279,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);
|
||||
|
@ -6349,6 +6319,7 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_fold(cx: &mut gpui::MutableAppContext) {
|
||||
populate_settings(cx);
|
||||
let buffer = MultiBuffer::build_simple(
|
||||
&"
|
||||
impl Foo {
|
||||
|
@ -6370,10 +6341,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);
|
||||
|
@ -6436,11 +6404,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(
|
||||
|
@ -6512,11 +6478,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);
|
||||
|
@ -6615,11 +6579,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);
|
||||
|
@ -6662,9 +6624,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(
|
||||
&[
|
||||
|
@ -6803,9 +6765,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(
|
||||
&[
|
||||
|
@ -6941,9 +6903,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);
|
||||
|
@ -6994,11 +6956,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(
|
||||
|
@ -7033,11 +6993,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(
|
||||
|
@ -7056,6 +7014,7 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_newline_with_old_selections(cx: &mut gpui::MutableAppContext) {
|
||||
populate_settings(cx);
|
||||
let buffer = MultiBuffer::build_simple(
|
||||
"
|
||||
a
|
||||
|
@ -7071,9 +7030,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),
|
||||
|
@ -7141,11 +7099,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
|
||||
});
|
||||
|
@ -7169,11 +7126,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
|
||||
|
@ -7245,9 +7200,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| {
|
||||
|
@ -7290,12 +7245,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(
|
||||
|
@ -7320,9 +7273,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(
|
||||
&[
|
||||
|
@ -7343,9 +7296,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);
|
||||
|
@ -7359,9 +7312,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(
|
||||
&[
|
||||
|
@ -7385,9 +7338,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(
|
||||
&[
|
||||
|
@ -7410,9 +7362,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![
|
||||
|
@ -7506,11 +7458,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 {
|
||||
|
@ -7528,12 +7479,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.
|
||||
|
@ -7659,9 +7608,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!(
|
||||
|
@ -7673,9 +7622,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(
|
||||
&[
|
||||
|
@ -7718,9 +7667,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![
|
||||
|
@ -7784,9 +7733,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);
|
||||
|
@ -7953,7 +7902,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()),
|
||||
|
@ -7970,7 +7919,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;
|
||||
|
||||
|
@ -8094,7 +8043,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 {
|
||||
|
@ -8129,7 +8078,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;
|
||||
|
@ -8151,7 +8100,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![
|
||||
|
@ -8183,7 +8132,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;
|
||||
|
||||
|
@ -8294,7 +8243,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
|
||||
|
@ -8303,7 +8252,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;
|
||||
|
@ -8401,7 +8350,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 {
|
||||
|
@ -8449,7 +8398,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);
|
||||
|
@ -8635,7 +8584,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()),
|
||||
|
@ -8655,7 +8604,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
|
||||
|
@ -8715,7 +8664,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);
|
||||
|
@ -8732,9 +8681,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(
|
||||
|
@ -8760,7 +8707,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);
|
||||
|
@ -8780,9 +8727,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(
|
||||
[
|
||||
|
@ -8817,7 +8762,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| {
|
||||
|
@ -8840,7 +8785,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),
|
||||
|
@ -8892,7 +8837,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![
|
||||
|
@ -8924,7 +8869,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;
|
||||
|
||||
|
@ -8960,10 +8905,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;
|
||||
|
@ -9113,13 +9056,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1468,16 +1468,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(),
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -319,13 +319,14 @@ impl LanguageRegistry {
|
|||
|
||||
let server_binary_path = server_binary_path.await?;
|
||||
let server_args = adapter.server_args();
|
||||
lsp::LanguageServer::new(
|
||||
let server = lsp::LanguageServer::new(
|
||||
&server_binary_path,
|
||||
server_args,
|
||||
&root_path,
|
||||
adapter.initialization_options(),
|
||||
background,
|
||||
)
|
||||
)?;
|
||||
Ok(server)
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite};
|
|||
use gpui::{executor, Task};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use postage::{barrier, prelude::Stream};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde_json::{json, value::RawValue, Value};
|
||||
use smol::{
|
||||
channel,
|
||||
|
@ -29,7 +29,8 @@ pub use lsp_types::*;
|
|||
const JSON_RPC_VERSION: &'static str = "2.0";
|
||||
const CONTENT_LEN_HEADER: &'static str = "Content-Length: ";
|
||||
|
||||
type NotificationHandler = Box<dyn Send + Sync + FnMut(&str)>;
|
||||
type NotificationHandler =
|
||||
Box<dyn Send + Sync + FnMut(Option<usize>, &str, &mut channel::Sender<Vec<u8>>) -> Result<()>>;
|
||||
type ResponseHandler = Box<dyn Send + FnOnce(Result<&str, Error>)>;
|
||||
|
||||
pub struct LanguageServer {
|
||||
|
@ -80,6 +81,12 @@ struct AnyResponse<'a> {
|
|||
result: Option<&'a RawValue>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Response<T> {
|
||||
id: usize,
|
||||
result: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Notification<'a, T> {
|
||||
#[serde(borrow)]
|
||||
|
@ -91,6 +98,8 @@ struct Notification<'a, T> {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
struct AnyNotification<'a> {
|
||||
#[serde(default)]
|
||||
id: Option<usize>,
|
||||
#[serde(borrow)]
|
||||
method: &'a str,
|
||||
#[serde(borrow)]
|
||||
|
@ -110,8 +119,13 @@ impl LanguageServer {
|
|||
options: Option<Value>,
|
||||
background: Arc<executor::Background>,
|
||||
) -> Result<Self> {
|
||||
let working_dir = if root_path.is_dir() {
|
||||
root_path
|
||||
} else {
|
||||
root_path.parent().unwrap_or(Path::new("/"))
|
||||
};
|
||||
let mut server = Command::new(binary_path)
|
||||
.current_dir(root_path)
|
||||
.current_dir(working_dir)
|
||||
.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
|
@ -147,6 +161,7 @@ impl LanguageServer {
|
|||
{
|
||||
let notification_handlers = notification_handlers.clone();
|
||||
let response_handlers = response_handlers.clone();
|
||||
let mut outbound_tx = outbound_tx.clone();
|
||||
async move {
|
||||
let _clear_response_handlers = ClearResponseHandlers(response_handlers.clone());
|
||||
let mut buffer = Vec::new();
|
||||
|
@ -163,11 +178,13 @@ impl LanguageServer {
|
|||
buffer.resize(message_len, 0);
|
||||
stdout.read_exact(&mut buffer).await?;
|
||||
|
||||
if let Ok(AnyNotification { method, params }) =
|
||||
if let Ok(AnyNotification { id, method, params }) =
|
||||
serde_json::from_slice(&buffer)
|
||||
{
|
||||
if let Some(handler) = notification_handlers.write().get_mut(method) {
|
||||
handler(params.get());
|
||||
if let Err(e) = handler(id, params.get(), &mut outbound_tx) {
|
||||
log::error!("error handling {} message: {:?}", method, e);
|
||||
}
|
||||
} else {
|
||||
log::info!(
|
||||
"unhandled notification {}:\n{}",
|
||||
|
@ -248,6 +265,13 @@ impl LanguageServer {
|
|||
root_uri: Some(root_uri),
|
||||
initialization_options: options,
|
||||
capabilities: ClientCapabilities {
|
||||
workspace: Some(WorkspaceClientCapabilities {
|
||||
configuration: Some(true),
|
||||
did_change_configuration: Some(DynamicRegistrationClientCapabilities {
|
||||
dynamic_registration: Some(true),
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
text_document: Some(TextDocumentClientCapabilities {
|
||||
definition: Some(GotoCapability {
|
||||
link_support: Some(true),
|
||||
|
@ -339,28 +363,77 @@ impl LanguageServer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn on_notification<T, F>(&mut self, mut f: F) -> Subscription
|
||||
pub fn on_notification<T, F>(&mut self, f: F) -> Subscription
|
||||
where
|
||||
T: notification::Notification,
|
||||
F: 'static + Send + Sync + FnMut(T::Params),
|
||||
{
|
||||
let prev_handler = self.notification_handlers.write().insert(
|
||||
T::METHOD,
|
||||
Box::new(
|
||||
move |notification| match serde_json::from_str(notification) {
|
||||
Ok(notification) => f(notification),
|
||||
Err(err) => log::error!("error parsing notification {}: {}", T::METHOD, err),
|
||||
},
|
||||
),
|
||||
);
|
||||
self.on_custom_notification(T::METHOD, f)
|
||||
}
|
||||
|
||||
pub fn on_request<T, F>(&mut self, f: F) -> Subscription
|
||||
where
|
||||
T: request::Request,
|
||||
F: 'static + Send + Sync + FnMut(T::Params) -> Result<T::Result>,
|
||||
{
|
||||
self.on_custom_request(T::METHOD, f)
|
||||
}
|
||||
|
||||
pub fn on_custom_notification<Params, F>(
|
||||
&mut self,
|
||||
method: &'static str,
|
||||
mut f: F,
|
||||
) -> Subscription
|
||||
where
|
||||
F: 'static + Send + Sync + FnMut(Params),
|
||||
Params: DeserializeOwned,
|
||||
{
|
||||
let prev_handler = self.notification_handlers.write().insert(
|
||||
method,
|
||||
Box::new(move |_, params, _| {
|
||||
let params = serde_json::from_str(params)?;
|
||||
f(params);
|
||||
Ok(())
|
||||
}),
|
||||
);
|
||||
assert!(
|
||||
prev_handler.is_none(),
|
||||
"registered multiple handlers for the same notification"
|
||||
"registered multiple handlers for the same LSP method"
|
||||
);
|
||||
|
||||
Subscription {
|
||||
method: T::METHOD,
|
||||
method,
|
||||
notification_handlers: self.notification_handlers.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_custom_request<Params, Res, F>(
|
||||
&mut self,
|
||||
method: &'static str,
|
||||
mut f: F,
|
||||
) -> Subscription
|
||||
where
|
||||
F: 'static + Send + Sync + FnMut(Params) -> Result<Res>,
|
||||
Params: DeserializeOwned,
|
||||
Res: Serialize,
|
||||
{
|
||||
let prev_handler = self.notification_handlers.write().insert(
|
||||
method,
|
||||
Box::new(move |id, params, tx| {
|
||||
if let Some(id) = id {
|
||||
let params = serde_json::from_str(params)?;
|
||||
let result = f(params)?;
|
||||
let response = serde_json::to_vec(&Response { id, result })?;
|
||||
tx.try_send(response)?;
|
||||
}
|
||||
Ok(())
|
||||
}),
|
||||
);
|
||||
assert!(
|
||||
prev_handler.is_none(),
|
||||
"registered multiple handlers for the same LSP method"
|
||||
);
|
||||
Subscription {
|
||||
method,
|
||||
notification_handlers: self.notification_handlers.clone(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -23,6 +23,7 @@ use language::{
|
|||
};
|
||||
use lsp::{DiagnosticSeverity, DocumentHighlightKind, LanguageServer};
|
||||
use lsp_command::*;
|
||||
use parking_lot::Mutex;
|
||||
use postage::watch;
|
||||
use rand::prelude::*;
|
||||
use search::SearchQuery;
|
||||
|
@ -52,6 +53,7 @@ pub struct Project {
|
|||
language_servers: HashMap<(WorktreeId, Arc<str>), Arc<LanguageServer>>,
|
||||
started_language_servers: HashMap<(WorktreeId, Arc<str>), Task<Option<Arc<LanguageServer>>>>,
|
||||
language_server_statuses: BTreeMap<usize, LanguageServerStatus>,
|
||||
language_server_settings: Arc<Mutex<serde_json::Value>>,
|
||||
next_language_server_id: usize,
|
||||
client: Arc<client::Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
|
@ -333,6 +335,7 @@ impl Project {
|
|||
language_servers: Default::default(),
|
||||
started_language_servers: Default::default(),
|
||||
language_server_statuses: Default::default(),
|
||||
language_server_settings: Default::default(),
|
||||
next_language_server_id: 0,
|
||||
nonce: StdRng::from_entropy().gen(),
|
||||
}
|
||||
|
@ -403,6 +406,7 @@ impl Project {
|
|||
language_servers_with_diagnostics_running: 0,
|
||||
language_servers: Default::default(),
|
||||
started_language_servers: Default::default(),
|
||||
language_server_settings: Default::default(),
|
||||
language_server_statuses: response
|
||||
.language_servers
|
||||
.into_iter()
|
||||
|
@ -1228,6 +1232,30 @@ impl Project {
|
|||
})
|
||||
.detach();
|
||||
|
||||
language_server
|
||||
.on_request::<lsp::request::WorkspaceConfiguration, _>({
|
||||
let settings = this
|
||||
.read_with(&cx, |this, _| this.language_server_settings.clone());
|
||||
move |params| {
|
||||
let settings = settings.lock();
|
||||
Ok(params
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
if let Some(section) = &item.section {
|
||||
settings
|
||||
.get(section)
|
||||
.cloned()
|
||||
.unwrap_or(serde_json::Value::Null)
|
||||
} else {
|
||||
settings.clone()
|
||||
}
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
language_server
|
||||
.on_notification::<lsp::notification::Progress, _>(move |params| {
|
||||
let token = match params.token {
|
||||
|
@ -1299,6 +1327,13 @@ impl Project {
|
|||
pending_diagnostic_updates: 0,
|
||||
},
|
||||
);
|
||||
language_server
|
||||
.notify::<lsp::notification::DidChangeConfiguration>(
|
||||
lsp::DidChangeConfigurationParams {
|
||||
settings: this.language_server_settings.lock().clone(),
|
||||
},
|
||||
)
|
||||
.ok();
|
||||
|
||||
if let Some(project_id) = this.remote_id() {
|
||||
this.client
|
||||
|
@ -1547,6 +1582,19 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_language_server_settings(&mut self, settings: serde_json::Value) {
|
||||
for server in self.language_servers.values() {
|
||||
server
|
||||
.notify::<lsp::notification::DidChangeConfiguration>(
|
||||
lsp::DidChangeConfigurationParams {
|
||||
settings: settings.clone(),
|
||||
},
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
*self.language_server_settings.lock() = settings;
|
||||
}
|
||||
|
||||
pub fn language_server_statuses(
|
||||
&self,
|
||||
) -> impl DoubleEndedIterator<Item = &LanguageServerStatus> {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -160,14 +158,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();
|
||||
|
@ -181,7 +174,6 @@ impl SearchBar {
|
|||
case_sensitive: false,
|
||||
whole_word: false,
|
||||
regex: false,
|
||||
settings,
|
||||
pending_search: None,
|
||||
query_contains_error: false,
|
||||
dismissed: false,
|
||||
|
@ -203,9 +195,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,
|
||||
|
@ -228,9 +220,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 {
|
||||
|
@ -247,9 +239,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()
|
||||
|
@ -474,8 +465,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(
|
||||
|
@ -486,6 +475,7 @@ impl SearchBar {
|
|||
}
|
||||
}
|
||||
|
||||
let theme = &cx.app_state::<Settings>().theme.search;
|
||||
editor.highlight_background::<Self>(
|
||||
ranges,
|
||||
theme.match_background,
|
||||
|
@ -531,7 +521,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(
|
||||
|
@ -546,11 +536,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_background::<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();
|
||||
|
|
|
@ -17,13 +17,20 @@ impl Snippet {
|
|||
parse_snippet(source, false, &mut text, &mut tabstops)
|
||||
.context("failed to parse snippet")?;
|
||||
|
||||
let last_tabstop = tabstops
|
||||
.remove(&0)
|
||||
.unwrap_or_else(|| SmallVec::from_iter([text.len() as isize..text.len() as isize]));
|
||||
Ok(Snippet {
|
||||
text,
|
||||
tabstops: tabstops.into_values().chain(Some(last_tabstop)).collect(),
|
||||
})
|
||||
let len = text.len() as isize;
|
||||
let final_tabstop = tabstops.remove(&0);
|
||||
let mut tabstops = tabstops.into_values().collect::<Vec<_>>();
|
||||
|
||||
if let Some(final_tabstop) = final_tabstop {
|
||||
tabstops.push(final_tabstop);
|
||||
} else {
|
||||
let end_tabstop = [len..len].into_iter().collect();
|
||||
if !tabstops.last().map_or(false, |t| *t == end_tabstop) {
|
||||
tabstops.push(end_tabstop);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Snippet { text, tabstops })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +46,13 @@ fn parse_snippet<'a>(
|
|||
Some('$') => {
|
||||
source = parse_tabstop(&source[1..], text, tabstops)?;
|
||||
}
|
||||
Some('\\') => {
|
||||
source = &source[1..];
|
||||
if let Some(c) = source.chars().next() {
|
||||
text.push(c);
|
||||
source = &source[c.len_utf8()..];
|
||||
}
|
||||
}
|
||||
Some('}') => {
|
||||
if nested {
|
||||
return Ok(source);
|
||||
|
@ -48,7 +62,7 @@ fn parse_snippet<'a>(
|
|||
}
|
||||
}
|
||||
Some(_) => {
|
||||
let chunk_end = source.find(&['}', '$']).unwrap_or(source.len());
|
||||
let chunk_end = source.find(&['}', '$', '\\']).unwrap_or(source.len());
|
||||
let (chunk, rest) = source.split_at(chunk_end);
|
||||
text.push_str(chunk);
|
||||
source = rest;
|
||||
|
@ -125,9 +139,22 @@ mod tests {
|
|||
assert_eq!(tabstops(&snippet), &[vec![4..4], vec![3..3], vec![8..8]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_snippet_with_last_tabstop_at_end() {
|
||||
let snippet = Snippet::parse(r#"foo.$1"#).unwrap();
|
||||
|
||||
// If the final tabstop is already at the end of the text, don't insert
|
||||
// an additional tabstop at the end.
|
||||
assert_eq!(snippet.text, r#"foo."#);
|
||||
assert_eq!(tabstops(&snippet), &[vec![4..4]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_snippet_with_explicit_final_tabstop() {
|
||||
let snippet = Snippet::parse(r#"<div class="$1">$0</div>"#).unwrap();
|
||||
|
||||
// If the final tabstop is explicitly specified via '$0', then
|
||||
// don't insert an additional tabstop at the end.
|
||||
assert_eq!(snippet.text, r#"<div class=""></div>"#);
|
||||
assert_eq!(tabstops(&snippet), &[vec![12..12], vec![14..14]]);
|
||||
}
|
||||
|
@ -161,6 +188,17 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_snippet_parsing_with_escaped_chars() {
|
||||
let snippet = Snippet::parse("\"\\$schema\": $1").unwrap();
|
||||
assert_eq!(snippet.text, "\"$schema\": ");
|
||||
assert_eq!(tabstops(&snippet), &[vec![11..11]]);
|
||||
|
||||
let snippet = Snippet::parse("{a\\}").unwrap();
|
||||
assert_eq!(snippet.text, "{a}");
|
||||
assert_eq!(tabstops(&snippet), &[vec![3..3]]);
|
||||
}
|
||||
|
||||
fn tabstops(snippet: &Snippet) -> Vec<Vec<Range<isize>>> {
|
||||
snippet.tabstops.iter().map(|t| t.to_vec()).collect()
|
||||
}
|
||||
|
|
|
@ -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,26 +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, cx: &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) {
|
||||
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;
|
||||
cx.refresh_windows();
|
||||
Self::set_theme(theme, cx);
|
||||
log::info!("reloaded theme {}", current_theme_name);
|
||||
}
|
||||
Err(error) => {
|
||||
|
@ -152,12 +122,10 @@ impl ThemeSelector {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
fn show_selected_theme(&mut self, cx: &mut MutableAppContext) {
|
||||
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, cx);
|
||||
}
|
||||
Ok(theme) => Self::set_theme(theme, cx),
|
||||
Err(error) => {
|
||||
log::error!("error loading theme {}: {}", mat.string, error)
|
||||
}
|
||||
|
@ -173,15 +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>, cx: &mut MutableAppContext) {
|
||||
self.settings_tx.lock().borrow_mut().theme = theme;
|
||||
cx.refresh_windows();
|
||||
}
|
||||
|
||||
fn update_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let background = cx.background().clone();
|
||||
let candidates = self
|
||||
|
@ -247,7 +206,7 @@ impl ThemeSelector {
|
|||
match event {
|
||||
editor::Event::Edited => {
|
||||
self.update_matches(cx);
|
||||
self.select_if_matching(&self.current_theme().name);
|
||||
self.select_if_matching(&cx.app_state::<Settings>().theme.name);
|
||||
self.show_selected_theme(cx);
|
||||
}
|
||||
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||
|
@ -257,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(),
|
||||
|
@ -270,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(
|
||||
|
@ -317,6 +274,13 @@ 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 {
|
||||
|
@ -324,7 +288,7 @@ impl Entity for ThemeSelector {
|
|||
|
||||
fn release(&mut self, cx: &mut MutableAppContext) {
|
||||
if !self.selection_completed {
|
||||
self.set_theme(self.original_theme.clone(), cx);
|
||||
Self::set_theme(self.original_theme.clone(), cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,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(
|
||||
|
@ -344,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)
|
||||
|
@ -371,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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ futures = "0.3"
|
|||
log = "0.4"
|
||||
parking_lot = "0.11.1"
|
||||
postage = { version = "0.4.1", features = ["futures-traits"] }
|
||||
schemars = "0.8"
|
||||
serde = { version = "1", features = ["derive", "rc"] }
|
||||
serde_json = { version = "1", features = ["preserve_order"] }
|
||||
smallvec = { version = "1.6", features = ["union"] }
|
||||
|
||||
[dev-dependencies]
|
||||
client = { path = "../client", features = ["test-support"] }
|
||||
gpui = { path = "../gpui", features = ["test-support"] }
|
||||
project = { path = "../project", features = ["test-support"] }
|
||||
serde_json = { version = "1.0.64", features = ["preserve_order"] }
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -1,34 +1,127 @@
|
|||
use anyhow::Result;
|
||||
use gpui::font_cache::{FamilyId, FontCache};
|
||||
use futures::{stream, SinkExt, StreamExt as _};
|
||||
use gpui::{
|
||||
executor,
|
||||
font_cache::{FamilyId, FontCache},
|
||||
};
|
||||
use language::Language;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use theme::Theme;
|
||||
use postage::{prelude::Stream, watch};
|
||||
use project::Fs;
|
||||
use schemars::{schema_for, JsonSchema};
|
||||
use serde::Deserialize;
|
||||
use std::{collections::HashMap, path::Path, sync::Arc, time::Duration};
|
||||
use theme::{Theme, ThemeRegistry};
|
||||
use util::ResultExt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Settings {
|
||||
pub buffer_font_family: FamilyId,
|
||||
pub buffer_font_size: f32,
|
||||
pub tab_size: usize,
|
||||
soft_wrap: SoftWrap,
|
||||
preferred_line_length: u32,
|
||||
overrides: HashMap<Arc<str>, Override>,
|
||||
pub soft_wrap: SoftWrap,
|
||||
pub preferred_line_length: u32,
|
||||
pub language_overrides: HashMap<Arc<str>, LanguageOverride>,
|
||||
pub theme: Arc<Theme>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Override {
|
||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct LanguageOverride {
|
||||
pub tab_size: Option<usize>,
|
||||
pub soft_wrap: Option<SoftWrap>,
|
||||
pub preferred_line_length: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SoftWrap {
|
||||
None,
|
||||
EditorWidth,
|
||||
PreferredLineLength,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SettingsFile(watch::Receiver<SettingsFileContent>);
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
struct SettingsFileContent {
|
||||
#[serde(default)]
|
||||
buffer_font_family: Option<String>,
|
||||
#[serde(default)]
|
||||
buffer_font_size: Option<f32>,
|
||||
#[serde(flatten)]
|
||||
editor: LanguageOverride,
|
||||
#[serde(default)]
|
||||
language_overrides: HashMap<Arc<str>, LanguageOverride>,
|
||||
#[serde(default)]
|
||||
theme: Option<String>,
|
||||
}
|
||||
|
||||
impl SettingsFile {
|
||||
pub async fn new(
|
||||
fs: Arc<dyn Fs>,
|
||||
executor: &executor::Background,
|
||||
path: impl Into<Arc<Path>>,
|
||||
) -> Self {
|
||||
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, rx) = watch::channel_with(settings);
|
||||
executor
|
||||
.spawn(async move {
|
||||
while events.next().await.is_some() {
|
||||
if let Some(settings) = Self::load(fs.clone(), &path).await {
|
||||
if tx.send(settings).await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
Self(rx)
|
||||
}
|
||||
|
||||
async fn load(fs: Arc<dyn Fs>, path: &Path) -> Option<SettingsFileContent> {
|
||||
if fs.is_file(&path).await {
|
||||
fs.load(&path)
|
||||
.await
|
||||
.log_err()
|
||||
.and_then(|data| serde_json::from_str(&data).log_err())
|
||||
} else {
|
||||
Some(SettingsFileContent::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn file_json_schema() -> serde_json::Value {
|
||||
serde_json::to_value(schema_for!(SettingsFileContent)).unwrap()
|
||||
}
|
||||
|
||||
pub fn from_files(
|
||||
defaults: Self,
|
||||
sources: Vec<SettingsFile>,
|
||||
theme_registry: Arc<ThemeRegistry>,
|
||||
font_cache: Arc<FontCache>,
|
||||
) -> 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(
|
||||
buffer_font_family: &str,
|
||||
font_cache: &FontCache,
|
||||
|
@ -40,35 +133,38 @@ impl Settings {
|
|||
tab_size: 4,
|
||||
soft_wrap: SoftWrap::None,
|
||||
preferred_line_length: 80,
|
||||
overrides: Default::default(),
|
||||
language_overrides: Default::default(),
|
||||
theme,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_tab_size(mut self, tab_size: usize) -> Self {
|
||||
self.tab_size = tab_size;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_overrides(
|
||||
mut self,
|
||||
language_name: impl Into<Arc<str>>,
|
||||
overrides: Override,
|
||||
overrides: LanguageOverride,
|
||||
) -> Self {
|
||||
self.overrides.insert(language_name.into(), overrides);
|
||||
self.language_overrides
|
||||
.insert(language_name.into(), overrides);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tab_size(&self, language: Option<&Arc<Language>>) -> usize {
|
||||
language
|
||||
.and_then(|language| self.language_overrides.get(language.name().as_ref()))
|
||||
.and_then(|settings| settings.tab_size)
|
||||
.unwrap_or(self.tab_size)
|
||||
}
|
||||
|
||||
pub fn soft_wrap(&self, language: Option<&Arc<Language>>) -> SoftWrap {
|
||||
language
|
||||
.and_then(|language| self.overrides.get(language.name().as_ref()))
|
||||
.and_then(|language| self.language_overrides.get(language.name().as_ref()))
|
||||
.and_then(|settings| settings.soft_wrap)
|
||||
.unwrap_or(self.soft_wrap)
|
||||
}
|
||||
|
||||
pub fn preferred_line_length(&self, language: Option<&Arc<Language>>) -> u32 {
|
||||
language
|
||||
.and_then(|language| self.overrides.get(language.name().as_ref()))
|
||||
.and_then(|language| self.language_overrides.get(language.name().as_ref()))
|
||||
.and_then(|settings| settings.preferred_line_length)
|
||||
.unwrap_or(self.preferred_line_length)
|
||||
}
|
||||
|
@ -81,8 +177,143 @@ impl Settings {
|
|||
tab_size: 4,
|
||||
soft_wrap: SoftWrap::None,
|
||||
preferred_line_length: 80,
|
||||
overrides: Default::default(),
|
||||
language_overrides: Default::default(),
|
||||
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), || Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(
|
||||
&mut self,
|
||||
data: &SettingsFileContent,
|
||||
theme_registry: &ThemeRegistry,
|
||||
font_cache: &FontCache,
|
||||
) {
|
||||
if let Some(value) = &data.buffer_font_family {
|
||||
if let Some(id) = font_cache.load_family(&[value]).log_err() {
|
||||
self.buffer_font_family = id;
|
||||
}
|
||||
}
|
||||
if let Some(value) = &data.theme {
|
||||
if let Some(theme) = theme_registry.get(value).log_err() {
|
||||
self.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
merge(&mut self.buffer_font_size, data.buffer_font_size);
|
||||
merge(&mut self.soft_wrap, data.editor.soft_wrap);
|
||||
merge(&mut self.tab_size, data.editor.tab_size);
|
||||
merge(
|
||||
&mut self.preferred_line_length,
|
||||
data.editor.preferred_line_length,
|
||||
);
|
||||
|
||||
for (language_name, settings) in &data.language_overrides {
|
||||
let target = self
|
||||
.language_overrides
|
||||
.entry(language_name.clone())
|
||||
.or_default();
|
||||
|
||||
merge_option(&mut target.tab_size, settings.tab_size);
|
||||
merge_option(&mut target.soft_wrap, settings.soft_wrap);
|
||||
merge_option(
|
||||
&mut target.preferred_line_length,
|
||||
settings.preferred_line_length,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn merge<T: Copy>(target: &mut T, value: Option<T>) {
|
||||
if let Some(value) = value {
|
||||
*target = value;
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_option<T: Copy>(target: &mut Option<T>, value: Option<T>) {
|
||||
if value.is_some() {
|
||||
*target = value;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use project::FakeFs;
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_settings_from_files(cx: &mut gpui::TestAppContext) {
|
||||
let executor = cx.background();
|
||||
let fs = FakeFs::new(executor.clone());
|
||||
|
||||
fs.save(
|
||||
"/settings1.json".as_ref(),
|
||||
&r#"
|
||||
{
|
||||
"buffer_font_size": 24,
|
||||
"soft_wrap": "editor_width",
|
||||
"language_overrides": {
|
||||
"Markdown": {
|
||||
"preferred_line_length": 100,
|
||||
"soft_wrap": "preferred_line_length"
|
||||
}
|
||||
}
|
||||
}
|
||||
"#
|
||||
.into(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let source1 = SettingsFile::new(fs.clone(), &executor, "/settings1.json".as_ref()).await;
|
||||
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(
|
||||
cx.read(Settings::test),
|
||||
vec![source1, source2, source3],
|
||||
ThemeRegistry::new((), cx.font_cache()),
|
||||
cx.font_cache(),
|
||||
);
|
||||
|
||||
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);
|
||||
assert_eq!(settings.tab_size, 4);
|
||||
assert_eq!(md_settings.soft_wrap, Some(SoftWrap::PreferredLineLength));
|
||||
assert_eq!(md_settings.preferred_line_length, Some(100));
|
||||
|
||||
fs.save(
|
||||
"/settings2.json".as_ref(),
|
||||
&r#"
|
||||
{
|
||||
"tab_size": 2,
|
||||
"soft_wrap": "none",
|
||||
"language_overrides": {
|
||||
"Markdown": {
|
||||
"preferred_line_length": 120
|
||||
}
|
||||
}
|
||||
}
|
||||
"#
|
||||
.into(),
|
||||
)
|
||||
.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);
|
||||
assert_eq!(settings.tab_size, 2);
|
||||
assert_eq!(md_settings.soft_wrap, Some(SoftWrap::PreferredLineLength));
|
||||
assert_eq!(md_settings.preferred_line_length, Some(120));
|
||||
|
||||
fs.remove_file("/settings2.json".as_ref(), Default::default())
|
||||
.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))
|
||||
|
|
|
@ -533,12 +533,7 @@ impl LspAdapter for JsonLspAdapter {
|
|||
}
|
||||
|
||||
pub fn build_language_registry(login_shell_env_loaded: Task<()>) -> LanguageRegistry {
|
||||
let mut languages = LanguageRegistry::new(login_shell_env_loaded);
|
||||
languages.set_language_server_download_dir(
|
||||
dirs::home_dir()
|
||||
.expect("failed to determine home directory")
|
||||
.join(".zed"),
|
||||
);
|
||||
let languages = LanguageRegistry::new(login_shell_env_loaded);
|
||||
languages.add(Arc::new(c()));
|
||||
languages.add(Arc::new(json()));
|
||||
languages.add(Arc::new(rust()));
|
||||
|
|
|
@ -4,15 +4,21 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use client::{self, http, ChannelList, UserStore};
|
||||
use fs::OpenOptions;
|
||||
use futures::{channel::oneshot, StreamExt};
|
||||
use gpui::{App, AssetSource, Task};
|
||||
use log::LevelFilter;
|
||||
use parking_lot::Mutex;
|
||||
use project::Fs;
|
||||
use simplelog::SimpleLogger;
|
||||
use smol::process::Command;
|
||||
use std::{env, fs, path::PathBuf, sync::Arc};
|
||||
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use util::ResultExt;
|
||||
use workspace::{self, settings, AppState, OpenNew, OpenParams, OpenPaths, Settings};
|
||||
use workspace::{
|
||||
self,
|
||||
settings::{self, SettingsFile},
|
||||
AppState, OpenNew, OpenParams, OpenPaths, Settings,
|
||||
};
|
||||
use zed::{
|
||||
self, assets::Assets, build_window_options, build_workspace, fs::RealFs, language, menus,
|
||||
};
|
||||
|
@ -23,25 +29,26 @@ fn main() {
|
|||
let app = gpui::App::new(Assets).unwrap();
|
||||
load_embedded_fonts(&app);
|
||||
|
||||
let fs = Arc::new(RealFs);
|
||||
let themes = ThemeRegistry::new(Assets, app.font_cache());
|
||||
let theme = themes.get(DEFAULT_THEME_NAME).unwrap();
|
||||
let settings = Settings::new("Zed Mono", &app.font_cache(), theme)
|
||||
let default_settings = Settings::new("Zed Mono", &app.font_cache(), theme)
|
||||
.unwrap()
|
||||
.with_overrides(
|
||||
language::PLAIN_TEXT.name(),
|
||||
settings::Override {
|
||||
settings::LanguageOverride {
|
||||
soft_wrap: Some(settings::SoftWrap::PreferredLineLength),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.with_overrides(
|
||||
"Markdown",
|
||||
settings::Override {
|
||||
settings::LanguageOverride {
|
||||
soft_wrap: Some(settings::SoftWrap::PreferredLineLength),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let (settings_tx, settings) = postage::watch::channel_with(settings);
|
||||
let settings_file = load_settings_file(&app, fs.clone());
|
||||
|
||||
let login_shell_env_loaded = if stdout_is_a_pty() {
|
||||
Task::ready(())
|
||||
|
@ -51,14 +58,14 @@ fn main() {
|
|||
})
|
||||
};
|
||||
|
||||
let languages = Arc::new(language::build_language_registry(login_shell_env_loaded));
|
||||
languages.set_theme(&settings.borrow().theme.editor.syntax);
|
||||
|
||||
app.run(move |cx| {
|
||||
let http = http::client();
|
||||
let client = client::Client::new(http.clone());
|
||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
|
||||
let mut path_openers = Vec::new();
|
||||
let mut languages = language::build_language_registry(login_shell_env_loaded);
|
||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
|
||||
let channel_list =
|
||||
cx.add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx));
|
||||
|
||||
project::Project::init(&client);
|
||||
client::Channel::init(&client);
|
||||
|
@ -84,23 +91,42 @@ fn main() {
|
|||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
let settings_file = cx.background().block(settings_file).unwrap();
|
||||
let mut settings_rx = Settings::from_files(
|
||||
default_settings,
|
||||
vec![settings_file],
|
||||
themes.clone(),
|
||||
cx.font_cache().clone(),
|
||||
);
|
||||
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.theme.editor.syntax);
|
||||
cx.add_app_state(settings);
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
languages: languages.clone(),
|
||||
settings_tx: Arc::new(Mutex::new(settings_tx)),
|
||||
settings,
|
||||
languages: Arc::new(languages),
|
||||
themes,
|
||||
channel_list: cx
|
||||
.add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
|
||||
channel_list,
|
||||
client,
|
||||
user_store,
|
||||
fs: Arc::new(RealFs),
|
||||
fs,
|
||||
path_openers: Arc::from(path_openers),
|
||||
build_window_options: &build_window_options,
|
||||
build_workspace: &build_workspace,
|
||||
});
|
||||
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()));
|
||||
|
||||
|
@ -208,3 +234,16 @@ fn load_embedded_fonts(app: &App) {
|
|||
.add_fonts(&embedded_fonts.into_inner())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn load_settings_file(app: &App, fs: Arc<dyn Fs>) -> oneshot::Receiver<SettingsFile> {
|
||||
let executor = app.background();
|
||||
let (tx, rx) = oneshot::channel();
|
||||
executor
|
||||
.clone()
|
||||
.spawn(async move {
|
||||
let file = SettingsFile::new(fs, &executor, zed::SETTINGS_PATH.clone()).await;
|
||||
tx.send(file).ok()
|
||||
})
|
||||
.detach();
|
||||
rx
|
||||
}
|
||||
|
|
|
@ -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)),
|
||||
|
|
|
@ -16,30 +16,58 @@ use gpui::{
|
|||
platform::{WindowBounds, WindowOptions},
|
||||
ModelHandle, ViewContext,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
pub use lsp;
|
||||
use project::Project;
|
||||
pub use project::{self, fs};
|
||||
use project_panel::ProjectPanel;
|
||||
use std::sync::Arc;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
pub use workspace;
|
||||
use workspace::{AppState, Workspace, WorkspaceParams};
|
||||
use workspace::{AppState, Settings, Workspace, WorkspaceParams};
|
||||
|
||||
action!(About);
|
||||
action!(Quit);
|
||||
action!(OpenSettings);
|
||||
action!(AdjustBufferFontSize, f32);
|
||||
|
||||
const MIN_FONT_SIZE: f32 = 6.0;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref ROOT_PATH: PathBuf = dirs::home_dir()
|
||||
.expect("failed to determine home directory")
|
||||
.join(".zed");
|
||||
pub static ref SETTINGS_PATH: PathBuf = ROOT_PATH.join("settings.json");
|
||||
}
|
||||
|
||||
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, cx| {
|
||||
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;
|
||||
cx.refresh_windows();
|
||||
cx.update_app_state::<Settings, _, _>(|settings, cx| {
|
||||
settings.buffer_font_size =
|
||||
(settings.buffer_font_size + action.0).max(MIN_FONT_SIZE);
|
||||
cx.refresh_windows();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_action({
|
||||
let fs = app_state.fs.clone();
|
||||
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
|
||||
let fs = fs.clone();
|
||||
cx.spawn(move |workspace, mut cx| async move {
|
||||
if !fs.is_file(&SETTINGS_PATH).await {
|
||||
fs.create_dir(&ROOT_PATH).await?;
|
||||
fs.create_file(&SETTINGS_PATH, Default::default()).await?;
|
||||
}
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_paths(&[SETTINGS_PATH.clone()], cx)
|
||||
})
|
||||
.await;
|
||||
Ok::<_, anyhow::Error>(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -48,6 +76,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
|||
cx.add_bindings(vec![
|
||||
Binding::new("cmd-=", AdjustBufferFontSize(1.), None),
|
||||
Binding::new("cmd--", AdjustBufferFontSize(-1.), None),
|
||||
Binding::new("cmd-,", OpenSettings, None),
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -61,16 +90,29 @@ 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(),
|
||||
};
|
||||
let mut workspace = Workspace::new(&workspace_params, cx);
|
||||
let project = workspace.project().clone();
|
||||
|
||||
project.update(cx, |project, _| {
|
||||
project.set_language_server_settings(serde_json::json!({
|
||||
"json": {
|
||||
"schemas": [
|
||||
{
|
||||
"fileMatch": "**/.zed/settings.json",
|
||||
"schema": Settings::file_json_schema(),
|
||||
}
|
||||
]
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
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",
|
||||
|
@ -80,35 +122,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);
|
||||
|
|
Loading…
Reference in a new issue