Fix most of the warnings

Antonio Scandurra created

Change summary

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(-)

Detailed changes

crates/context_menu/src/context_menu.rs 🔗

@@ -332,7 +332,6 @@ impl ContextMenu {
         &self,
         cx: &mut ViewContext<Self>,
     ) -> impl Drawable<ContextMenu> {
-        let window_id = cx.window_id();
         let style = cx.global::<Settings>().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::<Settings>().theme.context_menu.clone();
 
-        let window_id = cx.window_id();
         MouseEventHandler::<Menu, ContextMenu>::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,

crates/editor/src/element.rs 🔗

@@ -1901,8 +1901,8 @@ impl Drawable<Editor> 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)
         });
 

crates/gpui/src/elements.rs 🔗

@@ -586,9 +586,9 @@ impl<V: View, R: View> Drawable<V> for RootElement<R> {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        view: &mut V,
+        _view: &mut V,
         cx: &mut ViewContext<V>,
-    ) -> (Vector2F, Self::LayoutState) {
+    ) -> (Vector2F, ()) {
         let size = AnyRootElement::layout(self, constraint, cx)
             .log_err()
             .unwrap_or_else(|| Vector2F::zero());
@@ -600,35 +600,39 @@ impl<V: View, R: View> Drawable<V> for RootElement<R> {
         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<V>,
-    ) -> Self::PaintState {
-        todo!()
+    ) {
+        AnyRootElement::paint(self, scene, bounds.origin(), visible_bounds, cx).log_err();
     }
 
     fn rect_for_text_range(
         &self,
         range_utf16: Range<usize>,
-        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<V>,
     ) -> Option<RectF> {
-        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<V>,
     ) -> serde_json::Value {
-        todo!()
+        AnyRootElement::debug(self, cx)
+            .log_err()
+            .unwrap_or_default()
     }
 }
 

crates/gpui/src/elements/keystroke_label.rs 🔗

@@ -12,20 +12,17 @@ pub struct KeystrokeLabel {
     action: Box<dyn Action>,
     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<dyn Action>,
         container_style: ContainerStyle,
         text_style: TextStyle,
     ) -> Self {
         Self {
-            window_id,
             view_id,
             action,
             container_style,

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);

crates/gpui/src/elements/tooltip.rs 🔗

@@ -65,7 +65,6 @@ impl<V: View> Tooltip<V> {
         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<V: View> Tooltip<V> {
             .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<V: View> Tooltip<V> {
     }
 
     pub fn render_tooltip(
-        window_id: usize,
         focused_view_id: Option<usize>,
         text: String,
         style: TooltipStyle,
@@ -148,7 +146,6 @@ impl<V: View> Tooltip<V> {
             })
             .with_children(action.and_then(|action| {
                 let keystroke_label = KeystrokeLabel::new(
-                    window_id,
                     focused_view_id?,
                     action,
                     style.keystroke.container,

crates/journal/src/journal.rs 🔗

@@ -48,7 +48,7 @@ pub fn new_journal_entry(app_state: Arc<AppState>, 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

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<TerminalView>,
     ) {
         let pos = {
@@ -133,8 +133,8 @@ impl LayoutRect {
         scene: &mut SceneBuilder,
         origin: Vector2F,
         layout: &LayoutState,
-        view: &mut TerminalView,
-        cx: &mut ViewContext<TerminalView>,
+        _view: &mut TerminalView,
+        _cx: &mut ViewContext<TerminalView>,
     ) {
         let position = {
             let point = self.point;
@@ -390,7 +390,7 @@ impl TerminalElement {
         view_id: usize,
         visible_bounds: RectF,
         mode: TermMode,
-        cx: &mut ViewContext<TerminalView>,
+        _cx: &mut ViewContext<TerminalView>,
     ) {
         let connection = self.terminal;
 
@@ -597,7 +597,6 @@ impl Drawable<TerminalView> 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()

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},

crates/theme/src/ui.rs 🔗

@@ -135,7 +135,6 @@ pub fn keystroke_label<V: View>(
     // 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<V: View>(
 }
 
 pub fn keystroke_label_for<V: View>(
-    window_id: usize,
     view_id: usize,
     label_text: &'static str,
     label_style: &ContainedText,
@@ -160,7 +158,6 @@ pub fn keystroke_label_for<V: View>(
         )
         .with_child({
             KeystrokeLabel::new(
-                window_id,
                 view_id,
                 action,
                 keystroke_style.container,

crates/workspace/src/workspace.rs 🔗

@@ -286,7 +286,7 @@ pub fn init(app_state: Arc<AppState>, 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<AppState>, 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<PathBuf>,
         app_state: Arc<AppState>,
-        requesting_window_id: Option<usize>,
         cx: &mut AppContext,
     ) -> Task<(
         ViewHandle<Workspace>,
@@ -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<WorkspaceLocation> {
 pub fn open_paths(
     abs_paths: &[PathBuf],
     app_state: &Arc<AppState>,
-    requesting_window_id: Option<usize>,
     cx: &mut AppContext,
 ) -> Task<(
     ViewHandle<Workspace>,
@@ -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<Workspace>) + '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;
 

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;

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