Use built-in [lints] table in Cargo.toml
This commit is contained in:
parent
a865b38002
commit
5cd98f069d
32 changed files with 274 additions and 244 deletions
|
|
@ -10,6 +10,9 @@ homepage.workspace = true
|
|||
categories.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
iced_core.workspace = true
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//! A syntax highlighter for iced.
|
||||
use iced_core as core;
|
||||
|
||||
use crate::core::text::highlighter::{self, Format};
|
||||
|
|
@ -16,6 +17,8 @@ static THEMES: Lazy<highlighting::ThemeSet> =
|
|||
|
||||
const LINES_PER_SNAPSHOT: usize = 50;
|
||||
|
||||
/// A syntax highlighter.
|
||||
#[derive(Debug)]
|
||||
pub struct Highlighter {
|
||||
syntax: &'static parsing::SyntaxReference,
|
||||
highlighter: highlighting::Highlighter<'static>,
|
||||
|
|
@ -131,25 +134,47 @@ impl highlighter::Highlighter for Highlighter {
|
|||
}
|
||||
}
|
||||
|
||||
/// The settings of a [`Highlighter`].
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Settings {
|
||||
/// The [`Theme`] of the [`Highlighter`].
|
||||
///
|
||||
/// It dictates the color scheme that will be used for highlighting.
|
||||
pub theme: Theme,
|
||||
/// The extension of the file to highlight.
|
||||
///
|
||||
/// The [`Highlighter`] will use the extension to automatically determine
|
||||
/// the grammar to use for highlighting.
|
||||
pub extension: String,
|
||||
}
|
||||
|
||||
/// A highlight produced by a [`Highlighter`].
|
||||
#[derive(Debug)]
|
||||
pub struct Highlight(highlighting::StyleModifier);
|
||||
|
||||
impl Highlight {
|
||||
/// Returns the color of this [`Highlight`].
|
||||
///
|
||||
/// If `None`, the original text color should be unchanged.
|
||||
pub fn color(&self) -> Option<Color> {
|
||||
self.0.foreground.map(|color| {
|
||||
Color::from_rgba8(color.r, color.g, color.b, color.a as f32 / 255.0)
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the font of this [`Highlight`].
|
||||
///
|
||||
/// If `None`, the original font should be unchanged.
|
||||
pub fn font(&self) -> Option<Font> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the [`Format`] of the [`Highlight`].
|
||||
///
|
||||
/// It contains both the [`color`] and the [`font`].
|
||||
///
|
||||
/// [`color`]: Self::color
|
||||
/// [`font`]: Self::font
|
||||
pub fn to_format(&self) -> Format<Font> {
|
||||
Format {
|
||||
color: self.color(),
|
||||
|
|
@ -158,6 +183,8 @@ impl Highlight {
|
|||
}
|
||||
}
|
||||
|
||||
/// A highlighting theme.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Theme {
|
||||
SolarizedDark,
|
||||
|
|
@ -168,6 +195,7 @@ pub enum Theme {
|
|||
}
|
||||
|
||||
impl Theme {
|
||||
/// A static slice containing all the available themes.
|
||||
pub const ALL: &'static [Self] = &[
|
||||
Self::SolarizedDark,
|
||||
Self::Base16Mocha,
|
||||
|
|
@ -176,6 +204,7 @@ impl Theme {
|
|||
Self::InspiredGitHub,
|
||||
];
|
||||
|
||||
/// Returns `true` if the [`Theme`] is dark, and false otherwise.
|
||||
pub fn is_dark(self) -> bool {
|
||||
match self {
|
||||
Self::SolarizedDark
|
||||
|
|
@ -209,7 +238,7 @@ impl std::fmt::Display for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ScopeRangeIterator {
|
||||
struct ScopeRangeIterator {
|
||||
ops: Vec<(usize, parsing::ScopeStackOp)>,
|
||||
line_length: usize,
|
||||
index: usize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue