Skip to content

Commit

Permalink
Enable all warnings in workspace, fix all warnings (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld authored Dec 14, 2023
2 parents 4e7005b + 6170895 commit fcbd58f
Show file tree
Hide file tree
Showing 10 changed files with 502 additions and 1,125 deletions.
15 changes: 15 additions & 0 deletions crates/gpui2/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
use anyhow::{Context, Result};
use std::{
any::TypeId,
fmt,
hash::{Hash, Hasher},
};

Expand Down Expand Up @@ -297,6 +298,20 @@ impl<V: 'static + Render> From<WeakView<V>> for AnyWeakView {
}
}

impl PartialEq for AnyWeakView {
fn eq(&self, other: &Self) -> bool {
self.model == other.model
}
}

impl std::fmt::Debug for AnyWeakView {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AnyWeakView")
.field("entity_id", &self.model.entity_id)
.finish_non_exhaustive()
}
}

impl<T, E> Render for T
where
T: 'static + FnMut(&mut WindowContext) -> E,
Expand Down
179 changes: 12 additions & 167 deletions crates/workspace2/src/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
}

pub trait PanelHandle: Send + Sync {
fn entity_id(&self) -> EntityId;
fn panel_id(&self) -> EntityId;
fn persistent_name(&self) -> &'static str;
fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
Expand All @@ -62,7 +62,7 @@ impl<T> PanelHandle for View<T>
where
T: Panel,
{
fn entity_id(&self) -> EntityId {
fn panel_id(&self) -> EntityId {
Entity::entity_id(self)
}

Expand Down Expand Up @@ -135,7 +135,7 @@ pub struct Dock {
is_open: bool,
active_panel_index: usize,
focus_handle: FocusHandle,
focus_subscription: Subscription,
_focus_subscription: Subscription,
}

impl FocusableView for Dock {
Expand Down Expand Up @@ -187,7 +187,6 @@ struct PanelEntry {

pub struct PanelButtons {
dock: View<Dock>,
workspace: WeakView<Workspace>,
}

impl Dock {
Expand All @@ -204,7 +203,7 @@ impl Dock {
active_panel_index: 0,
is_open: false,
focus_handle,
focus_subscription,
_focus_subscription: focus_subscription,
}
}

Expand Down Expand Up @@ -261,7 +260,7 @@ impl Dock {

pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
for entry in &mut self.panel_entries {
if entry.panel.entity_id() == panel.entity_id() {
if entry.panel.panel_id() == panel.entity_id() {
if zoomed != entry.panel.is_zoomed(cx) {
entry.panel.set_zoomed(zoomed, cx);
}
Expand Down Expand Up @@ -309,7 +308,7 @@ impl Dock {

let was_visible = this.is_open()
&& this.visible_panel().map_or(false, |active_panel| {
active_panel.entity_id() == Entity::entity_id(&panel)
active_panel.panel_id() == Entity::entity_id(&panel)
});

this.remove_panel(&panel, cx);
Expand Down Expand Up @@ -351,7 +350,7 @@ impl Dock {
if let Some(ix) = this
.panel_entries
.iter()
.position(|entry| entry.panel.entity_id() == Entity::entity_id(&panel))
.position(|entry| entry.panel.panel_id() == Entity::entity_id(&panel))
{
this.set_open(true, cx);
this.activate_panel(ix, cx);
Expand All @@ -361,7 +360,7 @@ impl Dock {
PanelEvent::Close => {
if this
.visible_panel()
.map_or(false, |p| p.entity_id() == Entity::entity_id(&panel))
.map_or(false, |p| p.panel_id() == Entity::entity_id(&panel))
{
this.set_open(false, cx);
}
Expand Down Expand Up @@ -389,7 +388,7 @@ impl Dock {
if let Some(panel_ix) = self
.panel_entries
.iter()
.position(|entry| entry.panel.entity_id() == Entity::entity_id(panel))
.position(|entry| entry.panel.panel_id() == Entity::entity_id(panel))
{
if panel_ix == self.active_panel_index {
self.active_panel_index = 0;
Expand Down Expand Up @@ -450,7 +449,7 @@ impl Dock {
pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<f32> {
self.panel_entries
.iter()
.find(|entry| entry.panel.entity_id() == panel.entity_id())
.find(|entry| entry.panel.panel_id() == panel.panel_id())
.map(|entry| entry.panel.size(cx))
}

Expand Down Expand Up @@ -549,166 +548,12 @@ impl Render for Dock {
}

impl PanelButtons {
pub fn new(
dock: View<Dock>,
workspace: WeakView<Workspace>,
cx: &mut ViewContext<Self>,
) -> Self {
pub fn new(dock: View<Dock>, cx: &mut ViewContext<Self>) -> Self {
cx.observe(&dock, |_, _, cx| cx.notify()).detach();
Self { dock, workspace }
Self { dock }
}
}

// impl Render for PanelButtons {
// type Element = ();

// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
// todo!("")
// }

// fn ui_name() -> &'static str {
// "PanelButtons"
// }

// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// let theme = &settings::get::<ThemeSettings>(cx).theme;
// let tooltip_style = theme.tooltip.clone();
// let theme = &theme.workspace.status_bar.panel_buttons;
// let button_style = theme.button.clone();
// let dock = self.dock.read(cx);
// let active_ix = dock.active_panel_index;
// let is_open = dock.is_open;
// let dock_position = dock.position;
// let group_style = match dock_position {
// DockPosition::Left => theme.group_left,
// DockPosition::Bottom => theme.group_bottom,
// DockPosition::Right => theme.group_right,
// };
// let menu_corner = match dock_position {
// DockPosition::Left => AnchorCorner::BottomLeft,
// DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,
// };

// let panels = dock
// .panel_entries
// .iter()
// .map(|item| (item.panel.clone(), item.context_menu.clone()))
// .collect::<Vec<_>>();
// Flex::row()
// .with_children(panels.into_iter().enumerate().filter_map(
// |(panel_ix, (view, context_menu))| {
// let icon_path = view.icon_path(cx)?;
// let is_active = is_open && panel_ix == active_ix;
// let (tooltip, tooltip_action) = if is_active {
// (
// format!("Close {} dock", dock_position.to_label()),
// Some(match dock_position {
// DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
// DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),
// DockPosition::Right => crate::ToggleRightDock.boxed_clone(),
// }),
// )
// } else {
// view.icon_tooltip(cx)
// };
// Some(
// Stack::new()
// .with_child(
// MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| {
// let style = button_style.in_state(is_active);

// let style = style.style_for(state);
// Flex::row()
// .with_child(
// Svg::new(icon_path)
// .with_color(style.icon_color)
// .constrained()
// .with_width(style.icon_size)
// .aligned(),
// )
// .with_children(if let Some(label) = view.icon_label(cx) {
// Some(
// Label::new(label, style.label.text.clone())
// .contained()
// .with_style(style.label.container)
// .aligned(),
// )
// } else {
// None
// })
// .constrained()
// .with_height(style.icon_size)
// .contained()
// .with_style(style.container)
// })
// .with_cursor_style(CursorStyle::PointingHand)
// .on_click(MouseButton::Left, {
// let tooltip_action =
// tooltip_action.as_ref().map(|action| action.boxed_clone());
// move |_, this, cx| {
// if let Some(tooltip_action) = &tooltip_action {
// let window = cx.window();
// let view_id = this.workspace.id();
// let tooltip_action = tooltip_action.boxed_clone();
// cx.spawn(|_, mut cx| async move {
// window.dispatch_action(
// view_id,
// &*tooltip_action,
// &mut cx,
// );
// })
// .detach();
// }
// }
// })
// .on_click(MouseButton::Right, {
// let view = view.clone();
// let menu = context_menu.clone();
// move |_, _, cx| {
// const POSITIONS: [DockPosition; 3] = [
// DockPosition::Left,
// DockPosition::Right,
// DockPosition::Bottom,
// ];

// menu.update(cx, |menu, cx| {
// let items = POSITIONS
// .into_iter()
// .filter(|position| {
// *position != dock_position
// && view.position_is_valid(*position, cx)
// })
// .map(|position| {
// let view = view.clone();
// ContextMenuItem::handler(
// format!("Dock {}", position.to_label()),
// move |cx| view.set_position(position, cx),
// )
// })
// .collect();
// menu.show(Default::default(), menu_corner, items, cx);
// })
// }
// })
// .with_tooltip::<Self>(
// panel_ix,
// tooltip,
// tooltip_action,
// tooltip_style.clone(),
// cx,
// ),
// )
// .with_child(ChildView::new(&context_menu, cx)),
// )
// },
// ))
// .contained()
// .with_style(group_style)
// .into_any()
// }
// }

// here be kittens
impl Render for PanelButtons {
type Element = Div;

Expand Down
6 changes: 3 additions & 3 deletions crates/workspace2/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ pub mod test {
impl EventEmitter<ItemEvent> for TestItem {}

impl FocusableView for TestItem {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
Expand All @@ -941,8 +941,8 @@ pub mod test {
fn tab_content(
&self,
detail: Option<usize>,
selected: bool,
cx: &ui::prelude::WindowContext,
_selected: bool,
_cx: &ui::prelude::WindowContext,
) -> AnyElement {
self.tab_detail.set(detail);
gpui::div().into_any_element()
Expand Down
6 changes: 3 additions & 3 deletions crates/workspace2/src/modal_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gpui::{
use ui::{h_stack, v_stack};

pub trait ModalView: ManagedView {
fn on_before_dismiss(&mut self, cx: &mut ViewContext<Self>) -> bool {
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> bool {
true
}
}
Expand All @@ -27,7 +27,7 @@ impl<V: ModalView> ModalViewHandle for View<V> {

pub struct ActiveModal {
modal: Box<dyn ModalViewHandle>,
subscription: Subscription,
_subscription: Subscription,
previous_focus_handle: Option<FocusHandle>,
focus_handle: FocusHandle,
}
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ModalLayer {
{
self.active_modal = Some(ActiveModal {
modal: Box::new(new_modal.clone()),
subscription: cx.subscribe(&new_modal, |this, modal, _: &DismissEvent, cx| {
_subscription: cx.subscribe(&new_modal, |this, _, _: &DismissEvent, cx| {
this.hide_modal(cx);
}),
previous_focus_handle: cx.focused(),
Expand Down
Loading

0 comments on commit fcbd58f

Please sign in to comment.