Merge branch 'main' into collab-panel
This commit is contained in:
commit
c537cf2a57
92 changed files with 2015 additions and 1591 deletions
|
@ -570,8 +570,9 @@ impl TestClient {
|
|||
|
||||
// We use a workspace container so that we don't need to remove the window in order to
|
||||
// drop the workspace and we can use a ViewHandle instead.
|
||||
let (window_id, container) = cx.add_window(|_| WorkspaceContainer { workspace: None });
|
||||
let workspace = cx.add_view(window_id, |cx| {
|
||||
let window = cx.add_window(|_| WorkspaceContainer { workspace: None });
|
||||
let container = window.root(cx);
|
||||
let workspace = window.add_view(cx, |cx| {
|
||||
Workspace::new(0, project.clone(), self.app_state.clone(), cx)
|
||||
});
|
||||
container.update(cx, |container, cx| {
|
||||
|
|
|
@ -7,8 +7,7 @@ use client::{User, RECEIVE_TIMEOUT};
|
|||
use collections::HashSet;
|
||||
use editor::{
|
||||
test::editor_test_context::EditorTestContext, ConfirmCodeAction, ConfirmCompletion,
|
||||
ConfirmRename, Editor, ExcerptRange, MultiBuffer, Redo, Rename, ToOffset, ToggleCodeActions,
|
||||
Undo,
|
||||
ConfirmRename, Editor, ExcerptRange, MultiBuffer, Redo, Rename, ToggleCodeActions, Undo,
|
||||
};
|
||||
use fs::{repository::GitFileStatus, FakeFs, Fs as _, LineEnding, RemoveOptions};
|
||||
use futures::StreamExt as _;
|
||||
|
@ -1208,7 +1207,7 @@ async fn test_share_project(
|
|||
cx_c: &mut TestAppContext,
|
||||
) {
|
||||
deterministic.forbid_parking();
|
||||
let (window_b, _) = cx_b.add_window(|_| EmptyView);
|
||||
let window_b = cx_b.add_window(|_| EmptyView);
|
||||
let mut server = TestServer::start(&deterministic).await;
|
||||
let client_a = server.create_client(cx_a, "user_a").await;
|
||||
let client_b = server.create_client(cx_b, "user_b").await;
|
||||
|
@ -1316,7 +1315,7 @@ async fn test_share_project(
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let editor_b = cx_b.add_view(window_b, |cx| Editor::for_buffer(buffer_b, None, cx));
|
||||
let editor_b = window_b.add_view(cx_b, |cx| Editor::for_buffer(buffer_b, None, cx));
|
||||
|
||||
// Client A sees client B's selection
|
||||
deterministic.run_until_parked();
|
||||
|
@ -1499,8 +1498,9 @@ async fn test_host_disconnect(
|
|||
deterministic.run_until_parked();
|
||||
assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
|
||||
|
||||
let (window_id_b, workspace_b) =
|
||||
let window_b =
|
||||
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
|
||||
let workspace_b = window_b.root(cx_b);
|
||||
let editor_b = workspace_b
|
||||
.update(cx_b, |workspace, cx| {
|
||||
workspace.open_path((worktree_id, "b.txt"), None, true, cx)
|
||||
|
@ -1509,9 +1509,7 @@ async fn test_host_disconnect(
|
|||
.unwrap()
|
||||
.downcast::<Editor>()
|
||||
.unwrap();
|
||||
assert!(cx_b
|
||||
.read_window(window_id_b, |cx| editor_b.is_focused(cx))
|
||||
.unwrap());
|
||||
assert!(window_b.read_with(cx_b, |cx| editor_b.is_focused(cx)));
|
||||
editor_b.update(cx_b, |editor, cx| editor.insert("X", cx));
|
||||
assert!(cx_b.is_window_edited(workspace_b.window_id()));
|
||||
|
||||
|
@ -1525,7 +1523,7 @@ async fn test_host_disconnect(
|
|||
assert!(worktree_a.read_with(cx_a, |tree, _| !tree.as_local().unwrap().is_shared()));
|
||||
|
||||
// Ensure client B's edited state is reset and that the whole window is blurred.
|
||||
cx_b.read_window(window_id_b, |cx| {
|
||||
window_b.read_with(cx_b, |cx| {
|
||||
assert_eq!(cx.focused_view_id(), None);
|
||||
});
|
||||
assert!(!cx_b.is_window_edited(workspace_b.window_id()));
|
||||
|
@ -3440,13 +3438,11 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
|
|||
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
let (window_a, _) = cx_a.add_window(|_| EmptyView);
|
||||
let editor_a = cx_a.add_view(window_a, |cx| {
|
||||
Editor::for_buffer(buffer_a, Some(project_a), cx)
|
||||
});
|
||||
let window_a = cx_a.add_window(|_| EmptyView);
|
||||
let editor_a = window_a.add_view(cx_a, |cx| Editor::for_buffer(buffer_a, Some(project_a), cx));
|
||||
let mut editor_cx_a = EditorTestContext {
|
||||
cx: cx_a,
|
||||
window_id: window_a,
|
||||
window_id: window_a.window_id(),
|
||||
editor: editor_a,
|
||||
};
|
||||
|
||||
|
@ -3455,13 +3451,11 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
|
|||
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
let (window_b, _) = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = cx_b.add_view(window_b, |cx| {
|
||||
Editor::for_buffer(buffer_b, Some(project_b), cx)
|
||||
});
|
||||
let window_b = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = window_b.add_view(cx_b, |cx| Editor::for_buffer(buffer_b, Some(project_b), cx));
|
||||
let mut editor_cx_b = EditorTestContext {
|
||||
cx: cx_b,
|
||||
window_id: window_b,
|
||||
window_id: window_b.window_id(),
|
||||
editor: editor_b,
|
||||
};
|
||||
|
||||
|
@ -4200,8 +4194,8 @@ async fn test_collaborating_with_completion(
|
|||
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
let (window_b, _) = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = cx_b.add_view(window_b, |cx| {
|
||||
let window_b = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = window_b.add_view(cx_b, |cx| {
|
||||
Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx)
|
||||
});
|
||||
|
||||
|
@ -5312,8 +5306,9 @@ async fn test_collaborating_with_code_actions(
|
|||
|
||||
// Join the project as client B.
|
||||
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
||||
let (_window_b, workspace_b) =
|
||||
let window_b =
|
||||
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
|
||||
let workspace_b = window_b.root(cx_b);
|
||||
let editor_b = workspace_b
|
||||
.update(cx_b, |workspace, cx| {
|
||||
workspace.open_path((worktree_id, "main.rs"), None, true, cx)
|
||||
|
@ -5537,8 +5532,9 @@ async fn test_collaborating_with_renames(
|
|||
.unwrap();
|
||||
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
||||
|
||||
let (_window_b, workspace_b) =
|
||||
let window_b =
|
||||
cx_b.add_window(|cx| Workspace::new(0, project_b.clone(), client_b.app_state.clone(), cx));
|
||||
let workspace_b = window_b.root(cx_b);
|
||||
let editor_b = workspace_b
|
||||
.update(cx_b, |workspace, cx| {
|
||||
workspace.open_path((worktree_id, "one.rs"), None, true, cx)
|
||||
|
@ -5569,6 +5565,7 @@ async fn test_collaborating_with_renames(
|
|||
.unwrap();
|
||||
prepare_rename.await.unwrap();
|
||||
editor_b.update(cx_b, |editor, cx| {
|
||||
use editor::ToOffset;
|
||||
let rename = editor.pending_rename().unwrap();
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
assert_eq!(
|
||||
|
@ -7599,8 +7596,8 @@ async fn test_on_input_format_from_host_to_guest(
|
|||
.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
let (window_a, _) = cx_a.add_window(|_| EmptyView);
|
||||
let editor_a = cx_a.add_view(window_a, |cx| {
|
||||
let window_a = cx_a.add_window(|_| EmptyView);
|
||||
let editor_a = window_a.add_view(cx_a, |cx| {
|
||||
Editor::for_buffer(buffer_a, Some(project_a.clone()), cx)
|
||||
});
|
||||
|
||||
|
@ -7728,8 +7725,8 @@ async fn test_on_input_format_from_guest_to_host(
|
|||
.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
let (window_b, _) = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = cx_b.add_view(window_b, |cx| {
|
||||
let window_b = cx_b.add_window(|_| EmptyView);
|
||||
let editor_b = window_b.add_view(cx_b, |cx| {
|
||||
Editor::for_buffer(buffer_b, Some(project_b.clone()), cx)
|
||||
});
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||
|
||||
for screen in cx.platform().screens() {
|
||||
let screen_bounds = screen.bounds();
|
||||
let (window_id, _) = cx.add_window(
|
||||
let window = cx.add_window(
|
||||
WindowOptions {
|
||||
bounds: WindowBounds::Fixed(RectF::new(
|
||||
screen_bounds.upper_right()
|
||||
|
@ -49,7 +49,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||
|_| IncomingCallNotification::new(incoming_call.clone(), app_state.clone()),
|
||||
);
|
||||
|
||||
notification_windows.push(window_id);
|
||||
notification_windows.push(window.window_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||
|
||||
for screen in cx.platform().screens() {
|
||||
let screen_bounds = screen.bounds();
|
||||
let (window_id, _) = cx.add_window(
|
||||
let window = cx.add_window(
|
||||
WindowOptions {
|
||||
bounds: WindowBounds::Fixed(RectF::new(
|
||||
screen_bounds.upper_right() - vec2f(PADDING + window_size.x(), PADDING),
|
||||
|
@ -52,7 +52,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||
notification_windows
|
||||
.entry(*project_id)
|
||||
.or_insert(Vec::new())
|
||||
.push(window_id);
|
||||
.push(window.window_id());
|
||||
}
|
||||
}
|
||||
room::Event::RemoteProjectUnshared { project_id } => {
|
||||
|
|
|
@ -295,7 +295,9 @@ mod tests {
|
|||
let app_state = init_test(cx);
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let editor = cx.add_view(window_id, |cx| {
|
||||
let mut editor = Editor::single_line(None, cx);
|
||||
editor.set_text("abc", cx);
|
||||
|
|
|
@ -4,7 +4,7 @@ use gpui::{
|
|||
geometry::rect::RectF,
|
||||
platform::{WindowBounds, WindowKind, WindowOptions},
|
||||
AnyElement, AnyViewHandle, AppContext, ClipboardItem, Element, Entity, View, ViewContext,
|
||||
ViewHandle,
|
||||
WindowHandle,
|
||||
};
|
||||
use theme::ui::modal;
|
||||
|
||||
|
@ -18,43 +18,43 @@ const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
|
|||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
if let Some(copilot) = Copilot::global(cx) {
|
||||
let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
|
||||
let mut verification_window: Option<WindowHandle<CopilotCodeVerification>> = None;
|
||||
cx.observe(&copilot, move |copilot, cx| {
|
||||
let status = copilot.read(cx).status();
|
||||
|
||||
match &status {
|
||||
crate::Status::SigningIn { prompt } => {
|
||||
if let Some(code_verification_handle) = code_verification.as_mut() {
|
||||
let window_id = code_verification_handle.window_id();
|
||||
let updated = cx.update_window(window_id, |cx| {
|
||||
code_verification_handle.update(cx, |code_verification, cx| {
|
||||
code_verification.set_status(status.clone(), cx)
|
||||
});
|
||||
cx.activate_window();
|
||||
});
|
||||
if updated.is_none() {
|
||||
code_verification = Some(create_copilot_auth_window(cx, &status));
|
||||
if let Some(window) = verification_window.as_mut() {
|
||||
let updated = window
|
||||
.root(cx)
|
||||
.map(|root| {
|
||||
root.update(cx, |verification, cx| {
|
||||
verification.set_status(status.clone(), cx);
|
||||
cx.activate_window();
|
||||
})
|
||||
})
|
||||
.is_some();
|
||||
if !updated {
|
||||
verification_window = Some(create_copilot_auth_window(cx, &status));
|
||||
}
|
||||
} else if let Some(_prompt) = prompt {
|
||||
code_verification = Some(create_copilot_auth_window(cx, &status));
|
||||
verification_window = Some(create_copilot_auth_window(cx, &status));
|
||||
}
|
||||
}
|
||||
Status::Authorized | Status::Unauthorized => {
|
||||
if let Some(code_verification) = code_verification.as_ref() {
|
||||
let window_id = code_verification.window_id();
|
||||
cx.update_window(window_id, |cx| {
|
||||
code_verification.update(cx, |code_verification, cx| {
|
||||
code_verification.set_status(status, cx)
|
||||
if let Some(window) = verification_window.as_ref() {
|
||||
if let Some(verification) = window.root(cx) {
|
||||
verification.update(cx, |verification, cx| {
|
||||
verification.set_status(status, cx);
|
||||
cx.platform().activate(true);
|
||||
cx.activate_window();
|
||||
});
|
||||
|
||||
cx.platform().activate(true);
|
||||
cx.activate_window();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if let Some(code_verification) = code_verification.take() {
|
||||
cx.update_window(code_verification.window_id(), |cx| cx.remove_window());
|
||||
if let Some(code_verification) = verification_window.take() {
|
||||
code_verification.update(cx, |cx| cx.remove_window());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
fn create_copilot_auth_window(
|
||||
cx: &mut AppContext,
|
||||
status: &Status,
|
||||
) -> ViewHandle<CopilotCodeVerification> {
|
||||
) -> WindowHandle<CopilotCodeVerification> {
|
||||
let window_size = theme::current(cx).copilot.modal.dimensions();
|
||||
let window_options = WindowOptions {
|
||||
bounds: WindowBounds::Fixed(RectF::new(Default::default(), window_size)),
|
||||
|
@ -78,10 +78,9 @@ fn create_copilot_auth_window(
|
|||
is_movable: true,
|
||||
screen: None,
|
||||
};
|
||||
let (_, view) = cx.add_window(window_options, |_cx| {
|
||||
cx.add_window(window_options, |_cx| {
|
||||
CopilotCodeVerification::new(status.clone())
|
||||
});
|
||||
view
|
||||
})
|
||||
}
|
||||
|
||||
pub struct CopilotCodeVerification {
|
||||
|
|
|
@ -855,7 +855,9 @@ mod tests {
|
|||
|
||||
let language_server_id = LanguageServerId(0);
|
||||
let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Create some diagnostics
|
||||
project.update(cx, |project, cx| {
|
||||
|
@ -1248,7 +1250,9 @@ mod tests {
|
|||
let server_id_1 = LanguageServerId(100);
|
||||
let server_id_2 = LanguageServerId(101);
|
||||
let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
let view = cx.add_view(window_id, |cx| {
|
||||
ProjectDiagnosticsEditor::new(project.clone(), workspace.downgrade(), cx)
|
||||
|
|
|
@ -47,6 +47,7 @@ workspace = { path = "../workspace" }
|
|||
|
||||
aho-corasick = "0.7"
|
||||
anyhow.workspace = true
|
||||
convert_case = "0.6.0"
|
||||
futures.workspace = true
|
||||
indoc = "1.0.4"
|
||||
itertools = "0.10"
|
||||
|
@ -56,12 +57,12 @@ ordered-float.workspace = true
|
|||
parking_lot.workspace = true
|
||||
postage.workspace = true
|
||||
pulldown-cmark = { version = "0.9.2", default-features = false }
|
||||
rand.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
smallvec.workspace = true
|
||||
smol.workspace = true
|
||||
rand.workspace = true
|
||||
|
||||
tree-sitter-rust = { workspace = true, optional = true }
|
||||
tree-sitter-html = { workspace = true, optional = true }
|
||||
|
|
|
@ -28,6 +28,7 @@ use blink_manager::BlinkManager;
|
|||
use client::{ClickhouseEvent, TelemetrySettings};
|
||||
use clock::{Global, ReplicaId};
|
||||
use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
|
||||
use convert_case::{Case, Casing};
|
||||
use copilot::Copilot;
|
||||
pub use display_map::DisplayPoint;
|
||||
use display_map::*;
|
||||
|
@ -231,6 +232,13 @@ actions!(
|
|||
SortLinesCaseInsensitive,
|
||||
ReverseLines,
|
||||
ShuffleLines,
|
||||
ConvertToUpperCase,
|
||||
ConvertToLowerCase,
|
||||
ConvertToTitleCase,
|
||||
ConvertToSnakeCase,
|
||||
ConvertToKebabCase,
|
||||
ConvertToUpperCamelCase,
|
||||
ConvertToLowerCamelCase,
|
||||
Transpose,
|
||||
Cut,
|
||||
Copy,
|
||||
|
@ -353,6 +361,13 @@ pub fn init(cx: &mut AppContext) {
|
|||
cx.add_action(Editor::sort_lines_case_insensitive);
|
||||
cx.add_action(Editor::reverse_lines);
|
||||
cx.add_action(Editor::shuffle_lines);
|
||||
cx.add_action(Editor::convert_to_upper_case);
|
||||
cx.add_action(Editor::convert_to_lower_case);
|
||||
cx.add_action(Editor::convert_to_title_case);
|
||||
cx.add_action(Editor::convert_to_snake_case);
|
||||
cx.add_action(Editor::convert_to_kebab_case);
|
||||
cx.add_action(Editor::convert_to_upper_camel_case);
|
||||
cx.add_action(Editor::convert_to_lower_camel_case);
|
||||
cx.add_action(Editor::delete_to_previous_word_start);
|
||||
cx.add_action(Editor::delete_to_previous_subword_start);
|
||||
cx.add_action(Editor::delete_to_next_word_end);
|
||||
|
@ -4306,6 +4321,97 @@ impl Editor {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn convert_to_upper_case(&mut self, _: &ConvertToUpperCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_uppercase())
|
||||
}
|
||||
|
||||
pub fn convert_to_lower_case(&mut self, _: &ConvertToLowerCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_lowercase())
|
||||
}
|
||||
|
||||
pub fn convert_to_title_case(&mut self, _: &ConvertToTitleCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Title))
|
||||
}
|
||||
|
||||
pub fn convert_to_snake_case(&mut self, _: &ConvertToSnakeCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Snake))
|
||||
}
|
||||
|
||||
pub fn convert_to_kebab_case(&mut self, _: &ConvertToKebabCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Kebab))
|
||||
}
|
||||
|
||||
pub fn convert_to_upper_camel_case(
|
||||
&mut self,
|
||||
_: &ConvertToUpperCamelCase,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::UpperCamel))
|
||||
}
|
||||
|
||||
pub fn convert_to_lower_camel_case(
|
||||
&mut self,
|
||||
_: &ConvertToLowerCamelCase,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Camel))
|
||||
}
|
||||
|
||||
fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)
|
||||
where
|
||||
Fn: FnMut(&str) -> String,
|
||||
{
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = self.buffer.read(cx).snapshot(cx);
|
||||
|
||||
let mut new_selections = Vec::new();
|
||||
let mut edits = Vec::new();
|
||||
let mut selection_adjustment = 0i32;
|
||||
|
||||
for selection in self.selections.all::<usize>(cx) {
|
||||
let selection_is_empty = selection.is_empty();
|
||||
|
||||
let (start, end) = if selection_is_empty {
|
||||
let word_range = movement::surrounding_word(
|
||||
&display_map,
|
||||
selection.start.to_display_point(&display_map),
|
||||
);
|
||||
let start = word_range.start.to_offset(&display_map, Bias::Left);
|
||||
let end = word_range.end.to_offset(&display_map, Bias::Left);
|
||||
(start, end)
|
||||
} else {
|
||||
(selection.start, selection.end)
|
||||
};
|
||||
|
||||
let text = buffer.text_for_range(start..end).collect::<String>();
|
||||
let old_length = text.len() as i32;
|
||||
let text = callback(&text);
|
||||
|
||||
new_selections.push(Selection {
|
||||
start: (start as i32 - selection_adjustment) as usize,
|
||||
end: ((start + text.len()) as i32 - selection_adjustment) as usize,
|
||||
goal: SelectionGoal::None,
|
||||
..selection
|
||||
});
|
||||
|
||||
selection_adjustment += old_length - text.len() as i32;
|
||||
|
||||
edits.push((start..end, text));
|
||||
}
|
||||
|
||||
self.transact(cx, |this, cx| {
|
||||
this.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit(edits, None, cx);
|
||||
});
|
||||
|
||||
this.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select(new_selections);
|
||||
});
|
||||
|
||||
this.request_autoscroll(Autoscroll::fit(), cx);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = &display_map.buffer_snapshot;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3002,10 +3002,12 @@ mod tests {
|
|||
fn test_layout_line_numbers(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let (_, editor) = cx.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
});
|
||||
let editor = cx
|
||||
.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
})
|
||||
.root(cx);
|
||||
let element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));
|
||||
|
||||
let layouts = editor.update(cx, |editor, cx| {
|
||||
|
@ -3021,10 +3023,12 @@ mod tests {
|
|||
fn test_layout_with_placeholder_text_and_blocks(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let (_, editor) = cx.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple("", cx);
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
});
|
||||
let editor = cx
|
||||
.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple("", cx);
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
})
|
||||
.root(cx);
|
||||
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.set_placeholder_text("hello", cx);
|
||||
|
@ -3231,10 +3235,12 @@ mod tests {
|
|||
info!(
|
||||
"Creating editor with mode {editor_mode:?}, width {editor_width} and text '{input_text}'"
|
||||
);
|
||||
let (_, editor) = cx.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple(&input_text, cx);
|
||||
Editor::new(editor_mode, buffer, None, None, cx)
|
||||
});
|
||||
let editor = cx
|
||||
.add_window(|cx| {
|
||||
let buffer = MultiBuffer::build_simple(&input_text, cx);
|
||||
Editor::new(editor_mode, buffer, None, None, cx)
|
||||
})
|
||||
.root(cx);
|
||||
|
||||
let mut element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));
|
||||
let (_, layout_state) = editor.update(cx, |editor, cx| {
|
||||
|
|
|
@ -1135,7 +1135,9 @@ mod tests {
|
|||
)
|
||||
.await;
|
||||
let project = Project::test(fs, ["/a".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let worktree_id = workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
|
@ -1835,7 +1837,9 @@ mod tests {
|
|||
.await;
|
||||
let project = Project::test(fs, ["/a".as_ref()], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(Arc::new(language)));
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let worktree_id = workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
|
@ -1988,7 +1992,9 @@ mod tests {
|
|||
project.update(cx, |project, _| {
|
||||
project.languages().add(Arc::clone(&language))
|
||||
});
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let worktree_id = workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
|
@ -2074,8 +2080,9 @@ mod tests {
|
|||
|
||||
deterministic.run_until_parked();
|
||||
cx.foreground().run_until_parked();
|
||||
let (_, editor) =
|
||||
cx.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx));
|
||||
let editor = cx
|
||||
.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx))
|
||||
.root(cx);
|
||||
let editor_edited = Arc::new(AtomicBool::new(false));
|
||||
let fake_server = fake_servers.next().await.unwrap();
|
||||
let closure_editor_edited = Arc::clone(&editor_edited);
|
||||
|
@ -2327,7 +2334,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
|||
project.update(cx, |project, _| {
|
||||
project.languages().add(Arc::clone(&language))
|
||||
});
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let worktree_id = workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
|
@ -2372,8 +2381,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
|||
|
||||
deterministic.run_until_parked();
|
||||
cx.foreground().run_until_parked();
|
||||
let (_, editor) =
|
||||
cx.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx));
|
||||
let editor = cx
|
||||
.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx))
|
||||
.root(cx);
|
||||
let editor_edited = Arc::new(AtomicBool::new(false));
|
||||
let fake_server = fake_servers.next().await.unwrap();
|
||||
let closure_editor_edited = Arc::clone(&editor_edited);
|
||||
|
@ -2561,7 +2571,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
|||
|
||||
let project = Project::test(fs, ["/a".as_ref()], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(Arc::new(language)));
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let worktree_id = workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
|
|
|
@ -28,7 +28,10 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
use text::Selection;
|
||||
use util::{paths::FILE_ROW_COLUMN_DELIMITER, ResultExt, TryFutureExt};
|
||||
use util::{
|
||||
paths::{PathExt, FILE_ROW_COLUMN_DELIMITER},
|
||||
ResultExt, TryFutureExt,
|
||||
};
|
||||
use workspace::item::{BreadcrumbText, FollowableItemHandle};
|
||||
use workspace::{
|
||||
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
|
||||
|
@ -546,9 +549,7 @@ impl Item for Editor {
|
|||
.and_then(|f| f.as_local())?
|
||||
.abs_path(cx);
|
||||
|
||||
let file_path = util::paths::compact(&file_path)
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
let file_path = file_path.compact().to_string_lossy().to_string();
|
||||
|
||||
Some(file_path.into())
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ impl<'a> EditorLspTestContext<'a> {
|
|||
.insert_tree("/root", json!({ "dir": { file_name.clone(): "" }}))
|
||||
.await;
|
||||
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/root", true, cx)
|
||||
|
@ -98,7 +99,7 @@ impl<'a> EditorLspTestContext<'a> {
|
|||
Self {
|
||||
cx: EditorTestContext {
|
||||
cx,
|
||||
window_id,
|
||||
window_id: window.window_id(),
|
||||
editor,
|
||||
},
|
||||
lsp,
|
||||
|
|
|
@ -32,16 +32,14 @@ impl<'a> EditorTestContext<'a> {
|
|||
let buffer = project
|
||||
.update(cx, |project, cx| project.create_buffer("", None, cx))
|
||||
.unwrap();
|
||||
let (window_id, editor) = cx.update(|cx| {
|
||||
cx.add_window(Default::default(), |cx| {
|
||||
cx.focus_self();
|
||||
build_editor(MultiBuffer::build_from_buffer(buffer, cx), cx)
|
||||
})
|
||||
let window = cx.add_window(|cx| {
|
||||
cx.focus_self();
|
||||
build_editor(MultiBuffer::build_from_buffer(buffer, cx), cx)
|
||||
});
|
||||
|
||||
let editor = window.root(cx);
|
||||
Self {
|
||||
cx,
|
||||
window_id,
|
||||
window_id: window.window_id(),
|
||||
editor,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -617,8 +617,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
cx.dispatch_action(window_id, Toggle);
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
cx.dispatch_action(window.window_id(), Toggle);
|
||||
|
||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||
finder
|
||||
|
@ -631,8 +632,8 @@ mod tests {
|
|||
});
|
||||
|
||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||
cx.dispatch_action(window_id, SelectNext);
|
||||
cx.dispatch_action(window_id, Confirm);
|
||||
cx.dispatch_action(window.window_id(), SelectNext);
|
||||
cx.dispatch_action(window.window_id(), Confirm);
|
||||
active_pane
|
||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||
.await;
|
||||
|
@ -671,8 +672,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
cx.dispatch_action(window_id, Toggle);
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
cx.dispatch_action(window.window_id(), Toggle);
|
||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||
|
||||
let file_query = &first_file_name[..3];
|
||||
|
@ -704,8 +706,8 @@ mod tests {
|
|||
});
|
||||
|
||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||
cx.dispatch_action(window_id, SelectNext);
|
||||
cx.dispatch_action(window_id, Confirm);
|
||||
cx.dispatch_action(window.window_id(), SelectNext);
|
||||
cx.dispatch_action(window.window_id(), Confirm);
|
||||
active_pane
|
||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||
.await;
|
||||
|
@ -754,8 +756,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
cx.dispatch_action(window_id, Toggle);
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
cx.dispatch_action(window.window_id(), Toggle);
|
||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||
|
||||
let file_query = &first_file_name[..3];
|
||||
|
@ -787,8 +790,8 @@ mod tests {
|
|||
});
|
||||
|
||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||
cx.dispatch_action(window_id, SelectNext);
|
||||
cx.dispatch_action(window_id, Confirm);
|
||||
cx.dispatch_action(window.window_id(), SelectNext);
|
||||
cx.dispatch_action(window.window_id(), Confirm);
|
||||
active_pane
|
||||
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||
.await;
|
||||
|
@ -837,19 +840,23 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/dir".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let finder = cx
|
||||
.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
)
|
||||
})
|
||||
.root(cx);
|
||||
|
||||
let query = test_path_like("hi");
|
||||
finder
|
||||
|
@ -931,19 +938,23 @@ mod tests {
|
|||
cx,
|
||||
)
|
||||
.await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let finder = cx
|
||||
.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
)
|
||||
})
|
||||
.root(cx);
|
||||
finder
|
||||
.update(cx, |f, cx| {
|
||||
f.delegate_mut().spawn_search(test_path_like("hi"), cx)
|
||||
|
@ -967,19 +978,23 @@ mod tests {
|
|||
cx,
|
||||
)
|
||||
.await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let finder = cx
|
||||
.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
)
|
||||
})
|
||||
.root(cx);
|
||||
|
||||
// Even though there is only one worktree, that worktree's filename
|
||||
// is included in the matching, because the worktree is a single file.
|
||||
|
@ -1015,61 +1030,6 @@ mod tests {
|
|||
finder.read_with(cx, |f, _| assert_eq!(f.delegate().matches.len(), 0));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_multiple_matches_with_same_relative_path(cx: &mut TestAppContext) {
|
||||
let app_state = init_test(cx);
|
||||
app_state
|
||||
.fs
|
||||
.as_fake()
|
||||
.insert_tree(
|
||||
"/root",
|
||||
json!({
|
||||
"dir1": { "a.txt": "" },
|
||||
"dir2": { "a.txt": "" }
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let project = Project::test(
|
||||
app_state.fs.clone(),
|
||||
["/root/dir1".as_ref(), "/root/dir2".as_ref()],
|
||||
cx,
|
||||
)
|
||||
.await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
// Run a search that matches two files with the same relative path.
|
||||
finder
|
||||
.update(cx, |f, cx| {
|
||||
f.delegate_mut().spawn_search(test_path_like("a.t"), cx)
|
||||
})
|
||||
.await;
|
||||
|
||||
// Can switch between different matches with the same relative path.
|
||||
finder.update(cx, |finder, cx| {
|
||||
let delegate = finder.delegate_mut();
|
||||
assert_eq!(delegate.matches.len(), 2);
|
||||
assert_eq!(delegate.selected_index(), 0);
|
||||
delegate.set_selected_index(1, cx);
|
||||
assert_eq!(delegate.selected_index(), 1);
|
||||
delegate.set_selected_index(0, cx);
|
||||
assert_eq!(delegate.selected_index(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_path_distance_ordering(cx: &mut TestAppContext) {
|
||||
let app_state = init_test(cx);
|
||||
|
@ -1089,7 +1049,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let worktree_id = cx.read(|cx| {
|
||||
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
||||
assert_eq!(worktrees.len(), 1);
|
||||
|
@ -1103,18 +1065,20 @@ mod tests {
|
|||
worktree_id,
|
||||
path: Arc::from(Path::new("/root/dir2/b.txt")),
|
||||
}));
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
b_path,
|
||||
Vec::new(),
|
||||
let finder = cx
|
||||
.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
b_path,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
)
|
||||
})
|
||||
.root(cx);
|
||||
|
||||
finder
|
||||
.update(cx, |f, cx| {
|
||||
|
@ -1151,19 +1115,23 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let (_, finder) = cx.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let finder = cx
|
||||
.add_window(|cx| {
|
||||
Picker::new(
|
||||
FileFinderDelegate::new(
|
||||
workspace.downgrade(),
|
||||
workspace.read(cx).project().clone(),
|
||||
None,
|
||||
Vec::new(),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
)
|
||||
})
|
||||
.root(cx);
|
||||
finder
|
||||
.update(cx, |f, cx| {
|
||||
f.delegate_mut().spawn_search(test_path_like("dir"), cx)
|
||||
|
@ -1198,7 +1166,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let worktree_id = cx.read(|cx| {
|
||||
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
||||
assert_eq!(worktrees.len(), 1);
|
||||
|
@ -1404,7 +1374,9 @@ mod tests {
|
|||
.detach();
|
||||
deterministic.run_until_parked();
|
||||
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let worktree_id = cx.read(|cx| {
|
||||
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
|
||||
assert_eq!(worktrees.len(), 1,);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ use crate::{
|
|||
platform::{Event, InputHandler, KeyDownEvent, Platform},
|
||||
Action, AppContext, BorrowAppContext, BorrowWindowContext, Entity, FontCache, Handle,
|
||||
ModelContext, ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakHandle,
|
||||
WindowContext,
|
||||
WindowContext, WindowHandle,
|
||||
};
|
||||
use collections::BTreeMap;
|
||||
use futures::Future;
|
||||
|
@ -60,7 +60,7 @@ impl TestAppContext {
|
|||
RefCounts::new(leak_detector),
|
||||
(),
|
||||
);
|
||||
cx.next_entity_id = first_entity_id;
|
||||
cx.next_id = first_entity_id;
|
||||
let cx = TestAppContext {
|
||||
cx: Rc::new(RefCell::new(cx)),
|
||||
foreground_platform,
|
||||
|
@ -148,17 +148,18 @@ impl TestAppContext {
|
|||
self.cx.borrow_mut().add_model(build_model)
|
||||
}
|
||||
|
||||
pub fn add_window<T, F>(&mut self, build_root_view: F) -> (usize, ViewHandle<T>)
|
||||
pub fn add_window<T, F>(&mut self, build_root_view: F) -> WindowHandle<T>
|
||||
where
|
||||
T: View,
|
||||
F: FnOnce(&mut ViewContext<T>) -> T,
|
||||
{
|
||||
let (window_id, view) = self
|
||||
let window = self
|
||||
.cx
|
||||
.borrow_mut()
|
||||
.add_window(Default::default(), build_root_view);
|
||||
self.simulate_window_activation(Some(window_id));
|
||||
(window_id, view)
|
||||
self.simulate_window_activation(Some(window.window_id()));
|
||||
|
||||
WindowHandle::new(window.window_id())
|
||||
}
|
||||
|
||||
pub fn add_view<T, F>(&mut self, window_id: usize, build_view: F) -> ViewHandle<T>
|
||||
|
@ -405,14 +406,20 @@ impl BorrowAppContext for TestAppContext {
|
|||
}
|
||||
|
||||
impl BorrowWindowContext for TestAppContext {
|
||||
fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
self.cx
|
||||
.borrow()
|
||||
.read_window(window_id, f)
|
||||
.expect("window was closed")
|
||||
}
|
||||
|
||||
fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
|
||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||
&mut self,
|
||||
window_id: usize,
|
||||
f: F,
|
||||
) -> T {
|
||||
self.cx
|
||||
.borrow_mut()
|
||||
.update_window(window_id, f)
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
|||
util::post_inc,
|
||||
Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
|
||||
Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription,
|
||||
View, ViewContext, ViewHandle, WindowInvalidation,
|
||||
View, ViewContext, ViewHandle, WindowHandle, WindowInvalidation,
|
||||
};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use collections::{HashMap, HashSet};
|
||||
|
@ -142,7 +142,9 @@ impl BorrowAppContext for WindowContext<'_> {
|
|||
}
|
||||
|
||||
impl BorrowWindowContext for WindowContext<'_> {
|
||||
fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
if self.window_id == window_id {
|
||||
f(self)
|
||||
} else {
|
||||
|
@ -150,7 +152,11 @@ impl BorrowWindowContext for WindowContext<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
|
||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||
&mut self,
|
||||
window_id: usize,
|
||||
f: F,
|
||||
) -> T {
|
||||
if self.window_id == window_id {
|
||||
f(self)
|
||||
} else {
|
||||
|
@ -1151,15 +1157,15 @@ impl<'a> WindowContext<'a> {
|
|||
self.window.platform_window.prompt(level, msg, answers)
|
||||
}
|
||||
|
||||
pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> ViewHandle<V>
|
||||
pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> WindowHandle<V>
|
||||
where
|
||||
V: View,
|
||||
F: FnOnce(&mut ViewContext<V>) -> V,
|
||||
{
|
||||
let root_view = self.add_view(|cx| build_root_view(cx));
|
||||
self.window.root_view = Some(root_view.clone().into_any());
|
||||
self.window.focused_view_id = Some(root_view.id());
|
||||
root_view
|
||||
self.window.root_view = Some(root_view.into_any());
|
||||
WindowHandle::new(self.window_id)
|
||||
}
|
||||
|
||||
pub fn add_view<T, F>(&mut self, build_view: F) -> ViewHandle<T>
|
||||
|
@ -1176,7 +1182,7 @@ impl<'a> WindowContext<'a> {
|
|||
F: FnOnce(&mut ViewContext<T>) -> Option<T>,
|
||||
{
|
||||
let window_id = self.window_id;
|
||||
let view_id = post_inc(&mut self.next_entity_id);
|
||||
let view_id = post_inc(&mut self.next_id);
|
||||
let mut cx = ViewContext::mutable(self, view_id);
|
||||
let handle = if let Some(view) = build_view(&mut cx) {
|
||||
let mut keymap_context = KeymapContext::default();
|
||||
|
|
|
@ -61,7 +61,9 @@ async fn test_lsp_logs(cx: &mut TestAppContext) {
|
|||
.receive_notification::<lsp::notification::DidOpenTextDocument>()
|
||||
.await;
|
||||
|
||||
let (_, log_view) = cx.add_window(|cx| LspLogView::new(project.clone(), log_store.clone(), cx));
|
||||
let log_view = cx
|
||||
.add_window(|cx| LspLogView::new(project.clone(), log_store.clone(), cx))
|
||||
.root(cx);
|
||||
|
||||
language_server.notify::<lsp::notification::LogMessage>(lsp::LogMessageParams {
|
||||
message: "hello from the server".into(),
|
||||
|
|
|
@ -4,7 +4,7 @@ use collections::HashMap;
|
|||
|
||||
use gpui::{AppContext, AssetSource};
|
||||
use serde_derive::Deserialize;
|
||||
use util::iife;
|
||||
use util::{iife, paths::PathExt};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct TypeConfig {
|
||||
|
@ -48,14 +48,7 @@ impl FileAssociations {
|
|||
// FIXME: Associate a type with the languages and have the file's langauge
|
||||
// override these associations
|
||||
iife!({
|
||||
let suffix = path
|
||||
.file_name()
|
||||
.and_then(|os_str| os_str.to_str())
|
||||
.and_then(|file_name| {
|
||||
file_name
|
||||
.find('.')
|
||||
.and_then(|dot_index| file_name.get(dot_index + 1..))
|
||||
})?;
|
||||
let suffix = path.icon_suffix()?;
|
||||
|
||||
this.suffixes
|
||||
.get(suffix)
|
||||
|
|
|
@ -1756,7 +1756,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..50, cx),
|
||||
|
@ -1844,7 +1846,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
select_path(&panel, "root1", cx);
|
||||
|
@ -2195,7 +2199,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
select_path(&panel, "root1", cx);
|
||||
|
@ -2295,7 +2301,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/root1".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
panel.update(cx, |panel, cx| {
|
||||
|
@ -2368,7 +2376,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
toggle_expand_dir(&panel, "src/test", cx);
|
||||
|
@ -2457,7 +2467,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
select_path(&panel, "src/", cx);
|
||||
|
@ -2603,7 +2615,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
let new_search_events_count = Arc::new(AtomicUsize::new(0));
|
||||
|
@ -2690,7 +2704,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/project_root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));
|
||||
|
||||
panel.update(cx, |panel, cx| {
|
||||
|
|
|
@ -326,7 +326,9 @@ mod tests {
|
|||
},
|
||||
);
|
||||
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Create the project symbols view.
|
||||
let symbols = cx.add_view(window_id, |cx| {
|
||||
|
|
|
@ -5,6 +5,7 @@ use gpui::{
|
|||
elements::{Label, LabelStyle},
|
||||
AnyElement, Element, View,
|
||||
};
|
||||
use util::paths::PathExt;
|
||||
use workspace::WorkspaceLocation;
|
||||
|
||||
pub struct HighlightedText {
|
||||
|
@ -61,7 +62,7 @@ impl HighlightedWorkspaceLocation {
|
|||
.paths()
|
||||
.iter()
|
||||
.map(|path| {
|
||||
let path = util::paths::compact(&path);
|
||||
let path = path.compact();
|
||||
let highlighted_text = Self::highlights_for_path(
|
||||
path.as_ref(),
|
||||
&string_match.positions,
|
||||
|
|
|
@ -11,6 +11,7 @@ use highlighted_workspace_location::HighlightedWorkspaceLocation;
|
|||
use ordered_float::OrderedFloat;
|
||||
use picker::{Picker, PickerDelegate, PickerEvent};
|
||||
use std::sync::Arc;
|
||||
use util::paths::PathExt;
|
||||
use workspace::{
|
||||
notifications::simple_message_notification::MessageNotification, Workspace, WorkspaceLocation,
|
||||
WORKSPACE_DB,
|
||||
|
@ -134,7 +135,7 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
let combined_string = location
|
||||
.paths()
|
||||
.iter()
|
||||
.map(|path| util::paths::compact(&path).to_string_lossy().into_owned())
|
||||
.map(|path| path.compact().to_string_lossy().into_owned())
|
||||
.collect::<Vec<_>>()
|
||||
.join("");
|
||||
StringMatchCandidate::new(id, combined_string)
|
||||
|
|
|
@ -849,11 +849,13 @@ mod tests {
|
|||
cx,
|
||||
)
|
||||
});
|
||||
let (window_id, _root_view) = cx.add_window(|_| EmptyView);
|
||||
let window = cx.add_window(|_| EmptyView);
|
||||
|
||||
let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||
let editor = cx.add_view(window.window_id(), |cx| {
|
||||
Editor::for_buffer(buffer.clone(), None, cx)
|
||||
});
|
||||
|
||||
let search_bar = cx.add_view(window_id, |cx| {
|
||||
let search_bar = cx.add_view(window.window_id(), |cx| {
|
||||
let mut search_bar = BufferSearchBar::new(cx);
|
||||
search_bar.set_active_pane_item(Some(&editor), cx);
|
||||
search_bar.show(cx);
|
||||
|
@ -1229,7 +1231,8 @@ mod tests {
|
|||
"Should pick a query with multiple results"
|
||||
);
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));
|
||||
let (window_id, _root_view) = cx.add_window(|_| EmptyView);
|
||||
let window = cx.add_window(|_| EmptyView);
|
||||
let window_id = window.window_id();
|
||||
|
||||
let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||
|
||||
|
@ -1416,11 +1419,13 @@ mod tests {
|
|||
"#
|
||||
.unindent();
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));
|
||||
let (window_id, _root_view) = cx.add_window(|_| EmptyView);
|
||||
let window = cx.add_window(|_| EmptyView);
|
||||
|
||||
let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));
|
||||
let editor = cx.add_view(window.window_id(), |cx| {
|
||||
Editor::for_buffer(buffer.clone(), None, cx)
|
||||
});
|
||||
|
||||
let search_bar = cx.add_view(window_id, |cx| {
|
||||
let search_bar = cx.add_view(window.window_id(), |cx| {
|
||||
let mut search_bar = BufferSearchBar::new(cx);
|
||||
search_bar.set_active_pane_item(Some(&editor), cx);
|
||||
search_bar.show(cx);
|
||||
|
|
|
@ -1447,7 +1447,9 @@ pub mod tests {
|
|||
.await;
|
||||
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
|
||||
let search = cx.add_model(|cx| ProjectSearch::new(project, cx));
|
||||
let (_, search_view) = cx.add_window(|cx| ProjectSearchView::new(search.clone(), cx));
|
||||
let search_view = cx
|
||||
.add_window(|cx| ProjectSearchView::new(search.clone(), cx))
|
||||
.root(cx);
|
||||
|
||||
search_view.update(cx, |search_view, cx| {
|
||||
search_view
|
||||
|
@ -1564,7 +1566,9 @@ pub mod tests {
|
|||
)
|
||||
.await;
|
||||
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
let active_item = cx.read(|cx| {
|
||||
workspace
|
||||
|
@ -1748,7 +1752,9 @@ pub mod tests {
|
|||
let worktree_id = project.read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
});
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
|
||||
let active_item = cx.read(|cx| {
|
||||
workspace
|
||||
|
@ -1866,7 +1872,9 @@ pub mod tests {
|
|||
)
|
||||
.await;
|
||||
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
ProjectSearchView::deploy(workspace, &workspace::NewSearch, cx)
|
||||
});
|
||||
|
|
|
@ -1070,7 +1070,9 @@ mod tests {
|
|||
});
|
||||
|
||||
let project = Project::test(params.fs.clone(), [], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
|
||||
(project, workspace)
|
||||
}
|
||||
|
|
|
@ -30,49 +30,47 @@ pub mod legacy {
|
|||
}
|
||||
}
|
||||
|
||||
/// Compacts a given file path by replacing the user's home directory
|
||||
/// prefix with a tilde (`~`).
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `path` - A reference to a `Path` representing the file path to compact.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::path::{Path, PathBuf};
|
||||
/// use util::paths::compact;
|
||||
/// let path: PathBuf = [
|
||||
/// util::paths::HOME.to_string_lossy().to_string(),
|
||||
/// "some_file.txt".to_string(),
|
||||
/// ]
|
||||
/// .iter()
|
||||
/// .collect();
|
||||
/// if cfg!(target_os = "linux") || cfg!(target_os = "macos") {
|
||||
/// assert_eq!(compact(&path).to_str(), Some("~/some_file.txt"));
|
||||
/// } else {
|
||||
/// assert_eq!(compact(&path).to_str(), path.to_str());
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * A `PathBuf` containing the compacted file path. If the input path
|
||||
/// does not have the user's home directory prefix, or if we are not on
|
||||
/// Linux or macOS, the original path is returned unchanged.
|
||||
pub fn compact(path: &Path) -> PathBuf {
|
||||
if cfg!(target_os = "linux") || cfg!(target_os = "macos") {
|
||||
match path.strip_prefix(HOME.as_path()) {
|
||||
Ok(relative_path) => {
|
||||
let mut shortened_path = PathBuf::new();
|
||||
shortened_path.push("~");
|
||||
shortened_path.push(relative_path);
|
||||
shortened_path
|
||||
pub trait PathExt {
|
||||
fn compact(&self) -> PathBuf;
|
||||
fn icon_suffix(&self) -> Option<&str>;
|
||||
}
|
||||
|
||||
impl<T: AsRef<Path>> PathExt for T {
|
||||
/// Compacts a given file path by replacing the user's home directory
|
||||
/// prefix with a tilde (`~`).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * A `PathBuf` containing the compacted file path. If the input path
|
||||
/// does not have the user's home directory prefix, or if we are not on
|
||||
/// Linux or macOS, the original path is returned unchanged.
|
||||
fn compact(&self) -> PathBuf {
|
||||
if cfg!(target_os = "linux") || cfg!(target_os = "macos") {
|
||||
match self.as_ref().strip_prefix(HOME.as_path()) {
|
||||
Ok(relative_path) => {
|
||||
let mut shortened_path = PathBuf::new();
|
||||
shortened_path.push("~");
|
||||
shortened_path.push(relative_path);
|
||||
shortened_path
|
||||
}
|
||||
Err(_) => self.as_ref().to_path_buf(),
|
||||
}
|
||||
Err(_) => path.to_path_buf(),
|
||||
} else {
|
||||
self.as_ref().to_path_buf()
|
||||
}
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
|
||||
fn icon_suffix(&self) -> Option<&str> {
|
||||
let file_name = self.as_ref().file_name()?.to_str()?;
|
||||
|
||||
if file_name.starts_with(".") {
|
||||
return file_name.strip_prefix(".");
|
||||
}
|
||||
|
||||
self.as_ref()
|
||||
.extension()
|
||||
.map(|extension| extension.to_str())
|
||||
.flatten()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,4 +277,42 @@ mod tests {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_compact() {
|
||||
let path: PathBuf = [
|
||||
HOME.to_string_lossy().to_string(),
|
||||
"some_file.txt".to_string(),
|
||||
]
|
||||
.iter()
|
||||
.collect();
|
||||
if cfg!(target_os = "linux") || cfg!(target_os = "macos") {
|
||||
assert_eq!(path.compact().to_str(), Some("~/some_file.txt"));
|
||||
} else {
|
||||
assert_eq!(path.compact().to_str(), path.to_str());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_suffix() {
|
||||
// No dots in name
|
||||
let path = Path::new("/a/b/c/file_name.rs");
|
||||
assert_eq!(path.icon_suffix(), Some("rs"));
|
||||
|
||||
// Single dot in name
|
||||
let path = Path::new("/a/b/c/file.name.rs");
|
||||
assert_eq!(path.icon_suffix(), Some("rs"));
|
||||
|
||||
// Multiple dots in name
|
||||
let path = Path::new("/a/b/c/long.file.name.rs");
|
||||
assert_eq!(path.icon_suffix(), Some("rs"));
|
||||
|
||||
// Hidden file, no extension
|
||||
let path = Path::new("/a/b/c/.gitignore");
|
||||
assert_eq!(path.icon_suffix(), Some("gitignore"));
|
||||
|
||||
// Hidden file, with extension
|
||||
let path = Path::new("/a/b/c/.eslintrc.js");
|
||||
assert_eq!(path.icon_suffix(), Some("eslintrc.js"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,8 @@ pub trait Panel: View {
|
|||
fn is_zoomed(&self, _cx: &WindowContext) -> bool {
|
||||
false
|
||||
}
|
||||
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {
|
||||
|
||||
}
|
||||
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {
|
||||
|
||||
}
|
||||
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
|
||||
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
|
||||
fn should_activate_on_event(_: &Self::Event) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -1972,7 +1972,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
pane.update(cx, |pane, cx| {
|
||||
|
@ -1987,7 +1988,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
// 1. Add with a destination index
|
||||
|
@ -2065,7 +2067,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
// 1. Add with a destination index
|
||||
|
@ -2141,7 +2144,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
// singleton view
|
||||
|
@ -2209,7 +2213,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
add_labeled_item(&pane, "A", false, cx);
|
||||
|
@ -2256,7 +2261,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);
|
||||
|
@ -2276,7 +2282,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
add_labeled_item(&pane, "A", true, cx);
|
||||
|
@ -2299,7 +2306,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);
|
||||
|
@ -2319,7 +2327,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);
|
||||
|
@ -2339,7 +2348,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
add_labeled_item(&pane, "A", false, cx);
|
||||
|
|
|
@ -797,67 +797,59 @@ impl Workspace {
|
|||
DB.next_id().await.unwrap_or(0)
|
||||
};
|
||||
|
||||
let workspace = requesting_window_id
|
||||
.and_then(|window_id| {
|
||||
cx.update(|cx| {
|
||||
cx.replace_root_view(window_id, |cx| {
|
||||
Workspace::new(
|
||||
workspace_id,
|
||||
project_handle.clone(),
|
||||
app_state.clone(),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
let window = requesting_window_id.and_then(|window_id| {
|
||||
cx.update(|cx| {
|
||||
cx.replace_root_view(window_id, |cx| {
|
||||
Workspace::new(workspace_id, project_handle.clone(), app_state.clone(), cx)
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
let window_bounds_override = window_bounds_env_override(&cx);
|
||||
let (bounds, display) = if let Some(bounds) = window_bounds_override {
|
||||
(Some(bounds), None)
|
||||
} else {
|
||||
serialized_workspace
|
||||
.as_ref()
|
||||
.and_then(|serialized_workspace| {
|
||||
let display = serialized_workspace.display?;
|
||||
let mut bounds = serialized_workspace.bounds?;
|
||||
});
|
||||
let window = window.unwrap_or_else(|| {
|
||||
let window_bounds_override = window_bounds_env_override(&cx);
|
||||
let (bounds, display) = if let Some(bounds) = window_bounds_override {
|
||||
(Some(bounds), None)
|
||||
} else {
|
||||
serialized_workspace
|
||||
.as_ref()
|
||||
.and_then(|serialized_workspace| {
|
||||
let display = serialized_workspace.display?;
|
||||
let mut bounds = serialized_workspace.bounds?;
|
||||
|
||||
// Stored bounds are relative to the containing display.
|
||||
// So convert back to global coordinates if that screen still exists
|
||||
if let WindowBounds::Fixed(mut window_bounds) = bounds {
|
||||
if let Some(screen) = cx.platform().screen_by_id(display) {
|
||||
let screen_bounds = screen.bounds();
|
||||
window_bounds.set_origin_x(
|
||||
window_bounds.origin_x() + screen_bounds.origin_x(),
|
||||
);
|
||||
window_bounds.set_origin_y(
|
||||
window_bounds.origin_y() + screen_bounds.origin_y(),
|
||||
);
|
||||
bounds = WindowBounds::Fixed(window_bounds);
|
||||
} else {
|
||||
// Screen no longer exists. Return none here.
|
||||
return None;
|
||||
}
|
||||
// Stored bounds are relative to the containing display.
|
||||
// So convert back to global coordinates if that screen still exists
|
||||
if let WindowBounds::Fixed(mut window_bounds) = bounds {
|
||||
if let Some(screen) = cx.platform().screen_by_id(display) {
|
||||
let screen_bounds = screen.bounds();
|
||||
window_bounds.set_origin_x(
|
||||
window_bounds.origin_x() + screen_bounds.origin_x(),
|
||||
);
|
||||
window_bounds.set_origin_y(
|
||||
window_bounds.origin_y() + screen_bounds.origin_y(),
|
||||
);
|
||||
bounds = WindowBounds::Fixed(window_bounds);
|
||||
} else {
|
||||
// Screen no longer exists. Return none here.
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some((bounds, display))
|
||||
})
|
||||
.unzip()
|
||||
};
|
||||
Some((bounds, display))
|
||||
})
|
||||
.unzip()
|
||||
};
|
||||
|
||||
// Use the serialized workspace to construct the new window
|
||||
cx.add_window(
|
||||
(app_state.build_window_options)(bounds, display, cx.platform().as_ref()),
|
||||
|cx| {
|
||||
Workspace::new(
|
||||
workspace_id,
|
||||
project_handle.clone(),
|
||||
app_state.clone(),
|
||||
cx,
|
||||
)
|
||||
},
|
||||
)
|
||||
.1
|
||||
});
|
||||
// Use the serialized workspace to construct the new window
|
||||
cx.add_window(
|
||||
(app_state.build_window_options)(bounds, display, cx.platform().as_ref()),
|
||||
|cx| {
|
||||
Workspace::new(workspace_id, project_handle.clone(), app_state.clone(), cx)
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
// We haven't yielded the main thread since obtaining the window handle,
|
||||
// so the window exists.
|
||||
let workspace = window.root(&cx).unwrap();
|
||||
|
||||
(app_state.initialize_workspace)(
|
||||
workspace.downgrade(),
|
||||
|
@ -868,7 +860,7 @@ impl Workspace {
|
|||
.await
|
||||
.log_err();
|
||||
|
||||
cx.update_window(workspace.window_id(), |cx| cx.activate_window());
|
||||
window.update(&mut cx, |cx| cx.activate_window());
|
||||
|
||||
let workspace = workspace.downgrade();
|
||||
notify_if_database_failed(&workspace, &mut cx);
|
||||
|
@ -3987,7 +3979,7 @@ pub fn join_remote_project(
|
|||
.await?;
|
||||
|
||||
let window_bounds_override = window_bounds_env_override(&cx);
|
||||
let (_, workspace) = cx.add_window(
|
||||
let window = cx.add_window(
|
||||
(app_state.build_window_options)(
|
||||
window_bounds_override,
|
||||
None,
|
||||
|
@ -3995,6 +3987,7 @@ pub fn join_remote_project(
|
|||
),
|
||||
|cx| Workspace::new(0, project, app_state.clone(), cx),
|
||||
);
|
||||
let workspace = window.root(&cx).unwrap();
|
||||
(app_state.initialize_workspace)(
|
||||
workspace.downgrade(),
|
||||
false,
|
||||
|
@ -4123,10 +4116,11 @@ mod tests {
|
|||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
// Adding an item with no ambiguity renders the tab without detail.
|
||||
let item1 = cx.add_view(window_id, |_| {
|
||||
let item1 = window.add_view(cx, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]);
|
||||
item
|
||||
|
@ -4138,7 +4132,7 @@ mod tests {
|
|||
|
||||
// Adding an item that creates ambiguity increases the level of detail on
|
||||
// both tabs.
|
||||
let item2 = cx.add_view(window_id, |_| {
|
||||
let item2 = window.add_view(cx, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
|
||||
item
|
||||
|
@ -4152,7 +4146,7 @@ mod tests {
|
|||
// Adding an item that creates ambiguity increases the level of detail only
|
||||
// on the ambiguous tabs. In this case, the ambiguity can't be resolved so
|
||||
// we stop at the highest detail available.
|
||||
let item3 = cx.add_view(window_id, |_| {
|
||||
let item3 = window.add_view(cx, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
|
||||
item
|
||||
|
@ -4187,16 +4181,17 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["root1".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
let worktree_id = project.read_with(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
});
|
||||
|
||||
let item1 = cx.add_view(window_id, |cx| {
|
||||
let item1 = window.add_view(cx, |cx| {
|
||||
TestItem::new().with_project_items(&[TestProjectItem::new(1, "one.txt", cx)])
|
||||
});
|
||||
let item2 = cx.add_view(window_id, |cx| {
|
||||
let item2 = window.add_view(cx, |cx| {
|
||||
TestItem::new().with_project_items(&[TestProjectItem::new(2, "two.txt", cx)])
|
||||
});
|
||||
|
||||
|
@ -4211,14 +4206,14 @@ mod tests {
|
|||
);
|
||||
});
|
||||
assert_eq!(
|
||||
cx.current_window_title(window_id).as_deref(),
|
||||
cx.current_window_title(window.window_id()).as_deref(),
|
||||
Some("one.txt — root1")
|
||||
);
|
||||
|
||||
// Add a second item to a non-empty pane
|
||||
workspace.update(cx, |workspace, cx| workspace.add_item(Box::new(item2), cx));
|
||||
assert_eq!(
|
||||
cx.current_window_title(window_id).as_deref(),
|
||||
cx.current_window_title(window.window_id()).as_deref(),
|
||||
Some("two.txt — root1")
|
||||
);
|
||||
project.read_with(cx, |project, cx| {
|
||||
|
@ -4237,7 +4232,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
cx.current_window_title(window_id).as_deref(),
|
||||
cx.current_window_title(window.window_id()).as_deref(),
|
||||
Some("one.txt — root1")
|
||||
);
|
||||
project.read_with(cx, |project, cx| {
|
||||
|
@ -4257,14 +4252,14 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
cx.current_window_title(window_id).as_deref(),
|
||||
cx.current_window_title(window.window_id()).as_deref(),
|
||||
Some("one.txt — root1, root2")
|
||||
);
|
||||
|
||||
// Remove a project folder
|
||||
project.update(cx, |project, cx| project.remove_worktree(worktree_id, cx));
|
||||
assert_eq!(
|
||||
cx.current_window_title(window_id).as_deref(),
|
||||
cx.current_window_title(window.window_id()).as_deref(),
|
||||
Some("one.txt — root2")
|
||||
);
|
||||
}
|
||||
|
@ -4277,18 +4272,19 @@ mod tests {
|
|||
fs.insert_tree("/root", json!({ "one": "" })).await;
|
||||
|
||||
let project = Project::test(fs, ["root".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
// When there are no dirty items, there's nothing to do.
|
||||
let item1 = cx.add_view(window_id, |_| TestItem::new());
|
||||
let item1 = window.add_view(cx, |_| TestItem::new());
|
||||
workspace.update(cx, |w, cx| w.add_item(Box::new(item1.clone()), cx));
|
||||
let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));
|
||||
assert!(task.await.unwrap());
|
||||
|
||||
// When there are dirty untitled items, prompt to save each one. If the user
|
||||
// cancels any prompt, then abort.
|
||||
let item2 = cx.add_view(window_id, |_| TestItem::new().with_dirty(true));
|
||||
let item3 = cx.add_view(window_id, |cx| {
|
||||
let item2 = window.add_view(cx, |_| TestItem::new().with_dirty(true));
|
||||
let item3 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
|
||||
|
@ -4299,9 +4295,9 @@ mod tests {
|
|||
});
|
||||
let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));
|
||||
cx.foreground().run_until_parked();
|
||||
cx.simulate_prompt_answer(window_id, 2 /* cancel */);
|
||||
cx.simulate_prompt_answer(window.window_id(), 2 /* cancel */);
|
||||
cx.foreground().run_until_parked();
|
||||
assert!(!cx.has_pending_prompt(window_id));
|
||||
assert!(!cx.has_pending_prompt(window.window_id()));
|
||||
assert!(!task.await.unwrap());
|
||||
}
|
||||
|
||||
|
@ -4312,26 +4308,27 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, None, cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
let item1 = cx.add_view(window_id, |cx| {
|
||||
let item1 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
|
||||
});
|
||||
let item2 = cx.add_view(window_id, |cx| {
|
||||
let item2 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_conflict(true)
|
||||
.with_project_items(&[TestProjectItem::new(2, "2.txt", cx)])
|
||||
});
|
||||
let item3 = cx.add_view(window_id, |cx| {
|
||||
let item3 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_conflict(true)
|
||||
.with_project_items(&[TestProjectItem::new(3, "3.txt", cx)])
|
||||
});
|
||||
let item4 = cx.add_view(window_id, |cx| {
|
||||
let item4 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_project_items(&[TestProjectItem::new_untitled(cx)])
|
||||
|
@ -4359,10 +4356,10 @@ mod tests {
|
|||
assert_eq!(pane.items_len(), 4);
|
||||
assert_eq!(pane.active_item().unwrap().id(), item1.id());
|
||||
});
|
||||
assert!(cx.has_pending_prompt(window_id));
|
||||
assert!(cx.has_pending_prompt(window.window_id()));
|
||||
|
||||
// Confirm saving item 1.
|
||||
cx.simulate_prompt_answer(window_id, 0);
|
||||
cx.simulate_prompt_answer(window.window_id(), 0);
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
// Item 1 is saved. There's a prompt to save item 3.
|
||||
|
@ -4373,10 +4370,10 @@ mod tests {
|
|||
assert_eq!(pane.items_len(), 3);
|
||||
assert_eq!(pane.active_item().unwrap().id(), item3.id());
|
||||
});
|
||||
assert!(cx.has_pending_prompt(window_id));
|
||||
assert!(cx.has_pending_prompt(window.window_id()));
|
||||
|
||||
// Cancel saving item 3.
|
||||
cx.simulate_prompt_answer(window_id, 1);
|
||||
cx.simulate_prompt_answer(window.window_id(), 1);
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
// Item 3 is reloaded. There's a prompt to save item 4.
|
||||
|
@ -4387,10 +4384,10 @@ mod tests {
|
|||
assert_eq!(pane.items_len(), 2);
|
||||
assert_eq!(pane.active_item().unwrap().id(), item4.id());
|
||||
});
|
||||
assert!(cx.has_pending_prompt(window_id));
|
||||
assert!(cx.has_pending_prompt(window.window_id()));
|
||||
|
||||
// Confirm saving item 4.
|
||||
cx.simulate_prompt_answer(window_id, 0);
|
||||
cx.simulate_prompt_answer(window.window_id(), 0);
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
// There's a prompt for a path for item 4.
|
||||
|
@ -4414,13 +4411,14 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
// Create several workspace items with single project entries, and two
|
||||
// workspace items with multiple project entries.
|
||||
let single_entry_items = (0..=4)
|
||||
.map(|project_entry_id| {
|
||||
cx.add_view(window_id, |cx| {
|
||||
window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_project_items(&[TestProjectItem::new(
|
||||
|
@ -4431,7 +4429,7 @@ mod tests {
|
|||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let item_2_3 = cx.add_view(window_id, |cx| {
|
||||
let item_2_3 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_singleton(false)
|
||||
|
@ -4440,7 +4438,7 @@ mod tests {
|
|||
single_entry_items[3].read(cx).project_items[0].clone(),
|
||||
])
|
||||
});
|
||||
let item_3_4 = cx.add_view(window_id, |cx| {
|
||||
let item_3_4 = window.add_view(cx, |cx| {
|
||||
TestItem::new()
|
||||
.with_dirty(true)
|
||||
.with_singleton(false)
|
||||
|
@ -4492,7 +4490,7 @@ mod tests {
|
|||
&[ProjectEntryId::from_proto(0)]
|
||||
);
|
||||
});
|
||||
cx.simulate_prompt_answer(window_id, 0);
|
||||
cx.simulate_prompt_answer(window.window_id(), 0);
|
||||
|
||||
cx.foreground().run_until_parked();
|
||||
left_pane.read_with(cx, |pane, cx| {
|
||||
|
@ -4501,7 +4499,7 @@ mod tests {
|
|||
&[ProjectEntryId::from_proto(2)]
|
||||
);
|
||||
});
|
||||
cx.simulate_prompt_answer(window_id, 0);
|
||||
cx.simulate_prompt_answer(window.window_id(), 0);
|
||||
|
||||
cx.foreground().run_until_parked();
|
||||
close.await.unwrap();
|
||||
|
@ -4517,10 +4515,11 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
let item = cx.add_view(window_id, |cx| {
|
||||
let item = window.add_view(cx, |cx| {
|
||||
TestItem::new().with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
|
||||
});
|
||||
let item_id = item.id();
|
||||
|
@ -4560,7 +4559,7 @@ mod tests {
|
|||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 2));
|
||||
|
||||
// Deactivating the window still saves the file.
|
||||
cx.simulate_window_activation(Some(window_id));
|
||||
cx.simulate_window_activation(Some(window.window_id()));
|
||||
item.update(cx, |item, cx| {
|
||||
cx.focus_self();
|
||||
item.is_dirty = true;
|
||||
|
@ -4602,7 +4601,7 @@ mod tests {
|
|||
pane.update(cx, |pane, cx| pane.close_items(cx, move |id| id == item_id))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!cx.has_pending_prompt(window_id));
|
||||
assert!(!cx.has_pending_prompt(window.window_id()));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
|
||||
// Add the item again, ensuring autosave is prevented if the underlying file has been deleted.
|
||||
|
@ -4623,7 +4622,7 @@ mod tests {
|
|||
let _close_items =
|
||||
pane.update(cx, |pane, cx| pane.close_items(cx, move |id| id == item_id));
|
||||
deterministic.run_until_parked();
|
||||
assert!(cx.has_pending_prompt(window_id));
|
||||
assert!(cx.has_pending_prompt(window.window_id()));
|
||||
item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));
|
||||
}
|
||||
|
||||
|
@ -4634,9 +4633,10 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
let item = cx.add_view(window_id, |cx| {
|
||||
let item = window.add_view(cx, |cx| {
|
||||
TestItem::new().with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
|
||||
});
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
@ -4687,7 +4687,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
let panel = workspace.update(cx, |workspace, cx| {
|
||||
let panel = cx.add_view(|_| TestPanel::new(DockPosition::Right));
|
||||
|
@ -4834,7 +4835,8 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
|
||||
let (panel_1, panel_2) = workspace.update(cx, |workspace, cx| {
|
||||
// Add panel_1 on the left, panel_2 on the right.
|
||||
|
@ -4989,7 +4991,7 @@ mod tests {
|
|||
|
||||
// If focus is transferred to another view that's not a panel or another pane, we still show
|
||||
// the panel as zoomed.
|
||||
let focus_receiver = cx.add_view(window_id, |_| EmptyView);
|
||||
let focus_receiver = window.add_view(cx, |_| EmptyView);
|
||||
focus_receiver.update(cx, |_, cx| cx.focus_self());
|
||||
workspace.read_with(cx, |workspace, _| {
|
||||
assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any()));
|
||||
|
|
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
|
|||
description = "The fast, collaborative code editor."
|
||||
edition = "2021"
|
||||
name = "zed"
|
||||
version = "0.98.0"
|
||||
version = "0.99.0"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
name = "Shell Script"
|
||||
path_suffixes = [".sh", ".bash", ".bashrc", ".bash_profile", ".bash_aliases", ".bash_logout", ".profile", ".zsh", ".zshrc", ".zshenv", ".zsh_profile", ".zsh_aliases", ".zsh_histfile", ".zlogin"]
|
||||
path_suffixes = ["sh", "bash", "bashrc", "bash_profile", "bash_aliases", "bash_logout", "profile", "zsh", "zshrc", "zshenv", "zsh_profile", "zsh_aliases", "zsh_histfile", "zlogin"]
|
||||
line_comment = "# "
|
||||
first_line_pattern = "^#!.*\\b(?:ba|z)?sh\\b"
|
||||
brackets = [
|
||||
{ start = "[", end = "]", close = true, newline = false },
|
||||
|
|
|
@ -54,5 +54,5 @@
|
|||
|
||||
(
|
||||
(command (_) @constant)
|
||||
(.match? @constant "^-")
|
||||
(#match? @constant "^-")
|
||||
)
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
(identifier) @variable
|
||||
|
||||
((identifier) @constant
|
||||
(.match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
|
@ -106,3 +106,4 @@
|
|||
(primitive_type)
|
||||
(sized_type_specifier)
|
||||
] @type
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(preproc_def
|
||||
value: (preproc_arg) @content
|
||||
(.set! "language" "c"))
|
||||
(#set! "language" "c"))
|
||||
|
||||
(preproc_function_def
|
||||
value: (preproc_arg) @content
|
||||
(.set! "language" "c"))
|
||||
(#set! "language" "c"))
|
|
@ -31,13 +31,13 @@
|
|||
declarator: (field_identifier) @function)
|
||||
|
||||
((namespace_identifier) @type
|
||||
(.match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
|
||||
(auto) @type
|
||||
(type_identifier) @type
|
||||
|
||||
((identifier) @constant
|
||||
(.match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
|
||||
(field_identifier) @property
|
||||
(statement_identifier) @label
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(preproc_def
|
||||
value: (preproc_arg) @content
|
||||
(.set! "language" "c++"))
|
||||
(#set! "language" "c++"))
|
||||
|
||||
(preproc_function_def
|
||||
value: (preproc_arg) @content
|
||||
(.set! "language" "c++"))
|
||||
(#set! "language" "c++"))
|
|
@ -46,7 +46,7 @@
|
|||
(property_name)
|
||||
(plain_value)
|
||||
] @variable.special
|
||||
(.match? @variable.special "^--")
|
||||
(#match? @variable.special "^--")
|
||||
)
|
||||
|
||||
[
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
operator: "@"
|
||||
operand: (call
|
||||
target: (identifier) @unary
|
||||
(.match? @unary "^(doc)$"))
|
||||
(#match? @unary "^(doc)$"))
|
||||
) @context
|
||||
.
|
||||
(call
|
||||
|
@ -18,10 +18,10 @@
|
|||
target: (identifier) @name)
|
||||
operator: "when")
|
||||
])
|
||||
(.match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item
|
||||
(#match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item
|
||||
)
|
||||
|
||||
(call
|
||||
target: (identifier) @name
|
||||
(arguments (alias) @name)
|
||||
(.match? @name "^(defmodule|defprotocol)$")) @item
|
||||
(#match? @name "^(defmodule|defprotocol)$")) @item
|
||||
|
|
|
@ -54,13 +54,13 @@
|
|||
(sigil_name) @__name__
|
||||
quoted_start: _ @string
|
||||
quoted_end: _ @string
|
||||
(.match? @__name__ "^[sS]$")) @string
|
||||
(#match? @__name__ "^[sS]$")) @string
|
||||
|
||||
(sigil
|
||||
(sigil_name) @__name__
|
||||
quoted_start: _ @string.regex
|
||||
quoted_end: _ @string.regex
|
||||
(.match? @__name__ "^[rR]$")) @string.regex
|
||||
(#match? @__name__ "^[rR]$")) @string.regex
|
||||
|
||||
(sigil
|
||||
(sigil_name) @__name__
|
||||
|
@ -69,7 +69,7 @@
|
|||
|
||||
(
|
||||
(identifier) @comment.unused
|
||||
(.match? @comment.unused "^_")
|
||||
(#match? @comment.unused "^_")
|
||||
)
|
||||
|
||||
(call
|
||||
|
@ -91,7 +91,7 @@
|
|||
operator: "|>"
|
||||
right: (identifier))
|
||||
])
|
||||
(.match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
||||
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
|
||||
|
||||
(binary_operator
|
||||
operator: "|>"
|
||||
|
@ -99,15 +99,15 @@
|
|||
|
||||
(call
|
||||
target: (identifier) @keyword
|
||||
(.match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
|
||||
(#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$"))
|
||||
|
||||
(call
|
||||
target: (identifier) @keyword
|
||||
(.match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
|
||||
(#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
|
||||
|
||||
(
|
||||
(identifier) @constant.builtin
|
||||
(.match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
|
||||
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$")
|
||||
)
|
||||
|
||||
(unary_operator
|
||||
|
@ -121,7 +121,7 @@
|
|||
(sigil)
|
||||
(boolean)
|
||||
] @comment.doc))
|
||||
(.match? @__attribute__ "^(moduledoc|typedoc|doc)$"))
|
||||
(#match? @__attribute__ "^(moduledoc|typedoc|doc)$"))
|
||||
|
||||
(comment) @comment
|
||||
|
||||
|
@ -150,4 +150,4 @@
|
|||
((sigil
|
||||
(sigil_name) @_sigil_name
|
||||
(quoted_content) @embedded)
|
||||
(.eq? @_sigil_name "H"))
|
||||
(#eq? @_sigil_name "H"))
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
((sigil
|
||||
(sigil_name) @_sigil_name
|
||||
(quoted_content) @content)
|
||||
(.eq? @_sigil_name "H")
|
||||
(.set! language "heex"))
|
||||
(#eq? @_sigil_name "H")
|
||||
(#set! language "heex"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(call
|
||||
target: (identifier) @context
|
||||
(arguments (alias) @name)
|
||||
(.match? @context "^(defmodule|defprotocol)$")) @item
|
||||
(#match? @context "^(defmodule|defprotocol)$")) @item
|
||||
|
||||
(call
|
||||
target: (identifier) @context
|
||||
|
@ -23,4 +23,4 @@
|
|||
")" @context.extra))
|
||||
operator: "when")
|
||||
])
|
||||
(.match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item
|
||||
(#match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
((glsl_content) @content
|
||||
(.set! "language" "glsl"))
|
||||
(#set! "language" "glsl"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
((code) @content
|
||||
(.set! "language" "ruby")
|
||||
(.set! "combined"))
|
||||
(#set! "language" "ruby")
|
||||
(#set! "combined"))
|
||||
|
||||
((content) @content
|
||||
(.set! "language" "html")
|
||||
(.set! "combined"))
|
||||
(#set! "language" "html")
|
||||
(#set! "combined"))
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
(sized_type_specifier) @type
|
||||
|
||||
((identifier) @constant
|
||||
(.match? @constant "^[A-Z][A-Z\\d_]*$"))
|
||||
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
|
@ -114,5 +114,5 @@
|
|||
|
||||
(
|
||||
(identifier) @variable.builtin
|
||||
(.match? @variable.builtin "^gl_")
|
||||
(#match? @variable.builtin "^gl_")
|
||||
)
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
(expression_value)
|
||||
(ending_expression_value)
|
||||
] @content)
|
||||
(.set! language "elixir")
|
||||
(.set! combined)
|
||||
(#set! language "elixir")
|
||||
(#set! combined)
|
||||
)
|
||||
|
||||
((expression (expression_value) @content)
|
||||
(.set! language "elixir"))
|
||||
(#set! language "elixir"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(script_element
|
||||
(raw_text) @content
|
||||
(.set! "language" "javascript"))
|
||||
(#set! "language" "javascript"))
|
||||
|
||||
(style_element
|
||||
(raw_text) @content
|
||||
(.set! "language" "css"))
|
||||
(#set! "language" "css"))
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
; Special identifiers
|
||||
|
||||
((identifier) @type
|
||||
(.match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
(type_identifier) @type
|
||||
(predefined_type) @type.builtin
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
|||
(shorthand_property_identifier)
|
||||
(shorthand_property_identifier_pattern)
|
||||
] @constant
|
||||
(.match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
|
||||
|
||||
; Literals
|
||||
|
||||
|
@ -214,4 +214,4 @@
|
|||
"type"
|
||||
"readonly"
|
||||
"override"
|
||||
] @keyword
|
||||
] @keyword
|
|
@ -127,7 +127,7 @@
|
|||
(identifier) @variable
|
||||
|
||||
((identifier) @variable.special
|
||||
(.eq? @variable.special "self"))
|
||||
(#eq? @variable.special "self"))
|
||||
|
||||
(variable_list
|
||||
attribute: (attribute
|
||||
|
@ -137,7 +137,7 @@
|
|||
;; Constants
|
||||
|
||||
((identifier) @constant
|
||||
(.match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||
|
||||
(vararg_expression) @constant
|
||||
|
||||
|
@ -158,7 +158,7 @@
|
|||
[
|
||||
"{"
|
||||
"}"
|
||||
] @method.constructor)
|
||||
] @constructor)
|
||||
|
||||
;; Functions
|
||||
|
||||
|
@ -180,7 +180,7 @@
|
|||
|
||||
(function_call
|
||||
(identifier) @function.builtin
|
||||
(.any-of? @function.builtin
|
||||
(#any-of? @function.builtin
|
||||
;; built-in functions in Lua 5.1
|
||||
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
|
||||
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
|
||||
|
@ -195,4 +195,4 @@
|
|||
|
||||
(number) @number
|
||||
|
||||
(string) @string
|
||||
(string) @string
|
|
@ -43,15 +43,15 @@
|
|||
(relative_scope) @variable.builtin
|
||||
|
||||
((name) @constant
|
||||
(.match? @constant "^_?[A-Z][A-Z\\d_]+$"))
|
||||
(#match? @constant "^_?[A-Z][A-Z\\d_]+$"))
|
||||
((name) @constant.builtin
|
||||
(.match? @constant.builtin "^__[A-Z][A-Z\d_]+__$"))
|
||||
(#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$"))
|
||||
|
||||
((name) @method.constructor
|
||||
(.match? @method.constructor "^[A-Z]"))
|
||||
((name) @constructor
|
||||
(#match? @constructor "^[A-Z]"))
|
||||
|
||||
((name) @variable.builtin
|
||||
(.eq? @variable.builtin "this"))
|
||||
(#eq? @variable.builtin "this"))
|
||||
|
||||
(variable_name) @variable
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
((text) @content
|
||||
(.set! "language" "html")
|
||||
(.set! "combined"))
|
||||
(#set! "language" "html")
|
||||
(#set! "combined"))
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
; Identifier naming conventions
|
||||
|
||||
((identifier) @type
|
||||
(.match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
|
||||
((identifier) @constant
|
||||
(.match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
|
||||
; Builtin functions
|
||||
|
||||
((call
|
||||
function: (identifier) @function.builtin)
|
||||
(.match?
|
||||
(#match?
|
||||
@function.builtin
|
||||
"^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
|
||||
|
||||
|
@ -122,4 +122,4 @@
|
|||
"yield"
|
||||
"match"
|
||||
"case"
|
||||
] @keyword
|
||||
] @keyword
|
File diff suppressed because one or more lines are too long
|
@ -6,5 +6,5 @@
|
|||
(symbol) @name
|
||||
(list . (symbol) @name)
|
||||
]
|
||||
(.match? @start-symbol "^define")
|
||||
) @item
|
||||
(#match? @start-symbol "^define")
|
||||
) @item
|
|
@ -11,4 +11,4 @@
|
|||
(begin "begin" @open "end" @close)
|
||||
(module "module" @open "end" @close)
|
||||
(_ . "def" @open "end" @close)
|
||||
(_ . "class" @open "end" @close)
|
||||
(_ . "class" @open "end" @close)
|
|
@ -33,12 +33,12 @@
|
|||
(identifier) @variable
|
||||
|
||||
((identifier) @keyword
|
||||
(.match? @keyword "^(private|protected|public)$"))
|
||||
(#match? @keyword "^(private|protected|public)$"))
|
||||
|
||||
; Function calls
|
||||
|
||||
((identifier) @function.method.builtin
|
||||
(.eq? @function.method.builtin "require"))
|
||||
(#eq? @function.method.builtin "require"))
|
||||
|
||||
"defined?" @function.method.builtin
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
|||
] @property
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(.match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
|
||||
(#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
|
||||
|
||||
(file) @constant.builtin
|
||||
(line) @constant.builtin
|
||||
|
@ -71,7 +71,7 @@
|
|||
) @constant.builtin
|
||||
|
||||
((constant) @constant
|
||||
(.match? @constant "^[A-Z\\d_]+$"))
|
||||
(#match? @constant "^[A-Z\\d_]+$"))
|
||||
|
||||
(constant) @type
|
||||
|
||||
|
|
|
@ -38,11 +38,11 @@
|
|||
|
||||
; Assume uppercase names are types/enum-constructors
|
||||
((identifier) @type
|
||||
(.match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
|
||||
; Assume all-caps names are constants
|
||||
((identifier) @constant
|
||||
(.match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
||||
|
||||
[
|
||||
"("
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(macro_invocation
|
||||
(token_tree) @content
|
||||
(.set! "language" "rust"))
|
||||
(#set! "language" "rust"))
|
||||
|
||||
(macro_rule
|
||||
(token_tree) @content
|
||||
(.set! "language" "rust"))
|
||||
(#set! "language" "rust"))
|
|
@ -14,7 +14,7 @@
|
|||
(directive)] @comment
|
||||
|
||||
((symbol) @operator
|
||||
(.match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$"))
|
||||
(#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$"))
|
||||
|
||||
(list
|
||||
.
|
||||
|
@ -23,6 +23,6 @@
|
|||
(list
|
||||
.
|
||||
(symbol) @keyword
|
||||
(.match? @keyword
|
||||
(#match? @keyword
|
||||
"^(define-syntax|let\\*|lambda|λ|case|=>|quote-splicing|unquote-splicing|set!|let|letrec|letrec-syntax|let-values|let\\*-values|do|else|define|cond|syntax-rules|unquote|begin|quote|let-syntax|and|if|quasiquote|letrec|delay|or|when|unless|identifier-syntax|assert|library|export|import|rename|only|except|prefix)$"
|
||||
))
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
(symbol) @name
|
||||
(list . (symbol) @name)
|
||||
]
|
||||
(.match? @start-symbol "^define")
|
||||
) @item
|
||||
(#match? @start-symbol "^define")
|
||||
) @item
|
|
@ -2,27 +2,27 @@
|
|||
; --------------
|
||||
(script_element
|
||||
(raw_text) @content
|
||||
(.set! "language" "javascript"))
|
||||
(#set! "language" "javascript"))
|
||||
|
||||
((script_element
|
||||
(start_tag
|
||||
(attribute
|
||||
(quoted_attribute_value (attribute_value) @_language)))
|
||||
(raw_text) @content)
|
||||
(.eq? @_language "ts")
|
||||
(.set! "language" "typescript"))
|
||||
(#eq? @_language "ts")
|
||||
(#set! "language" "typescript"))
|
||||
|
||||
((script_element
|
||||
(start_tag
|
||||
(attribute
|
||||
(quoted_attribute_value (attribute_value) @_language)))
|
||||
(raw_text) @content)
|
||||
(.eq? @_language "typescript")
|
||||
(.set! "language" "typescript"))
|
||||
(#eq? @_language "typescript")
|
||||
(#set! "language" "typescript"))
|
||||
|
||||
(style_element
|
||||
(raw_text) @content
|
||||
(.set! "language" "css"))
|
||||
(#set! "language" "css"))
|
||||
|
||||
((raw_text_expr) @content
|
||||
(.set! "language" "javascript"))
|
||||
(#set! "language" "javascript"))
|
||||
|
|
|
@ -43,11 +43,11 @@
|
|||
|
||||
; Special identifiers
|
||||
|
||||
((identifier) @method.constructor
|
||||
(.match? @method.constructor "^[A-Z]"))
|
||||
((identifier) @constructor
|
||||
(#match? @constructor "^[A-Z]"))
|
||||
|
||||
((identifier) @type
|
||||
(.match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
(type_identifier) @type
|
||||
(predefined_type) @type.builtin
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
(shorthand_property_identifier)
|
||||
(shorthand_property_identifier_pattern)
|
||||
] @constant
|
||||
(.match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
|
||||
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
|
||||
|
||||
; Literals
|
||||
|
||||
|
@ -218,4 +218,4 @@
|
|||
"type"
|
||||
"readonly"
|
||||
"override"
|
||||
] @keyword
|
||||
] @keyword
|
|
@ -981,7 +981,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
|
||||
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
||||
let file1 = entries[0].clone();
|
||||
|
@ -1293,7 +1295,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Open a file within an existing worktree.
|
||||
workspace
|
||||
|
@ -1334,7 +1338,9 @@ mod tests {
|
|||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());
|
||||
|
||||
// Create a new untitled buffer
|
||||
|
@ -1427,7 +1433,9 @@ mod tests {
|
|||
|
||||
let project = Project::test(app_state.fs.clone(), [], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(rust_lang()));
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Create a new untitled buffer
|
||||
cx.dispatch_action(window_id, NewFile);
|
||||
|
@ -1478,7 +1486,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
|
||||
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
||||
let file1 = entries[0].clone();
|
||||
|
@ -1552,7 +1562,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project.clone(), cx))
|
||||
.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
||||
|
@ -1829,7 +1841,9 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = cx
|
||||
.add_window(|cx| Workspace::test_new(project, cx))
|
||||
.root(cx);
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
|
||||
let entries = cx.read(|cx| workspace.file_project_paths(cx));
|
||||
|
@ -2071,7 +2085,8 @@ mod tests {
|
|||
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
let (window_id, _view) = cx.add_window(|_| TestView);
|
||||
let window = cx.add_window(|_| TestView);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Test loading the keymap base at all
|
||||
assert_key_bindings_for(
|
||||
|
@ -2241,7 +2256,8 @@ mod tests {
|
|||
|
||||
cx.foreground().run_until_parked();
|
||||
|
||||
let (window_id, _view) = cx.add_window(|_| TestView);
|
||||
let window = cx.add_window(|_| TestView);
|
||||
let window_id = window.window_id();
|
||||
|
||||
// Test loading the keymap base at all
|
||||
assert_key_bindings_for(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue