diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 55454ebc6..bdf0f405f 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::HashMap, iter}; +use std::{borrow::Cow, collections::HashMap}; use helix_stdx::rope::RopeSliceExt; use tree_house::TREE_SITTER_MATCH_LIMIT; @@ -214,7 +214,10 @@ fn whitespace_with_same_width(text: RopeSlice) -> String { if grapheme == "\t" { s.push('\t'); } else { - s.extend(std::iter::repeat(' ').take(grapheme_width(&Cow::from(grapheme)))); + s.extend(std::iter::repeat_n( + ' ', + grapheme_width(&Cow::from(grapheme)), + )); } } s @@ -243,10 +246,10 @@ pub fn normalize_indentation( original_len += 1; } if indent_style == IndentStyle::Tabs { - dst.extend(iter::repeat('\t').take(len / tab_width)); + dst.extend(std::iter::repeat_n('\t', len / tab_width)); len %= tab_width; } - dst.extend(iter::repeat(' ').take(len)); + dst.extend(std::iter::repeat_n(' ', len)); original_len } diff --git a/helix-core/src/snippets/elaborate.rs b/helix-core/src/snippets/elaborate.rs index 012d1db77..b17c149f6 100644 --- a/helix-core/src/snippets/elaborate.rs +++ b/helix-core/src/snippets/elaborate.rs @@ -361,7 +361,7 @@ impl Transform { } } FormatItem::Conditional(i, ref if_, ref else_) => { - if cap.get_group(i).map_or(true, |mat| mat.is_empty()) { + if cap.get_group(i).is_none_or(|mat| mat.is_empty()) { buf.push_str(else_) } else { buf.push_str(if_) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 1845686a4..325c47ac6 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -562,15 +562,15 @@ impl Syntax { self.inner.tree_for_byte_range(start, end) } - pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option { + pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option> { self.inner.named_descendant_for_byte_range(start, end) } - pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option { + pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option> { self.inner.descendant_for_byte_range(start, end) } - pub fn walk(&self) -> TreeCursor { + pub fn walk(&self) -> TreeCursor<'_> { self.inner.walk() } @@ -1073,7 +1073,7 @@ fn node_is_visible(node: &Node) -> bool { node.is_missing() || (node.is_named() && node.grammar().node_kind_is_visible(node.kind_id())) } -fn format_anonymous_node_kind(kind: &str) -> Cow { +fn format_anonymous_node_kind(kind: &str) -> Cow<'_, str> { if kind.contains('"') { Cow::Owned(kind.replace('"', "\\\"")) } else { @@ -1130,7 +1130,6 @@ fn pretty_print_tree_impl( } /// Finds the child of `node` which contains the given byte range. - pub fn child_for_byte_range<'a>(node: &Node<'a>, range: ops::Range) -> Option> { for child in node.children() { let child_range = child.byte_range(); diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 21b72b5f5..41faf8f7f 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -520,7 +520,7 @@ impl ChangeSet { pos } - pub fn changes_iter(&self) -> ChangeIterator { + pub fn changes_iter(&self) -> ChangeIterator<'_> { ChangeIterator::new(self) } } @@ -753,7 +753,7 @@ impl Transaction { }) } - pub fn changes_iter(&self) -> ChangeIterator { + pub fn changes_iter(&self) -> ChangeIterator<'_> { self.changes.changes_iter() } } diff --git a/helix-lsp-types/src/code_action.rs b/helix-lsp-types/src/code_action.rs index 6cc39e0d0..b46327e82 100644 --- a/helix-lsp-types/src/code_action.rs +++ b/helix-lsp-types/src/code_action.rs @@ -129,6 +129,7 @@ pub struct CodeActionParams { /// response for CodeActionRequest pub type CodeActionResponse = Vec; +#[allow(clippy::large_enum_variant)] // TODO: In a separate PR attempt the `Box` pattern. #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] #[serde(untagged)] pub enum CodeActionOrCommand { diff --git a/helix-lsp-types/src/progress.rs b/helix-lsp-types/src/progress.rs index 41fa74f9f..61552fdb1 100644 --- a/helix-lsp-types/src/progress.rs +++ b/helix-lsp-types/src/progress.rs @@ -40,14 +40,6 @@ pub struct WorkDoneProgressCancelParams { pub token: ProgressToken, } -/// Options to signal work done progress support in server capabilities. -#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)] -#[serde(rename_all = "camelCase")] -pub struct WorkDoneProgressOptions { - #[serde(skip_serializing_if = "Option::is_none")] - pub work_done_progress: Option, -} - /// An optional token that a server can use to report work done progress #[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] diff --git a/helix-stdx/src/env.rs b/helix-stdx/src/env.rs index 6f9a091e4..9e7781a0c 100644 --- a/helix-stdx/src/env.rs +++ b/helix-stdx/src/env.rs @@ -85,7 +85,7 @@ fn find_brace_end(src: &[u8]) -> Option { None } -fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option) -> Cow { +fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option) -> Cow<'_, OsStr> { use regex_automata::meta::Regex; static REGEX: Lazy = Lazy::new(|| { @@ -157,7 +157,7 @@ fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option) /// * `${:-}`, `${-}` /// * `${:=}`, `${=default}` /// -pub fn expand + ?Sized>(src: &S) -> Cow { +pub fn expand + ?Sized>(src: &S) -> Cow<'_, OsStr> { expand_impl(src.as_ref(), |var| std::env::var_os(var)) } diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 929774c79..0494db3e7 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -100,7 +100,7 @@ struct PickerDiagnostic { diag: lsp::Diagnostic, } -fn location_to_file_location(location: &Location) -> Option { +fn location_to_file_location(location: &Location) -> Option> { let path = location.uri.as_path()?; let line = Some(( location.range.start.line as usize, @@ -589,7 +589,7 @@ struct CodeActionOrCommandItem { impl ui::menu::Item for CodeActionOrCommandItem { type Data = (); - fn format(&self, _data: &Self::Data) -> Row { + fn format(&self, _data: &Self::Data) -> Row<'_> { match &self.lsp_item { lsp::CodeActionOrCommand::CodeAction(action) => action.title.as_str().into(), lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(), @@ -1146,7 +1146,7 @@ pub fn rename_symbol(cx: &mut Context) { let Some(language_server) = doc .language_servers_with_feature(LanguageServerFeature::RenameSymbol) - .find(|ls| language_server_id.map_or(true, |id| id == ls.id())) + .find(|ls| language_server_id.is_none_or(|id| id == ls.id())) else { cx.editor .set_error("No configured language server supports symbol renaming"); diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d26b47054..4831b9382 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -3740,7 +3740,7 @@ pub(super) fn command_mode(cx: &mut Context) { cx.push_layer(Box::new(prompt)); } -fn command_line_doc(input: &str) -> Option> { +fn command_line_doc(input: &str) -> Option> { let (command, _, _) = command_line::split(input); let command = TYPABLE_COMMAND_MAP.get(command)?; diff --git a/helix-term/src/handlers/completion/item.rs b/helix-term/src/handlers/completion/item.rs index 7a473b024..136d72db7 100644 --- a/helix-term/src/handlers/completion/item.rs +++ b/helix-term/src/handlers/completion/item.rs @@ -67,6 +67,7 @@ impl LspCompletionItem { } } +#[allow(clippy::large_enum_variant)] // TODO: In a separate PR attempt the `Box` pattern. #[derive(Debug, PartialEq, Clone)] pub enum CompletionItem { Lsp(LspCompletionItem), diff --git a/helix-term/src/handlers/completion/request.rs b/helix-term/src/handlers/completion/request.rs index 29cd8e42c..fd65cd4d8 100644 --- a/helix-term/src/handlers/completion/request.rs +++ b/helix-term/src/handlers/completion/request.rs @@ -87,7 +87,7 @@ impl helix_event::AsyncHook for CompletionHandler { if self .trigger .or(self.in_flight) - .map_or(true, |trigger| trigger.doc != doc || trigger.view != view) + .is_none_or(|trigger| trigger.doc != doc || trigger.view != view) { self.trigger = Some(Trigger { pos: trigger_pos, diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index e17762bfc..c0d3294fe 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,9 +1,9 @@ +use crate::handlers::completion::LspCompletionItem; use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent}; use crate::{ compositor::{Component, Context, Event, EventResult}, handlers::completion::{ - trigger_auto_completion, CompletionItem, CompletionResponse, LspCompletionItem, - ResolveHandler, + trigger_auto_completion, CompletionItem, CompletionResponse, ResolveHandler, }, }; use helix_core::snippets::{ActiveSnippet, RenderedSnippet, Snippet}; @@ -28,7 +28,7 @@ use std::cmp::Reverse; impl menu::Item for CompletionItem { type Data = Style; - fn format(&self, dir_style: &Self::Data) -> menu::Row { + fn format(&self, dir_style: &Self::Data) -> menu::Row<'_> { let deprecated = match self { CompletionItem::Lsp(LspCompletionItem { item, .. }) => { item.deprecated.unwrap_or_default() diff --git a/helix-term/src/ui/document.rs b/helix-term/src/ui/document.rs index 524d829c4..de85268a6 100644 --- a/helix-term/src/ui/document.rs +++ b/helix-term/src/ui/document.rs @@ -214,7 +214,7 @@ impl<'a> TextRenderer<'a> { let tab_width = doc.tab_width(); let tab = if ws_render.tab() == WhitespaceRenderValue::All { std::iter::once(ws_chars.tab) - .chain(std::iter::repeat(ws_chars.tabpad).take(tab_width - 1)) + .chain(std::iter::repeat_n(ws_chars.tabpad, tab_width - 1)) .collect() } else { " ".repeat(tab_width) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 76e50229a..41cf96ac0 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -13,7 +13,7 @@ pub trait Item: Sync + Send + 'static { /// Additional editor state that is used for label calculation. type Data: Sync + Send + 'static; - fn format(&self, data: &Self::Data) -> Row; + fn format(&self, data: &Self::Data) -> Row<'_>; } pub type MenuCallback = Box, MenuEvent)>; diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index c485fd88c..ee4a163d3 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -900,7 +900,7 @@ impl Picker { if let Some((preview, range)) = self.get_preview(cx.editor) { let doc = match preview.document() { Some(doc) - if range.map_or(true, |(start, end)| { + if range.is_none_or(|(start, end)| { start <= end && end <= doc.text().len_lines() }) => { diff --git a/helix-vcs/src/diff.rs b/helix-vcs/src/diff.rs index cc97ef851..d87f3ce70 100644 --- a/helix-vcs/src/diff.rs +++ b/helix-vcs/src/diff.rs @@ -72,7 +72,7 @@ impl DiffHandle { } /// Load the actual diff - pub fn load(&self) -> Diff { + pub fn load(&self) -> Diff<'_> { Diff { diff: self.diff.read(), inverted: self.inverted, diff --git a/helix-vcs/src/diff/line_cache.rs b/helix-vcs/src/diff/line_cache.rs index 4a03a8f5a..187ac5400 100644 --- a/helix-vcs/src/diff/line_cache.rs +++ b/helix-vcs/src/diff/line_cache.rs @@ -128,7 +128,7 @@ impl InternedRopeLines { /// Returns the `InternedInput` for performing the diff. /// If `diff_base` or `doc` is so large that performing a diff could slow the editor /// this function returns `None`. - pub fn interned_lines(&self) -> Option<&InternedInput> { + pub fn interned_lines(&self) -> Option<&InternedInput>> { if self.is_too_large() { None } else { diff --git a/helix-vcs/src/diff/worker.rs b/helix-vcs/src/diff/worker.rs index 3471b4cb3..0caab36f0 100644 --- a/helix-vcs/src/diff/worker.rs +++ b/helix-vcs/src/diff/worker.rs @@ -102,7 +102,7 @@ struct EventAccumulator { render_lock: Option, } -impl<'a> EventAccumulator { +impl EventAccumulator { fn new() -> EventAccumulator { EventAccumulator { diff_base: None, diff --git a/helix-view/src/annotations/diagnostics.rs b/helix-view/src/annotations/diagnostics.rs index be36cd010..dc1414625 100644 --- a/helix-view/src/annotations/diagnostics.rs +++ b/helix-view/src/annotations/diagnostics.rs @@ -186,7 +186,7 @@ impl<'a> InlineDiagnosticAccumulator<'a> { .doc .diagnostics .get(self.idx) - .map_or(true, |diag| diag.range.start != grapheme.char_idx) + .is_none_or(|diag| diag.range.start != grapheme.char_idx) { return false; } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 04b7703c5..1c2cbebc9 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1655,7 +1655,7 @@ impl Document { let savepoint_idx = self .savepoints .iter() - .position(|savepoint_ref| savepoint_ref.as_ptr() == savepoint as *const _) + .position(|savepoint_ref| std::ptr::eq(savepoint_ref.as_ptr(), savepoint)) .expect("Savepoint must belong to this document"); let savepoint_ref = self.savepoints.remove(savepoint_idx); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 766829204..7f8cff9c3 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1644,7 +1644,7 @@ impl Editor { doc.language_servers.iter().filter(|(name, doc_ls)| { language_servers .get(*name) - .map_or(true, |ls| ls.id() != doc_ls.id()) + .is_none_or(|ls| ls.id() != doc_ls.id()) }); for (_, language_server) in doc_language_servers_not_in_registry { @@ -1654,7 +1654,7 @@ impl Editor { let language_servers_not_in_doc = language_servers.iter().filter(|(name, ls)| { doc.language_servers .get(*name) - .map_or(true, |doc_ls| ls.id() != doc_ls.id()) + .is_none_or(|doc_ls| ls.id() != doc_ls.id()) }); for (_, language_server) in language_servers_not_in_doc { diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index c2cbc0da5..7506e5156 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -69,7 +69,7 @@ pub fn diagnostic<'doc>( .iter() .take_while(|d| { d.line == line - && d.provider.language_server_id().map_or(true, |id| { + && d.provider.language_server_id().is_none_or(|id| { doc.language_servers_with_feature(LanguageServerFeature::Diagnostics) .any(|ls| ls.id() == id) }) diff --git a/helix-view/src/handlers/lsp.rs b/helix-view/src/handlers/lsp.rs index c1041b2aa..e7ff9b62a 100644 --- a/helix-view/src/handlers/lsp.rs +++ b/helix-view/src/handlers/lsp.rs @@ -355,7 +355,7 @@ impl Editor { && diagnostic .source .as_ref() - .map_or(true, |source| !unchanged_diag_sources.contains(source)) + .is_none_or(|source| !unchanged_diag_sources.contains(source)) }; let diagnostics = Self::doc_diagnostics_with_filter( &self.language_servers, diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index aba947a21..d596b35a7 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -441,7 +441,7 @@ impl Tree { } } - pub fn traverse(&self) -> Traverse { + pub fn traverse(&self) -> Traverse<'_> { Traverse::new(self) }