From 7394bf1cdc8fd6276c43be160a40276289a1287c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Apr 2023 10:51:53 +0200 Subject: [PATCH] Fix most of the warnings --- crates/context_menu/src/context_menu.rs | 4 --- crates/editor/src/element.rs | 8 ++--- crates/gpui/src/elements.rs | 38 +++++++++++--------- crates/gpui/src/elements/keystroke_label.rs | 3 -- crates/gpui/src/elements/text.rs | 2 +- crates/gpui/src/elements/tooltip.rs | 5 +-- crates/journal/src/journal.rs | 2 +- crates/terminal_view/src/terminal_element.rs | 9 +++-- crates/terminal_view/src/terminal_view.rs | 2 +- crates/theme/src/ui.rs | 3 -- crates/workspace/src/workspace.rs | 14 +++----- crates/zed/src/main.rs | 6 ++-- crates/zed/src/zed.rs | 9 ++--- 13 files changed, 44 insertions(+), 61 deletions(-) diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 465880cef588e3848a87963ed69d2dd57f038ebb..e7a91e0efc18cd4c46eca039eaa1b9b4829378f0 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -332,7 +332,6 @@ impl ContextMenu { &self, cx: &mut ViewContext, ) -> impl Drawable { - let window_id = cx.window_id(); let style = cx.global::().theme.context_menu.clone(); Flex::row() .with_child( @@ -390,7 +389,6 @@ impl ContextMenu { }; KeystrokeLabel::new( - window_id, view_id, action.boxed_clone(), style.keystroke.container, @@ -424,7 +422,6 @@ impl ContextMenu { let style = cx.global::().theme.context_menu.clone(); - let window_id = cx.window_id(); MouseEventHandler::::new(0, cx, |_, cx| { Flex::column() .with_children(self.items.iter().enumerate().map(|(ix, item)| { @@ -456,7 +453,6 @@ impl ContextMenu { }) .with_child({ KeystrokeLabel::new( - window_id, view_id, action.boxed_clone(), style.keystroke.container, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 5f9cd38d6ac49483615bfdcdbf9d832961c74377..f3f985720e9215d521315b191fea403bbfaea203 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1901,8 +1901,8 @@ impl Drawable for EditorElement { let mut context_menu = None; let mut code_actions_indicator = None; - let mut hover = None; - let mut mode = EditorMode::Full; + let mut hover; + let mode; let mut fold_indicators = { let newest_selection_head = editor .selections @@ -2560,7 +2560,7 @@ mod tests { fn test_layout_line_numbers(cx: &mut gpui::AppContext) { cx.set_global(Settings::test(cx)); let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx); - let (window_id, editor) = cx.add_window(Default::default(), |cx| { + let (_, editor) = cx.add_window(Default::default(), |cx| { Editor::new(EditorMode::Full, buffer, None, None, cx) }); let element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx)); @@ -2578,7 +2578,7 @@ mod tests { fn test_layout_with_placeholder_text_and_blocks(cx: &mut gpui::AppContext) { cx.set_global(Settings::test(cx)); let buffer = MultiBuffer::build_simple("", cx); - let (window_id, editor) = cx.add_window(Default::default(), |cx| { + let (_, editor) = cx.add_window(Default::default(), |cx| { Editor::new(EditorMode::Full, buffer, None, None, cx) }); diff --git a/crates/gpui/src/elements.rs b/crates/gpui/src/elements.rs index a13c7ccf075c594b819be00d08ddea39dc37db9d..e5aa225fe334255a07b7dd0cd33c4146b398ac2b 100644 --- a/crates/gpui/src/elements.rs +++ b/crates/gpui/src/elements.rs @@ -586,9 +586,9 @@ impl Drawable for RootElement { fn layout( &mut self, constraint: SizeConstraint, - view: &mut V, + _view: &mut V, cx: &mut ViewContext, - ) -> (Vector2F, Self::LayoutState) { + ) -> (Vector2F, ()) { let size = AnyRootElement::layout(self, constraint, cx) .log_err() .unwrap_or_else(|| Vector2F::zero()); @@ -600,35 +600,39 @@ impl Drawable for RootElement { scene: &mut SceneBuilder, bounds: RectF, visible_bounds: RectF, - layout: &mut Self::LayoutState, - view: &mut V, + _layout: &mut Self::LayoutState, + _view: &mut V, cx: &mut ViewContext, - ) -> Self::PaintState { - todo!() + ) { + AnyRootElement::paint(self, scene, bounds.origin(), visible_bounds, cx).log_err(); } fn rect_for_text_range( &self, range_utf16: Range, - bounds: RectF, - visible_bounds: RectF, - layout: &Self::LayoutState, - paint: &Self::PaintState, - view: &V, + _bounds: RectF, + _visible_bounds: RectF, + _layout: &Self::LayoutState, + _paint: &Self::PaintState, + _view: &V, cx: &ViewContext, ) -> Option { - todo!() + AnyRootElement::rect_for_text_range(self, range_utf16, cx) + .log_err() + .flatten() } fn debug( &self, - bounds: RectF, - layout: &Self::LayoutState, - paint: &Self::PaintState, - view: &V, + _bounds: RectF, + _layout: &Self::LayoutState, + _paint: &Self::PaintState, + _view: &V, cx: &ViewContext, ) -> serde_json::Value { - todo!() + AnyRootElement::debug(self, cx) + .log_err() + .unwrap_or_default() } } diff --git a/crates/gpui/src/elements/keystroke_label.rs b/crates/gpui/src/elements/keystroke_label.rs index d5fd8c6d56ad1140ffd02e50c2e6574e4372c4a4..78d111e29a8600df1e721cef004a178e4220653b 100644 --- a/crates/gpui/src/elements/keystroke_label.rs +++ b/crates/gpui/src/elements/keystroke_label.rs @@ -12,20 +12,17 @@ pub struct KeystrokeLabel { action: Box, container_style: ContainerStyle, text_style: TextStyle, - window_id: usize, view_id: usize, } impl KeystrokeLabel { pub fn new( - window_id: usize, view_id: usize, action: Box, container_style: ContainerStyle, text_style: TextStyle, ) -> Self { Self { - window_id, view_id, action, container_style, diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index fc99907aaf72fc91a504653ad116bcecac5f6ccf..2dde00ea0c8bdfdd48718d2a14b7661a71735ecd 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -280,7 +280,7 @@ mod tests { #[crate::test(self)] fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) { - let (window_id, root_view) = cx.add_window(Default::default(), |_| TestView); + let (_, root_view) = cx.add_window(Default::default(), |_| TestView); fonts::with_font_cache(cx.font_cache().clone(), || { root_view.update(cx, |view, cx| { let mut text = Text::new("Hello\r\n", Default::default()).with_soft_wrap(true); diff --git a/crates/gpui/src/elements/tooltip.rs b/crates/gpui/src/elements/tooltip.rs index 6647281b97425ba19158c0731b30406da7f2b255..1d17b62ba77dd103650f43be3d688e10d9dbcd3c 100644 --- a/crates/gpui/src/elements/tooltip.rs +++ b/crates/gpui/src/elements/tooltip.rs @@ -65,7 +65,6 @@ impl Tooltip { let state = state_handle.read(cx).clone(); let tooltip = if state.visible.get() { let mut collapsed_tooltip = Self::render_tooltip( - cx.window_id, focused_view_id, text.clone(), style.clone(), @@ -75,7 +74,7 @@ impl Tooltip { .boxed(); Some( Overlay::new( - Self::render_tooltip(cx.window_id, focused_view_id, text, style, action, false) + Self::render_tooltip(focused_view_id, text, style, action, false) .constrained() .dynamically(move |constraint, view, cx| { SizeConstraint::strict_along( @@ -128,7 +127,6 @@ impl Tooltip { } pub fn render_tooltip( - window_id: usize, focused_view_id: Option, text: String, style: TooltipStyle, @@ -148,7 +146,6 @@ impl Tooltip { }) .with_children(action.and_then(|action| { let keystroke_label = KeystrokeLabel::new( - window_id, focused_view_id?, action, style.keystroke.container, diff --git a/crates/journal/src/journal.rs b/crates/journal/src/journal.rs index bdc6f5893ff0a2337821e0a4e82fce21c37a8af7..b74eab4f77ad35bf1cb2b526083cda051d2b67b7 100644 --- a/crates/journal/src/journal.rs +++ b/crates/journal/src/journal.rs @@ -48,7 +48,7 @@ pub fn new_journal_entry(app_state: Arc, cx: &mut AppContext) { async move { let (journal_dir, entry_path) = create_entry.await?; let (workspace, _) = cx - .update(|cx| workspace::open_paths(&[journal_dir], &app_state, None, cx)) + .update(|cx| workspace::open_paths(&[journal_dir], &app_state, cx)) .await; let opened = workspace diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 5fe22f6e274e998f63fcc5ed07c10f09fd054b52..06f5cc9227a5dcdc00dd6400a6fb0b5f6a69c8d6 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -88,7 +88,7 @@ impl LayoutCell { origin: Vector2F, layout: &LayoutState, visible_bounds: RectF, - view: &mut TerminalView, + _view: &mut TerminalView, cx: &mut ViewContext, ) { let pos = { @@ -133,8 +133,8 @@ impl LayoutRect { scene: &mut SceneBuilder, origin: Vector2F, layout: &LayoutState, - view: &mut TerminalView, - cx: &mut ViewContext, + _view: &mut TerminalView, + _cx: &mut ViewContext, ) { let position = { let point = self.point; @@ -390,7 +390,7 @@ impl TerminalElement { view_id: usize, visible_bounds: RectF, mode: TermMode, - cx: &mut ViewContext, + _cx: &mut ViewContext, ) { let connection = self.terminal; @@ -597,7 +597,6 @@ impl Drawable for TerminalElement { terminal.last_content.last_hovered_hyperlink.clone() }); - let view_handle = self.view.clone(); let hyperlink_tooltip = last_hovered_hyperlink.map(|(uri, _, id)| { let mut tooltip = Overlay::new( Empty::new() diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index eef6859c80b1848bf4414cf0e1414902cd5f581d..3358fdc8d66b69a393fb2d8d74eec5721ab26ceb 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -12,7 +12,7 @@ use context_menu::{ContextMenu, ContextMenuItem}; use dirs::home_dir; use gpui::{ actions, - elements::{AnchorCorner, ChildView, Flex, Label, ParentElement, Stack, Text}, + elements::{AnchorCorner, ChildView, Flex, Label, ParentElement, Stack}, geometry::vector::Vector2F, impl_actions, impl_internal_actions, keymap_matcher::{KeymapContext, Keystroke}, diff --git a/crates/theme/src/ui.rs b/crates/theme/src/ui.rs index e6a762808ffa5331d393e697ef2d6514c5e20242..fe31d1f1415183749270923d4e13e800df824f19 100644 --- a/crates/theme/src/ui.rs +++ b/crates/theme/src/ui.rs @@ -135,7 +135,6 @@ pub fn keystroke_label( // FIXME: Put the theme in it's own global so we can // query the keystroke style on our own keystroke_label_for( - cx.window_id(), cx.handle().id(), label_text, label_style, @@ -145,7 +144,6 @@ pub fn keystroke_label( } pub fn keystroke_label_for( - window_id: usize, view_id: usize, label_text: &'static str, label_style: &ContainedText, @@ -160,7 +158,6 @@ pub fn keystroke_label_for( ) .with_child({ KeystrokeLabel::new( - window_id, view_id, action, keystroke_style.container, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ba687f19dd3fc808f6430935e99612791e77bcab..56087a661dcf044cf3078899e24cdc4a9d32ba64 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -286,7 +286,7 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { let app_state = Arc::downgrade(&app_state); move |action: &OpenPaths, cx: &mut AppContext| { if let Some(app_state) = app_state.upgrade() { - open_paths(&action.paths, &app_state, None, cx).detach(); + open_paths(&action.paths, &app_state, cx).detach(); } } }); @@ -299,14 +299,13 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { } let app_state = app_state.upgrade()?; - let window_id = cx.window_id(); let action = action.clone(); let close = workspace.prepare_to_close(false, cx); Some(cx.spawn_weak(|_, mut cx| async move { let can_close = close.await?; if can_close { - cx.update(|cx| open_paths(&action.paths, &app_state, Some(window_id), cx)) + cx.update(|cx| open_paths(&action.paths, &app_state, cx)) .await; } Ok(()) @@ -857,7 +856,6 @@ impl Workspace { fn new_local( abs_paths: Vec, app_state: Arc, - requesting_window_id: Option, cx: &mut AppContext, ) -> Task<( ViewHandle, @@ -1059,7 +1057,7 @@ impl Workspace { if self.project.read(cx).is_local() { Task::Ready(Some(callback(self, cx))) } else { - let task = Self::new_local(Vec::new(), app_state.clone(), None, cx); + let task = Self::new_local(Vec::new(), app_state.clone(), cx); cx.spawn(|_vh, mut cx| async move { let (workspace, _) = task.await; workspace.update(&mut cx, callback) @@ -3027,7 +3025,6 @@ pub async fn last_opened_workspace_paths() -> Option { pub fn open_paths( abs_paths: &[PathBuf], app_state: &Arc, - requesting_window_id: Option, cx: &mut AppContext, ) -> Task<( ViewHandle, @@ -3058,8 +3055,7 @@ pub fn open_paths( .contains(&false); cx.update(|cx| { - let task = - Workspace::new_local(abs_paths, app_state.clone(), requesting_window_id, cx); + let task = Workspace::new_local(abs_paths, app_state.clone(), cx); cx.spawn(|mut cx| async move { let (workspace, items) = task.await; @@ -3083,7 +3079,7 @@ pub fn open_new( cx: &mut AppContext, init: impl FnOnce(&mut Workspace, &mut ViewContext) + 'static, ) -> Task<()> { - let task = Workspace::new_local(Vec::new(), app_state.clone(), None, cx); + let task = Workspace::new_local(Vec::new(), app_state.clone(), cx); cx.spawn(|mut cx| async move { let (workspace, opened_paths) = task.await; diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 0e4f15261f9dd22c28968ae91f3837d8f02a0731..4f453ec32e26f407a416c93f22e75fdfd6a3bf21 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -219,7 +219,7 @@ fn main() { cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx)) .detach(); } else if let Ok(Some(paths)) = open_paths_rx.try_next() { - cx.update(|cx| workspace::open_paths(&paths, &app_state, None, cx)) + cx.update(|cx| workspace::open_paths(&paths, &app_state, cx)) .detach(); } else { cx.spawn({ @@ -243,7 +243,7 @@ fn main() { let app_state = app_state.clone(); async move { while let Some(paths) = open_paths_rx.next().await { - cx.update(|cx| workspace::open_paths(&paths, &app_state, None, cx)) + cx.update(|cx| workspace::open_paths(&paths, &app_state, cx)) .detach(); } } @@ -607,7 +607,7 @@ async fn handle_cli_connection( paths }; let (workspace, items) = cx - .update(|cx| workspace::open_paths(&paths, &app_state, None, cx)) + .update(|cx| workspace::open_paths(&paths, &app_state, cx)) .await; let mut errored = false; diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 49404d6ebcd165657b36c75e8a813055b301d86d..19401d53127376db9fcc07ca500436d7ded53ce6 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -703,14 +703,13 @@ mod tests { open_paths( &[PathBuf::from("/root/a"), PathBuf::from("/root/b")], &app_state, - None, cx, ) }) .await; assert_eq!(cx.window_ids().len(), 1); - cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, None, cx)) + cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, cx)) .await; assert_eq!(cx.window_ids().len(), 1); let workspace_1 = cx @@ -728,7 +727,6 @@ mod tests { open_paths( &[PathBuf::from("/root/b"), PathBuf::from("/root/c")], &app_state, - None, cx, ) }) @@ -741,7 +739,6 @@ mod tests { open_paths( &[PathBuf::from("/root/c"), PathBuf::from("/root/d")], &app_state, - Some(window_id), cx, ) }) @@ -771,7 +768,7 @@ mod tests { .insert_tree("/root", json!({"a": "hey"})) .await; - cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, None, cx)) + cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, cx)) .await; assert_eq!(cx.window_ids().len(), 1); @@ -813,7 +810,7 @@ mod tests { assert!(!cx.is_window_edited(workspace.window_id())); // Opening the buffer again doesn't impact the window's edited state. - cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, None, cx)) + cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, cx)) .await; let editor = workspace.read_with(cx, |workspace, cx| { workspace