diff options
| author | pml68 <contact@pml68.dev> | 2025-01-07 00:26:21 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-01-07 00:26:21 +0100 |
| commit | 98329311ad068a9e0e3c8d7c78b95e794671ac5e (patch) | |
| tree | f56fb4996ef5fe6f880b0d3b51cff6aa1135358d | |
| parent | feat: make Highlighter generic over any T that is text_editor::Catalog (diff) | |
| download | iced_custom_highlighter-98329311ad068a9e0e3c8d7c78b95e794671ac5e.tar.gz | |
chore: remove once_cell dep, disable default features for syntect
| -rw-r--r-- | Cargo.toml | 26 | ||||
| -rw-r--r-- | src/lib.rs | 26 |
2 files changed, 36 insertions, 16 deletions
@@ -12,9 +12,31 @@ rust-version = "1.80" [dependencies] iced_widget = "0.13.4" -once_cell = "1.0" -syntect = "5.1" +syntect = { version = "5.1", default-features = false, features = ["default-syntaxes", "regex-onig"] } [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] all-features = true + +[lints.rust] +missing_debug_implementations = "deny" +unsafe_code = "deny" +unused_results = "deny" + +[lints.clippy] +type-complexity = "allow" +semicolon_if_nothing_returned = "deny" +trivially-copy-pass-by-ref = "deny" +default_trait_access = "deny" +match-wildcard-for-single-variants = "deny" +redundant-closure-for-method-calls = "deny" +filter_map_next = "deny" +manual_let_else = "deny" +unused_async = "deny" +from_over_into = "deny" +needless_borrow = "deny" +new_without_default = "deny" +useless_conversion = "deny" + +[lints.rustdoc] +broken_intra_doc_links = "forbid" @@ -6,15 +6,15 @@ use iced_widget::core::text::highlighter::{self, Format}; use iced_widget::text_editor::Catalog; use iced_widget::Theme; -use once_cell::sync::Lazy; use std::collections::HashSet; use std::ops::Range; use std::str::FromStr; +use std::sync::LazyLock; use syntect::highlighting; use syntect::parsing; -static SYNTAXES: Lazy<parsing::SyntaxSet> = - Lazy::new(parsing::SyntaxSet::load_defaults_nonewlines); +static SYNTAXES: LazyLock<parsing::SyntaxSet> = + LazyLock::new(parsing::SyntaxSet::load_defaults_nonewlines); const LINES_PER_SNAPSHOT: usize = 50; @@ -50,7 +50,7 @@ impl<T: Catalog + 'static + Clone + PartialEq> highlighter::Highlighter .find_syntax_by_token(&settings.token) .unwrap_or_else(|| SYNTAXES.find_syntax_plain_text()); - let style = settings.style.clone(); + let style = settings.style; let custom_scopes = settings.custom_scopes.clone(); let parser = parsing::ParseState::new(syntax); @@ -72,7 +72,7 @@ impl<T: Catalog + 'static + Clone + PartialEq> highlighter::Highlighter self.custom_scopes = new_settings.custom_scopes.clone(); - self.style = new_settings.style.clone(); + self.style = new_settings.style; // Restart the highlighter self.change_line(0); @@ -138,7 +138,7 @@ impl<T: Catalog + 'static + Clone + PartialEq> highlighter::Highlighter stack.clone(), custom_scopes.clone(), ), - style: style.clone(), + style: *style, }, )) } @@ -403,7 +403,7 @@ impl Scope { Self::Parantheses => "meta.brace.round, punctuation.definition.parameters.begin, punctuation.definition.parameters.end", Self::Braces => "meta.brace.curly", Self::Other => "", - Self::Custom {scope_string,..} => &scope_string + Self::Custom {scope_string,..} => scope_string } } @@ -411,16 +411,14 @@ impl Scope { stack: parsing::ScopeStack, custom_scopes: Vec<Self>, ) -> Self { - let scopes: Vec<Self>; - - if custom_scopes.len() > 0 { + let scopes = if !custom_scopes.is_empty() { let mut hashset: HashSet<Self> = - (*Self::ALL).to_vec().into_iter().collect(); + (*Self::ALL).iter().cloned().collect(); hashset.extend(custom_scopes); - scopes = hashset.into_iter().collect(); + hashset.into_iter().collect() } else { - scopes = Self::ALL.to_vec(); - } + Self::ALL.to_vec() + }; let selectors: Vec<(Self, highlighting::ScopeSelectors)> = scopes .iter() |
