From a0cfa0bdd08f17cac68dd6fc5bb056e2307ef23a Mon Sep 17 00:00:00 2001 From: kenoss Date: Mon, 20 May 2024 03:40:17 +0900 Subject: [PATCH] fix #6164: Reduce format failure for non default `imports_granularity` This patch reduces format failure for non default `imports_granularity` and correct the behavior around some edge cases. - Supports too long line of `use ...` that contains `{}`. - Fixes the width calculation of too long lines of `use ...`. --- src/imports.rs | 74 +++++++++++++-- src/shape.rs | 11 +++ tests/source/5131_crate.rs | 151 ++++++++++++++++++++++++++++++ tests/source/5131_module.rs | 179 ++++++++++++++++++++++++++++++++++++ tests/source/5131_one.rs | 150 ++++++++++++++++++++++++++++++ tests/target/5131_crate.rs | 128 ++++++++++++++++++++++++++ tests/target/5131_module.rs | 169 ++++++++++++++++++++++++++++++++++ tests/target/5131_one.rs | 128 ++++++++++++++++++++++++++ tests/target/issue_3033.rs | 14 ++- 9 files changed, 995 insertions(+), 9 deletions(-) diff --git a/src/imports.rs b/src/imports.rs index 05195553c08..38d91c37f85 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -1068,7 +1068,7 @@ impl Rewrite for UseSegment { context, use_tree_list, // 1 = "{" and "}" - shape.offset_left(1)?.sub_width(1)?, + shape.offset_left(1)?.saturating_sub_width(1), )?, }) } @@ -1077,15 +1077,75 @@ impl Rewrite for UseSegment { impl Rewrite for UseTree { // This does NOT format attributes and visibility or add a trailing `;`. fn rewrite(&self, context: &RewriteContext<'_>, mut shape: Shape) -> Option { + let shape_top_level = shape.clone(); let mut result = String::with_capacity(256); + let mut is_first = true; + let mut prev_is_allow_overflow = false; let mut iter = self.path.iter().peekable(); while let Some(segment) = iter.next() { - let segment_str = segment.rewrite(context, shape)?; - result.push_str(&segment_str); - if iter.peek().is_some() { - result.push_str("::"); - // 2 = "::" - shape = shape.offset_left(2 + segment_str.len())?; + // Try stacking the next segment, e.g. `use prev::next_segment::...` and + // `use prev::{next, segment}`. + let can_stack_with_constraint = (|| { + // If the segment follows `use ` or `{`, force to consume the segment with overflow. + if is_first { + let mut chunk = segment.rewrite(context, shape.infinite_width())?; + let next_shape = if iter.peek().is_some() { + chunk.push_str("::"); + shape.offset_left_maybe_overflow(chunk.len()) + } else { + shape.clone() + }; + Some((chunk, next_shape)) + } else { + // If the segment follows `use ` or newline, allow overflow by "{". + let s = if prev_is_allow_overflow + && matches!(segment.kind, UseSegmentKind::List(_)) + { + shape.add_width(1) + } else { + shape.clone() + }; + let mut chunk = segment.rewrite(context, s)?; + let next_shape = match iter.peek().map(|s| &s.kind) { + Some(UseSegmentKind::List(_)) => { + chunk.push_str("::"); + let ret = shape.offset_left(chunk.len())?; + // Ensure that there is a room for the next "{". + ret.offset_left(1)?; + ret + } + Some(_) => { + chunk.push_str("::"); + shape.offset_left(chunk.len())? + } + None => shape.clone(), + }; + Some((chunk, next_shape)) + } + })(); + match can_stack_with_constraint { + Some((chunk, next_shape)) => { + result.push_str(&chunk); + shape = next_shape; + prev_is_allow_overflow = is_first; + is_first = false; + } + // If the next segment exceeds the given width, continue with newline. + None => { + let segment_str = segment.rewrite(context, shape)?; + let mut chunk = format!( + "{}{}", + " ".repeat(shape.indent.block_indent + 4), + segment_str + ); + if iter.peek().is_some() { + chunk.push_str("::"); + } + result.push_str("\n"); + result.push_str(&chunk); + shape = shape_top_level.offset_left_maybe_overflow(segment_str.len()); + prev_is_allow_overflow = true; + } } } Some(result) diff --git a/src/shape.rs b/src/shape.rs index 4376fd12b52..dfb9086f729 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -242,6 +242,13 @@ impl Shape { }) } + pub(crate) fn add_width(&self, width: usize) -> Shape { + Shape { + width: self.width + width, + ..*self + } + } + pub(crate) fn shrink_left(&self, width: usize) -> Option { Some(Shape { width: self.width.checked_sub(width)?, @@ -254,6 +261,10 @@ impl Shape { self.add_offset(width).sub_width(width) } + pub(crate) fn offset_left_maybe_overflow(&self, width: usize) -> Shape { + self.add_offset(width).saturating_sub_width(width) + } + pub(crate) fn used_width(&self) -> usize { self.indent.block_indent + self.offset } diff --git a/tests/source/5131_crate.rs b/tests/source/5131_crate.rs index 96a31659022..73277c6cf88 100644 --- a/tests/source/5131_crate.rs +++ b/tests/source/5131_crate.rs @@ -12,3 +12,154 @@ use foo::d::e; use qux::h; use qux::h as h2; use qux::i; + + +mod indent4 { + use column_____________________________________________________________________________________102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_______________________________________________________________________________096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_________________________________________________________________________090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::c102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; +} + +use smithay::{ + backend::renderer::element::{ + default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, + }, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, + desktop::{ + space::SpaceElement, + utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, + }, + PopupKind, PopupManager, Space, + }, + input::{ + keyboard::{Keysym, LedState, XkbConfig}, + pointer::{CursorImageStatus, PointerHandle}, + Seat, SeatHandler, SeatState, + }, + output::Output, + reexports::{ + calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction}, + wayland_protocols::xdg::decoration::{ + self as xdg_decoration, + zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode, + }, + wayland_server::{ + backend::{ClientData, ClientId, DisconnectReason}, + protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, + Display, DisplayHandle, Resource, + }, + }, + utils::{Clock, Monotonic, Rectangle}, + wayland::{ + compositor::{get_parent, with_states, CompositorClientState, CompositorState}, + dmabuf::DmabufFeedback, + fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, + }, + input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, + keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, + KeyboardShortcutsInhibitor, + }, + output::{OutputHandler, OutputManagerState}, + pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, + }, + pointer_gestures::PointerGesturesState, + presentation::PresentationState, + relative_pointer::RelativePointerManagerState, + seat::WaylandFocus, + security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, + SecurityContextState, + }, + selection::data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, + }, + selection::{ + primary_selection::{ + set_primary_focus, PrimarySelectionHandler, PrimarySelectionState, + }, + wlr_data_control::{DataControlHandler, DataControlState}, + SelectionHandler, + }, + shell::{ + wlr_layer::WlrLayerShellState, + xdg::{ + decoration::{XdgDecorationHandler, XdgDecorationState}, + ToplevelSurface, XdgShellState, XdgToplevelSurfaceData, + }, + }, + shm::{ShmHandler, ShmState}, + socket::ListeningSocketSource, + tablet_manager::{TabletManagerState, TabletSeatTrait}, + text_input::TextInputManagerState, + viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, + xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, + }, + xdg_foreign::{XdgForeignHandler, XdgForeignState}, + }, +}; diff --git a/tests/source/5131_module.rs b/tests/source/5131_module.rs index 3e9139177c5..bda6f458dc0 100644 --- a/tests/source/5131_module.rs +++ b/tests/source/5131_module.rs @@ -31,3 +31,182 @@ mod a { } } } + +mod indent4 { + use column_____________________________________________________________________________________102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_______________________________________________________________________________096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_________________________________________________________________________090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::c102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + // Check that the behavior when "{" exceeds the max column. + // + // Note that `shape.offset_left(4)?.sub_width(1)?;` in + // `rewrite_reorderable_or_regroupable_items()` replaces the max column 100 by 99. + + use x::column______________________________________________________________________________098::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use x::column__Only_the_last_one_wraps_due_to_brace_______________________________________097::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use x::column_____________________________________________________________________________096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; +} + +use smithay::{ + backend::renderer::element::{ + default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, + }, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, + desktop::{ + space::SpaceElement, + utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, + }, + PopupKind, PopupManager, Space, + }, + input::{ + keyboard::{Keysym, LedState, XkbConfig}, + pointer::{CursorImageStatus, PointerHandle}, + Seat, SeatHandler, SeatState, + }, + output::Output, + reexports::{ + calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction}, + wayland_protocols::xdg::decoration::{ + self as xdg_decoration, + zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode, + }, + wayland_server::{ + backend::{ClientData, ClientId, DisconnectReason}, + protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, + Display, DisplayHandle, Resource, + }, + }, + utils::{Clock, Monotonic, Rectangle}, + wayland::{ + compositor::{get_parent, with_states, CompositorClientState, CompositorState}, + dmabuf::DmabufFeedback, + fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, + }, + input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, + keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, + KeyboardShortcutsInhibitor, + }, + output::{OutputHandler, OutputManagerState}, + pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, + }, + pointer_gestures::PointerGesturesState, + presentation::PresentationState, + relative_pointer::RelativePointerManagerState, + seat::WaylandFocus, + security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, + SecurityContextState, + }, + selection::data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, + }, + selection::{ + primary_selection::{ + set_primary_focus, PrimarySelectionHandler, PrimarySelectionState, + }, + wlr_data_control::{DataControlHandler, DataControlState}, + SelectionHandler, + }, + shell::{ + wlr_layer::WlrLayerShellState, + xdg::{ + decoration::{XdgDecorationHandler, XdgDecorationState}, + ToplevelSurface, XdgShellState, XdgToplevelSurfaceData, + }, + }, + shm::{ShmHandler, ShmState}, + socket::ListeningSocketSource, + tablet_manager::{TabletManagerState, TabletSeatTrait}, + text_input::TextInputManagerState, + viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, + xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, + }, + xdg_foreign::{XdgForeignHandler, XdgForeignState}, + }, +}; diff --git a/tests/source/5131_one.rs b/tests/source/5131_one.rs index 61ddf13410d..18825fb7fdb 100644 --- a/tests/source/5131_one.rs +++ b/tests/source/5131_one.rs @@ -13,3 +13,153 @@ use bar::d::e; use bar::d::e as e2; use qux::h; use qux::i; + +mod indent4 { + use column_____________________________________________________________________________________102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_______________________________________________________________________________096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use column_________________________________________________________________________090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::c102::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{ + Foo, + bar::Bar, + bar::baz::Baz, + Foo2, + bar::Bar2, + }; +} + +use smithay::{ + backend::renderer::element::{ + default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, + }, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, + desktop::{ + space::SpaceElement, + utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, + }, + PopupKind, PopupManager, Space, + }, + input::{ + keyboard::{Keysym, LedState, XkbConfig}, + pointer::{CursorImageStatus, PointerHandle}, + Seat, SeatHandler, SeatState, + }, + output::Output, + reexports::{ + calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction}, + wayland_protocols::xdg::decoration::{ + self as xdg_decoration, + zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode, + }, + wayland_server::{ + backend::{ClientData, ClientId, DisconnectReason}, + protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, + Display, DisplayHandle, Resource, + }, + }, + utils::{Clock, Monotonic, Rectangle}, + wayland::{ + compositor::{get_parent, with_states, CompositorClientState, CompositorState}, + dmabuf::DmabufFeedback, + fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, + }, + input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, + keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, + KeyboardShortcutsInhibitor, + }, + output::{OutputHandler, OutputManagerState}, + pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, + }, + pointer_gestures::PointerGesturesState, + presentation::PresentationState, + relative_pointer::RelativePointerManagerState, + seat::WaylandFocus, + security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, + SecurityContextState, + }, + selection::data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, + }, + selection::{ + primary_selection::{ + set_primary_focus, PrimarySelectionHandler, PrimarySelectionState, + }, + wlr_data_control::{DataControlHandler, DataControlState}, + SelectionHandler, + }, + shell::{ + wlr_layer::WlrLayerShellState, + xdg::{ + decoration::{XdgDecorationHandler, XdgDecorationState}, + ToplevelSurface, XdgShellState, XdgToplevelSurfaceData, + }, + }, + shm::{ShmHandler, ShmState}, + socket::ListeningSocketSource, + tablet_manager::{TabletManagerState, TabletSeatTrait}, + text_input::TextInputManagerState, + viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, + xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, + }, + xdg_foreign::{XdgForeignHandler, XdgForeignState}, + }, +}; diff --git a/tests/target/5131_crate.rs b/tests/target/5131_crate.rs index 557d6670355..625865137f9 100644 --- a/tests/target/5131_crate.rs +++ b/tests/target/5131_crate.rs @@ -7,3 +7,131 @@ use foo::{ d::e, }; use qux::{h, h as h2, i}; + +mod indent4 { + use column_____________________________________________________________________________________102::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use column_______________________________________________________________________________096::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use column_________________________________________________________________________090::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c102::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; +} + +use smithay::{ + backend::renderer::element::{ + default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, + }, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, + desktop::{ + space::SpaceElement, + utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, + }, + PopupKind, PopupManager, Space, + }, + input::{ + keyboard::{Keysym, LedState, XkbConfig}, + pointer::{CursorImageStatus, PointerHandle}, + Seat, SeatHandler, SeatState, + }, + output::Output, + reexports::{ + calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction}, + wayland_protocols::xdg::decoration::{ + self as xdg_decoration, + zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode, + }, + wayland_server::{ + backend::{ClientData, ClientId, DisconnectReason}, + protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, + Display, DisplayHandle, Resource, + }, + }, + utils::{Clock, Monotonic, Rectangle}, + wayland::{ + compositor::{get_parent, with_states, CompositorClientState, CompositorState}, + dmabuf::DmabufFeedback, + fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, + }, + input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, + keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, + KeyboardShortcutsInhibitor, + }, + output::{OutputHandler, OutputManagerState}, + pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, + }, + pointer_gestures::PointerGesturesState, + presentation::PresentationState, + relative_pointer::RelativePointerManagerState, + seat::WaylandFocus, + security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, + SecurityContextState, + }, + selection::{ + data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, + }, + primary_selection::{set_primary_focus, PrimarySelectionHandler, PrimarySelectionState}, + wlr_data_control::{DataControlHandler, DataControlState}, + SelectionHandler, + }, + shell::{ + wlr_layer::WlrLayerShellState, + xdg::{ + decoration::{XdgDecorationHandler, XdgDecorationState}, + ToplevelSurface, XdgShellState, XdgToplevelSurfaceData, + }, + }, + shm::{ShmHandler, ShmState}, + socket::ListeningSocketSource, + tablet_manager::{TabletManagerState, TabletSeatTrait}, + text_input::TextInputManagerState, + viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, + xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, + }, + xdg_foreign::{XdgForeignHandler, XdgForeignState}, + }, +}; diff --git a/tests/target/5131_module.rs b/tests/target/5131_module.rs index 763024d6fa4..ba480deb15f 100644 --- a/tests/target/5131_module.rs +++ b/tests/target/5131_module.rs @@ -30,3 +30,172 @@ mod a { } } } + +mod indent4 { + use column_____________________________________________________________________________________102:: + bar::baz::Baz; + use column_____________________________________________________________________________________102:: + bar::{Bar, Bar2}; + use column_____________________________________________________________________________________102::{ + Foo, Foo2, + }; + + use column_______________________________________________________________________________096:: + bar::baz::Baz; + use column_______________________________________________________________________________096:: + bar::{Bar, Bar2}; + use column_______________________________________________________________________________096::{ + Foo, Foo2, + }; + + use column_________________________________________________________________________090::bar:: + baz::Baz; + use column_________________________________________________________________________090::bar::{ + Bar, Bar2, + }; + use column_________________________________________________________________________090::{ + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c102::bar::baz::Baz; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c102::bar::{Bar, Bar2}; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c102::{Foo, Foo2}; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + bar::baz::Baz; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + bar::{Bar, Bar2}; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::bar:: + baz::Baz; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::bar::{ + Bar, Bar2, + }; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::bar::baz::Baz; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::bar::{ + Bar, Bar2, + }; + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{Foo, Foo2}; + + // Check that the behavior when "{" exceeds the max column. + // + // Note that `shape.offset_left(4)?.sub_width(1)?;` in + // `rewrite_reorderable_or_regroupable_items()` replaces the max column 100 by 99. + + use x:: + column______________________________________________________________________________098:: + bar::baz::Baz; + use x:: + column______________________________________________________________________________098:: + bar::{Bar, Bar2}; + use x:: + column______________________________________________________________________________098::{ + Foo, Foo2, + }; + + use x::column__Only_the_last_one_wraps_due_to_brace_______________________________________097:: + bar::baz::Baz; + use x::column__Only_the_last_one_wraps_due_to_brace_______________________________________097:: + bar::{Bar, Bar2}; + use x:: + column__Only_the_last_one_wraps_due_to_brace_______________________________________097::{ + Foo, Foo2, + }; + + use x::column_____________________________________________________________________________096:: + bar::baz::Baz; + use x::column_____________________________________________________________________________096:: + bar::{Bar, Bar2}; + use x:: + column_____________________________________________________________________________096::{ + Foo, Foo2, + }; +} + +use smithay::backend::renderer::element::utils::select_dmabuf_feedback; +use smithay::backend::renderer::element::{ + default_primary_scanout_output_compare, RenderElementStates, +}; +use smithay::desktop::space::SpaceElement; +use smithay::desktop::utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, +}; +use smithay::desktop::{PopupKind, PopupManager, Space}; +use smithay::input::keyboard::{Keysym, LedState, XkbConfig}; +use smithay::input::pointer::{CursorImageStatus, PointerHandle}; +use smithay::input::{Seat, SeatHandler, SeatState}; +use smithay::output::Output; +use smithay::reexports::calloop::generic::Generic; +use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction}; +use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server:: + zxdg_toplevel_decoration_v1::Mode as DecorationMode; +use smithay::reexports::wayland_protocols::xdg::decoration::{self as xdg_decoration}; +use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason}; +use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; +use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; +use smithay::reexports::wayland_server::{Display, DisplayHandle, Resource}; +use smithay::utils::{Clock, Monotonic, Rectangle}; +use smithay::wayland::compositor::{ + get_parent, with_states, CompositorClientState, CompositorState, +}; +use smithay::wayland::dmabuf::DmabufFeedback; +use smithay::wayland::fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, +}; +use smithay::wayland::input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}; +use smithay::wayland::keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, KeyboardShortcutsInhibitor, +}; +use smithay::wayland::output::{OutputHandler, OutputManagerState}; +use smithay::wayland::pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, +}; +use smithay::wayland::pointer_gestures::PointerGesturesState; +use smithay::wayland::presentation::PresentationState; +use smithay::wayland::relative_pointer::RelativePointerManagerState; +use smithay::wayland::seat::WaylandFocus; +use smithay::wayland::security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, SecurityContextState, +}; +use smithay::wayland::selection::data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, +}; +use smithay::wayland::selection::primary_selection::{ + set_primary_focus, PrimarySelectionHandler, PrimarySelectionState, +}; +use smithay::wayland::selection::wlr_data_control::{DataControlHandler, DataControlState}; +use smithay::wayland::selection::SelectionHandler; +use smithay::wayland::shell::wlr_layer::WlrLayerShellState; +use smithay::wayland::shell::xdg::decoration::{XdgDecorationHandler, XdgDecorationState}; +use smithay::wayland::shell::xdg::{ToplevelSurface, XdgShellState, XdgToplevelSurfaceData}; +use smithay::wayland::shm::{ShmHandler, ShmState}; +use smithay::wayland::socket::ListeningSocketSource; +use smithay::wayland::tablet_manager::{TabletManagerState, TabletSeatTrait}; +use smithay::wayland::text_input::TextInputManagerState; +use smithay::wayland::viewporter::ViewporterState; +use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; +use smithay::wayland::xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, +}; +use smithay::wayland::xdg_foreign::{XdgForeignHandler, XdgForeignState}; +use smithay::{ + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, +}; diff --git a/tests/target/5131_one.rs b/tests/target/5131_one.rs index a086dae5a42..3fc122b300b 100644 --- a/tests/target/5131_one.rs +++ b/tests/target/5131_one.rs @@ -10,3 +10,131 @@ use { }, qux::{h, i}, }; + +mod indent4 { + use column_____________________________________________________________________________________102::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use column_______________________________________________________________________________096::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use column_________________________________________________________________________090::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c102::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; + + use c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::{ + bar::{baz::Baz, Bar, Bar2}, + Foo, Foo2, + }; +} + +use smithay::{ + backend::renderer::element::{ + default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, + }, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, + delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, + delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, + desktop::{ + space::SpaceElement, + utils::{ + surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, + update_surface_primary_scanout_output, OutputPresentationFeedback, + }, + PopupKind, PopupManager, Space, + }, + input::{ + keyboard::{Keysym, LedState, XkbConfig}, + pointer::{CursorImageStatus, PointerHandle}, + Seat, SeatHandler, SeatState, + }, + output::Output, + reexports::{ + calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction}, + wayland_protocols::xdg::decoration::{ + self as xdg_decoration, + zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode, + }, + wayland_server::{ + backend::{ClientData, ClientId, DisconnectReason}, + protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, + Display, DisplayHandle, Resource, + }, + }, + utils::{Clock, Monotonic, Rectangle}, + wayland::{ + compositor::{get_parent, with_states, CompositorClientState, CompositorState}, + dmabuf::DmabufFeedback, + fractional_scale::{ + with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState, + }, + input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, + keyboard_shortcuts_inhibit::{ + KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, + KeyboardShortcutsInhibitor, + }, + output::{OutputHandler, OutputManagerState}, + pointer_constraints::{ + with_pointer_constraint, PointerConstraintsHandler, PointerConstraintsState, + }, + pointer_gestures::PointerGesturesState, + presentation::PresentationState, + relative_pointer::RelativePointerManagerState, + seat::WaylandFocus, + security_context::{ + SecurityContext, SecurityContextHandler, SecurityContextListenerSource, + SecurityContextState, + }, + selection::{ + data_device::{ + set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, + ServerDndGrabHandler, + }, + primary_selection::{set_primary_focus, PrimarySelectionHandler, PrimarySelectionState}, + wlr_data_control::{DataControlHandler, DataControlState}, + SelectionHandler, + }, + shell::{ + wlr_layer::WlrLayerShellState, + xdg::{ + decoration::{XdgDecorationHandler, XdgDecorationState}, + ToplevelSurface, XdgShellState, XdgToplevelSurfaceData, + }, + }, + shm::{ShmHandler, ShmState}, + socket::ListeningSocketSource, + tablet_manager::{TabletManagerState, TabletSeatTrait}, + text_input::TextInputManagerState, + viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, + xdg_activation::{ + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, + }, + xdg_foreign::{XdgForeignHandler, XdgForeignState}, + }, +}; diff --git a/tests/target/issue_3033.rs b/tests/target/issue_3033.rs index e12249a6da6..92cc89201ed 100644 --- a/tests/target/issue_3033.rs +++ b/tests/target/issue_3033.rs @@ -1,2 +1,12 @@ -use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerBinding:: - BluetoothRemoteGATTServerMethods; +use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding:: + BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods; + +mod indent4 { + use column__This_segment_overflows_because_it_follows_use______________________________________102:: + column__This_segment_overflows_because_it_follows_newline__________________________________102:: + c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c012:: + column__This_segment_wraps_because_it_exceeds_100_and_follows_the_previous_segment___102:: + c012::c018::c024::c030::c036::c042::c048::c054::c060::c066::c072::c078::c084::c090::c096:: + c012::column__This_segment_doesnt_wrap_because_it_doesnt_exceed_100__________________096::Foo; +}