Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed Jan 17, 2025
1 parent 7100aa4 commit 795ea0d
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 47 deletions.
20 changes: 8 additions & 12 deletions lapce-app/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub struct Doc {
/// (line, col)
pub completion_pos: RwSignal<(usize, usize)>,

/// Current inline completion text, if any.
/// Current inline completion text, if any.
/// This will be displayed even on views that are not focused.
pub inline_completion: RwSignal<Option<String>>,
/// (line, col)
Expand Down Expand Up @@ -641,7 +641,7 @@ impl Doc {
self.buffer.with_untracked(|b| b.rev())
}

/// Get the buffer's line-ending.
/// Get the buffer's line-ending.
/// Note: this may not be the same as what the actual line endings in the file are, rather this
/// is what the line-ending is set to (and what it will be saved as).
pub fn line_ending(&self) -> LineEnding {
Expand Down Expand Up @@ -705,8 +705,7 @@ impl Doc {
fn check_auto_save(&self) {
let config = self.common.config.get_untracked();
if config.editor.autosave_interval > 0 {
let Some(path) =
self.content.with_untracked(|c| c.path().map(|x| x.clone()))
let Some(path) = self.content.with_untracked(|c| c.path().cloned())
else {
return;
};
Expand Down Expand Up @@ -1272,12 +1271,13 @@ impl Doc {
.set(FindProgress::InProgress(Selection::new()));

let find_result = self.find_result.clone();
let find_rev_signal = self.common.find.rev.clone();
let triggered_by_changes = self.common.find.triggered_by_changes.clone();
let find_rev_signal = self.common.find.rev;
let triggered_by_changes = self.common.find.triggered_by_changes;

let path = self.content.get_untracked().path().map(|x| x.clone());
let path = self.content.get_untracked().path().cloned();
let common = self.common.clone();
let send = create_ext_action(self.scope, move |occurrences: Selection| {
#[allow(clippy::single_match)]
match (
occurrences.regions().is_empty(),
&path,
Expand Down Expand Up @@ -2099,11 +2099,7 @@ impl Styling for DocStyling {
&& end >= start_offset
&& diag.severity < Some(DiagnosticSeverity::HINT)
{
let start = if start > start_offset {
start - start_offset
} else {
0
};
let start = start.saturating_sub(start_offset);
let end = end - start_offset;
let start = phantom_text.col_after(start, true);
let end = phantom_text.col_after(end, false);
Expand Down
9 changes: 4 additions & 5 deletions lapce-app/src/editor/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,18 @@ impl FoldingRanges {
FoldingRangeStatus::Fold => {
folded.insert(
item.start.line,
FoldingDisplayItem::Folded(item.start.clone()),
FoldingDisplayItem::Folded(item.start),
);
limit_line = item.end.line;
}
FoldingRangeStatus::Unfold => {
unfold_start.insert(
item.start.line,
FoldingDisplayItem::UnfoldStart(item.start.clone()),
FoldingDisplayItem::UnfoldStart(item.start),
);
unfold_end.insert(
item.end.line,
FoldingDisplayItem::UnfoldEnd(item.end.clone()),
FoldingDisplayItem::UnfoldEnd(item.end),
);
limit_line = 0;
}
Expand All @@ -265,9 +265,8 @@ impl FoldingRanges {
for (key, val) in folded {
unfold_start.insert(key, val);
}
let items = unfold_start.into_iter().map(|x| x.1).collect();

items
unfold_start.into_iter().map(|x| x.1).collect()
}
}

Expand Down
4 changes: 2 additions & 2 deletions lapce-app/src/editor/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ fn editor_gutter_folding_range(
viewport: RwSignal<Rect>,
) -> impl View {
let config = window_tab_data.common.config;
let doc_clone = doc.clone();
let doc_clone = doc;
dyn_stack(
move || doc.get().folding_ranges.get().to_display_items(),
move |item| *item,
Expand All @@ -1738,7 +1738,7 @@ fn editor_gutter_folding_range(
item,
)
.on_click_stop({
let value = doc_clone.clone();
let value = doc_clone;
move |_| {
value.get_untracked().folding_ranges.update(|x| match item {
FoldingDisplayItem::UnfoldStart(pos)
Expand Down
7 changes: 2 additions & 5 deletions lapce-app/src/main_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Editors {
Self(cx.create_rw_signal(im::HashMap::new()))
}

/// Add an editor to the editors.
/// Add an editor to the editors.
/// Returns the id of the editor.
pub fn insert(&self, editor: EditorData) -> EditorId {
let id = editor.id();
Expand Down Expand Up @@ -2377,10 +2377,7 @@ impl MainSplitData {
if let Some(tab_id) = self.editor_tabs.with_untracked(|x| {
for (tab_id, tab_data) in x {
if tab_data.with_untracked(|x| {
x.children
.iter()
.find(|(_, _, child)| child.id() == id)
.is_some()
x.children.iter().any(|(_, _, child)| child.id() == id)
}) {
return Some(*tab_id);
}
Expand Down
5 changes: 2 additions & 3 deletions lapce-app/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ pub fn settings_view(
let search_editor = editors.make_local(cx, common);
let doc = search_editor.doc_signal();

let items = settings_data.items.clone();
let kinds = settings_data.kinds.clone();
let items = settings_data.items;
let kinds = settings_data.kinds;
let filtered_items_signal = settings_data.filtered_items;
create_effect(move |_| {
let doc = doc.get();
Expand Down Expand Up @@ -370,7 +370,6 @@ pub fn settings_view(
let scroll_pos = create_rw_signal(Point::ZERO);

let current_kind = {
let kinds = kinds.clone();
create_memo(move |_| {
let scroll_pos = scroll_pos.get();
let scroll_y = scroll_pos.y + 30.0;
Expand Down
2 changes: 1 addition & 1 deletion lapce-app/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn restart(path: &Path) -> Result<()> {
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
pub fn restart(path: &Path) -> Result<()> {
use std::os::unix::process::CommandExt;
std::process::Command::new(path).arg("-n").exec();
let _ = std::process::Command::new(path).arg("-n").exec();
Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion lapce-app/src/window_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ impl WindowTabData {
.installed
.get_untracked()
.values()
.into_iter()
.map(|x| {
let meta = x.meta.get_untracked();
(meta.name.clone(), meta)
Expand Down
2 changes: 1 addition & 1 deletion lapce-core/src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl LensBuilder {
}
}

impl<'a> Iterator for LensIter<'a> {
impl Iterator for LensIter<'_> {
type Item = (usize, usize);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
6 changes: 1 addition & 5 deletions lapce-core/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ pub fn line_styles(
if start > end_offset || end < start_offset {
None
} else {
let start = if start > start_offset {
start - start_offset
} else {
0
};
let start = start.saturating_sub(start_offset);
let end = end - start_offset;
let style = style.clone();
Some(LineStyle { start, end, style })
Expand Down
8 changes: 4 additions & 4 deletions lapce-core/src/syntax/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,13 @@ pub(crate) struct HighlightIterLayer<'a> {
pub(crate) depth: usize,
}

impl<'a> std::fmt::Debug for HighlightIterLayer<'a> {
impl std::fmt::Debug for HighlightIterLayer<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HighlightIterLayer").finish()
}
}

impl<'a> HighlightIterLayer<'a> {
impl HighlightIterLayer<'_> {
// First, sort scope boundaries by their byte offset in the document. At a
// given position, emit scope endings before scope beginnings. Finally, emit
// scope boundaries from deeper layers first.
Expand All @@ -426,7 +426,7 @@ impl<'a> HighlightIterLayer<'a> {
}
}

impl<'a> HighlightIter<'a> {
impl HighlightIter<'_> {
fn emit_event(
&mut self,
offset: usize,
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<'a> HighlightIter<'a> {
}
}

impl<'a> Iterator for HighlightIter<'a> {
impl Iterator for HighlightIter<'_> {
type Item = Result<HighlightEvent, super::Error>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion lapce-proxy/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,11 @@ impl FileWatchNotifier {
}

fn handle_open_file_fs_event(&self, event: notify::Event) {
const PREFIX: &str = r"\\?\";
if event.kind.is_modify() || event.kind.is_remove() {
for path in event.paths {
#[cfg(windows)]
if let Some(path_str) = path.to_str() {
const PREFIX: &str = r"\\?\";
if path_str.starts_with(PREFIX) {
let path = PathBuf::from(&path_str[PREFIX.len()..]);
self.proxy_rpc.notification(
Expand Down
14 changes: 7 additions & 7 deletions lapce-rpc/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Naming {
}

pub fn is_accepting_input(&self) -> bool {
self.state().map_or(false, NamingState::is_accepting_input)
self.state().is_some_and(NamingState::is_accepting_input)
}

pub fn editor_needs_reset(&self) -> bool {
Expand Down Expand Up @@ -264,13 +264,13 @@ pub struct FileNodeViewData {
pub struct FileNodeItem {
pub path: PathBuf,
pub is_dir: bool,
/// Whether the directory's children have been read.
/// Whether the directory's children have been read.
/// Does nothing if not a directory.
pub read: bool,
/// Whether the directory is open in the explorer view.
pub open: bool,
pub children: HashMap<PathBuf, FileNodeItem>,
/// The number of child (directories) that are open themselves
/// The number of child (directories) that are open themselves
/// Used for sizing of the explorer list
pub children_open_count: usize,
}
Expand Down Expand Up @@ -301,15 +301,15 @@ impl Ord for FileNodeItem {
}

impl FileNodeItem {
/// Collect the children, sorted by name.
/// Collect the children, sorted by name.
/// Note: this will be empty if the directory has not been read.
pub fn sorted_children(&self) -> Vec<&FileNodeItem> {
let mut children = self.children.values().collect::<Vec<&FileNodeItem>>();
children.sort();
children
}

/// Collect the children, sorted by name.
/// Collect the children, sorted by name.
/// Note: this will be empty if the directory has not been read.
pub fn sorted_children_mut(&mut self) -> Vec<&mut FileNodeItem> {
let mut children = self
Expand Down Expand Up @@ -369,7 +369,7 @@ impl FileNodeItem {
.try_fold(self, |node, path| node.children.get_mut(path))
}

/// Remove a specific child from the node.
/// Remove a specific child from the node.
/// The path is recursive and will remove the child from parent indicated by the path.
pub fn remove_child(&mut self, path: &Path) -> Option<FileNodeItem> {
let parent = path.parent()?;
Expand Down Expand Up @@ -404,7 +404,7 @@ impl FileNodeItem {
Some(())
}

/// Set the children of the node.
/// Set the children of the node.
/// Note: this opens the node.
pub fn set_item_children(
&mut self,
Expand Down

0 comments on commit 795ea0d

Please sign in to comment.