Skip to content

Commit

Permalink
Remove plist-load feature (but keep code structure)
Browse files Browse the repository at this point in the history
It is not enough to make the `default` feature depend on it. Putting code behind
a feature is in practice a semver breakage. See
sharkdp/bat#1991 (comment) and trishume#402.

It was added in trishume#345 after doing some refactoring. We can keep the refactoring,
but we choose to remove the feature for now. Another option would be to make the
feature opt-out rather than opt-in and rename it to `no-plist-load` or similar.
That would be too unergonomic and confusing however, so for now we just remove
it. We might add it back for v5.0.0
  • Loading branch information
Martin Nordholts committed Dec 28, 2021
1 parent 219a81d commit 0b3fc96
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: |
# Run these tests in release mode since they're slow as heck otherwise
cargo test --features default-fancy --no-default-features --release
- name: Ensure highlight works without 'plist-load' and 'yaml-load' features
- name: Ensure highlight works without 'yaml-load'
run: |
cargo run --example synhtml --no-default-features --features html,assets,dump-load,dump-create,regex-onig -- examples/synhtml.rs
- name: make stuff
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Version 4.7.0](https://github.com/trishume/syntect/compare/v4.7.0...v4.7.1) (2021-12-xx)

- Remove 'plist-load' feature again due to semver violation. [#403](https://github.com/trishume/syntect/pull/403)

## [Version 4.7.0](https://github.com/trishume/syntect/compare/v4.6.0...v4.7.0) (2021-12-25)

- Lazy-load syntaxes to significantly improve startup time
Expand Down
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ regex-onig = ["onig"]
parsing = ["regex-syntax", "fnv"]

# Support for .tmPreferenes metadata files (indentation, comment syntax, etc)
metadata = ["parsing", "plist-load"]
metadata = ["parsing"]
# The `assets` feature enables inclusion of the default theme and syntax packages.
# For `assets` to do anything, it requires one of `dump-load-rs` or `dump-load` to be set.
assets = []
html = ["parsing"]
# Support for parsing .tmTheme files and .tmPreferences files
plist-load = ["plist"]
# Support for parsing .sublime-syntax files
yaml-load = ["yaml-rust", "parsing"]
default-onig = ["parsing", "assets", "html", "plist-load", "yaml-load", "dump-load", "dump-create", "regex-onig"]
default-onig = ["parsing", "assets", "html", "yaml-load", "dump-load", "dump-create", "regex-onig"]
# In order to switch to the fancy-regex engine, disable default features then add the default-fancy feature
default-fancy = ["parsing", "assets", "html", "plist-load", "yaml-load", "dump-load", "dump-create", "regex-fancy"]
default-fancy = ["parsing", "assets", "html", "yaml-load", "dump-load", "dump-create", "regex-fancy"]
default = ["default-onig"]

# [profile.release]
Expand Down
4 changes: 0 additions & 4 deletions src/highlighting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@
//! [`ThemeSet`]: struct.ThemeSet.html
mod highlighter;
mod selector;
#[cfg(feature = "plist-load")]
pub(crate) mod settings;
mod style;
mod theme;
#[cfg(feature = "plist-load")]
mod theme_load;
mod theme_set;

pub use self::selector::*;
#[cfg(feature = "plist-load")]
pub use self::settings::SettingsError;
pub use self::style::*;
pub use self::theme::*;
#[cfg(feature = "plist-load")]
pub use self::theme_load::*;
pub use self::highlighter::*;
pub use self::theme_set::*;
6 changes: 0 additions & 6 deletions src/highlighting/theme_set.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::theme::Theme;
#[cfg(feature = "plist-load")]
use super::settings::*;
use super::super::LoadingError;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -34,29 +33,25 @@ impl ThemeSet {
}

/// Loads a theme given a path to a .tmTheme file
#[cfg(feature = "plist-load")]
pub fn get_theme<P: AsRef<Path>>(path: P) -> Result<Theme, LoadingError> {
let file = std::fs::File::open(path)?;
let mut file = std::io::BufReader::new(file);
Self::load_from_reader(&mut file)
}

/// Loads a theme given a readable stream
#[cfg(feature = "plist-load")]
pub fn load_from_reader<R: std::io::BufRead + std::io::Seek>(r: &mut R) -> Result<Theme, LoadingError> {
Ok(Theme::parse_settings(read_plist(r)?)?)
}

/// Generate a `ThemeSet` from all themes in a folder
#[cfg(feature = "plist-load")]
pub fn load_from_folder<P: AsRef<Path>>(folder: P) -> Result<ThemeSet, LoadingError> {
let mut theme_set = Self::new();
theme_set.add_from_folder(folder)?;
Ok(theme_set)
}

/// Load all the themes in the folder into this `ThemeSet`
#[cfg(feature = "plist-load")]
pub fn add_from_folder<P: AsRef<Path>>(&mut self, folder: P) -> Result<(), LoadingError> {
let paths = Self::discover_theme_paths(folder)?;
for p in &paths {
Expand All @@ -74,7 +69,6 @@ impl ThemeSet {
#[cfg(test)]
mod tests {
use crate::highlighting::{ThemeSet, Color};
#[cfg(feature = "plist-load")]
#[test]
fn can_parse_common_themes() {
let themes = ThemeSet::load_from_folder("testdata").unwrap();
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use std::fmt;
use serde_json::Error as JsonError;
#[cfg(all(feature = "yaml-load", feature = "parsing"))]
use crate::parsing::ParseSyntaxError;
#[cfg(feature = "plist-load")]
use crate::highlighting::{ParseThemeError, SettingsError};

/// Common error type used by syntax and theme loading
Expand All @@ -66,17 +65,14 @@ pub enum LoadingError {
#[cfg(feature = "metadata")]
ParseMetadata(JsonError),
/// a theme file was invalid in some way
#[cfg(feature = "plist-load")]
ParseTheme(ParseThemeError),
/// a theme's Plist syntax was invalid in some way
#[cfg(feature = "plist-load")]
ReadSettings(SettingsError),
/// A path given to a method was invalid.
/// Possibly because it didn't reference a file or wasn't UTF-8.
BadPath,
}

#[cfg(feature = "plist-load")]
impl From<SettingsError> for LoadingError {
fn from(error: SettingsError) -> LoadingError {
LoadingError::ReadSettings(error)
Expand All @@ -89,7 +85,6 @@ impl From<IoError> for LoadingError {
}
}

#[cfg(feature = "plist-load")]
impl From<ParseThemeError> for LoadingError {
fn from(error: ParseThemeError) -> LoadingError {
LoadingError::ParseTheme(error)
Expand Down Expand Up @@ -127,9 +122,7 @@ impl fmt::Display for LoadingError {
},
#[cfg(feature = "metadata")]
ParseMetadata(_) => write!(f, "Failed to parse JSON"),
#[cfg(feature = "plist-load")]
ParseTheme(_) => write!(f, "Invalid syntax theme"),
#[cfg(feature = "plist-load")]
ReadSettings(_) => write!(f, "Invalid syntax theme settings"),
BadPath => write!(f, "Invalid path"),
}
Expand Down

0 comments on commit 0b3fc96

Please sign in to comment.