Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feature semver violations in v4.7.0 #403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .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 All @@ -76,4 +76,4 @@ jobs:
- name: Run Xi tests
run: |
# Test the build configuration that Xi uses
cargo test --lib --no-default-features --features "assets dump-load-rs"
cargo test --lib --no-default-features --features "assets dump-load"
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.1](https://github.com/trishume/syntect/compare/v4.7.0...v4.7.1) (2022-01-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
35 changes: 15 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ walkdir = "2.0"
regex-syntax = { version = "0.6", optional = true }
lazy_static = "1.0"
bitflags = "1.0.4"
plist = { version = "1", optional = true }
plist = "1"
bincode = { version = "1.0", optional = true }
flate2 = { version = "1.0", optional = true, default-features = false }
flate2 = { version = "1.0", optional = true }
fnv = { version = "1.0", optional = true }
serde = "1.0"
serde_derive = "1.0"
Expand All @@ -47,36 +47,31 @@ pretty_assertions = "0.6"
# will fail, choose one of each. If you are using both creation and loading,
# your binary will be smaller if you choose the same one for each.

# Pure Rust dump loading, slower than regular `dump-load`
dump-load-rs = ["flate2/rust_backend", "bincode"]
# Dump loading using flate2, which depends on the miniz C library.
dump-load = ["flate2/default", "bincode"]
# Dump creation using flate2, which depends on the miniz C library.
dump-create = ["flate2/default", "bincode"]
# Pure Rust dump creation, worse compressor so produces larger dumps than dump-create
dump-create-rs = ["flate2/rust_backend", "bincode"]
# Legacy alias for `dump-load`
dump-load-rs = ["dump-load"]
# Dump loading using flate2
dump-load = ["flate2", "bincode"]
# Dump creation using flate2
dump-create = ["flate2", "bincode"]
# Legacy alias for `dump-create`
dump-create-rs = ["dump-create"]

regex-fancy = ["fancy-regex"]
regex-onig = ["onig"]

# If you enable "parsing", you must also enable either "dump-load" or
# "dump-load-rs", and "dump-create" or "dump-create-rs". Otherwise the code that
# enables lazy-loading of syntaxes will not compile.
parsing = ["regex-syntax", "fnv"]
parsing = ["regex-syntax", "fnv", "dump-create", "dump-load"]

# 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.
# For `assets` to do anything, it requires `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
54 changes: 27 additions & 27 deletions src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@
//! [`ThemeSet`]: ../highlighting/struct.ThemeSet.html
//! [`dump_to_file`]: fn.dump_to_file.html
use bincode::Result;
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
use bincode::deserialize_from;
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
use bincode::serialize_into;
use std::fs::File;
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
use std::io::{BufRead};
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
use std::io::{BufWriter, Write};
#[cfg(all(feature = "parsing", feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "parsing", feature = "assets", feature = "dump-load"))]
use crate::parsing::SyntaxSet;
#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "assets", feature = "dump-load"))]
use crate::highlighting::ThemeSet;
use std::path::Path;
#[cfg(feature = "dump-create")]
use flate2::write::ZlibEncoder;
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
use flate2::bufread::ZlibDecoder;
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
use flate2::Compression;
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
use serde::Serialize;
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
use serde::de::DeserializeOwned;

/// Dumps an object to the given writer in a compressed binary format
///
/// The writer is encoded with the `bincode` crate and compressed with `flate2`.
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
pub fn dump_to_writer<T: Serialize, W: Write>(to_dump: &T, output: W) -> Result<()> {
serialize_to_writer_impl(to_dump, output, true)
}

/// Dumps an object to a binary array in the same format as [`dump_to_writer`]
///
/// [`dump_to_writer`]: fn.dump_to_writer.html
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
pub fn dump_binary<T: Serialize>(o: &T) -> Vec<u8> {
let mut v = Vec::new();
dump_to_writer(o, &mut v).unwrap();
Expand All @@ -62,28 +62,28 @@ pub fn dump_binary<T: Serialize>(o: &T) -> Vec<u8> {
/// the `bincode` crate and then compressed with the `flate2` crate.
///
/// [`dump_to_writer`]: fn.dump_to_writer.html
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
pub fn dump_to_file<T: Serialize, P: AsRef<Path>>(o: &T, path: P) -> Result<()> {
let out = BufWriter::new(File::create(path)?);
dump_to_writer(o, out)
}

/// A helper function for decoding and decompressing data from a reader
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
pub fn from_reader<T: DeserializeOwned, R: BufRead>(input: R) -> Result<T> {
deserialize_from_reader_impl(input, true)
}

/// Returns a fully loaded object from a binary dump.
///
/// This function panics if the dump is invalid.
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
pub fn from_binary<T: DeserializeOwned>(v: &[u8]) -> T {
from_reader(v).unwrap()
}

/// Returns a fully loaded object from a binary dump file.
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
pub fn from_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T> {
let contents = std::fs::read(path)?;
from_reader(&contents[..])
Expand All @@ -93,15 +93,15 @@ pub fn from_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T>
/// itself shall not be compressed, because the data for its lazy-loaded
/// syntaxes are already compressed. Compressing another time just results in
/// bad performance.
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
pub fn dump_to_uncompressed_file<T: Serialize, P: AsRef<Path>>(o: &T, path: P) -> Result<()> {
let out = BufWriter::new(File::create(path)?);
serialize_to_writer_impl(o, out, false)
}

/// To be used when deserializing a [`SyntaxSet`] that was previously written to
/// file using [dump_to_uncompressed_file].
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
pub fn from_uncompressed_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T> {
let contents = std::fs::read(path)?;
deserialize_from_reader_impl(&contents[..], false)
Expand All @@ -110,13 +110,13 @@ pub fn from_uncompressed_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P)
/// To be used when deserializing a [`SyntaxSet`] from raw data, for example
/// data that has been embedded in your own binary with the [`include_bytes!`]
/// macro.
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
fn from_uncompressed_data<T: DeserializeOwned>(v: &[u8]) -> Result<T> {
#[cfg(feature = "dump-load")]
pub fn from_uncompressed_data<T: DeserializeOwned>(v: &[u8]) -> Result<T> {
deserialize_from_reader_impl(v, false)
}

/// Private low level helper function used to implement the public API.
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
#[cfg(feature = "dump-create")]
fn serialize_to_writer_impl<T: Serialize, W: Write>(to_dump: &T, output: W, use_compression: bool) -> Result<()> {
if use_compression {
let mut encoder = ZlibEncoder::new(output, Compression::best());
Expand All @@ -127,7 +127,7 @@ fn serialize_to_writer_impl<T: Serialize, W: Write>(to_dump: &T, output: W, use_
}

/// Private low level helper function used to implement the public API.
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
#[cfg(feature = "dump-load")]
fn deserialize_from_reader_impl<T: DeserializeOwned, R: BufRead>(input: R, use_compression: bool) -> Result<T> {
if use_compression {
let mut decoder = ZlibDecoder::new(input);
Expand All @@ -137,7 +137,7 @@ fn deserialize_from_reader_impl<T: DeserializeOwned, R: BufRead>(input: R, use_c
}
}

#[cfg(all(feature = "parsing", feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "parsing", feature = "assets", feature = "dump-load"))]
impl SyntaxSet {
/// Instantiates a new syntax set from a binary dump of Sublime Text's default open source
/// syntax definitions.
Expand Down Expand Up @@ -195,7 +195,7 @@ impl SyntaxSet {
}
}

#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "assets", feature = "dump-load"))]
impl ThemeSet {
/// Loads the set of default themes
/// Currently includes (these are the keys for the map):
Expand All @@ -210,7 +210,7 @@ impl ThemeSet {

#[cfg(test)]
mod tests {
#[cfg(all(feature = "yaml-load", any(feature = "dump-create", feature = "dump-create-rs"), any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "yaml-load", feature = "dump-create", feature = "dump-load"))]
#[test]
fn can_dump_and_load() {
use super::*;
Expand All @@ -225,7 +225,7 @@ mod tests {
assert_eq!(ss.syntaxes().len(), ss2.syntaxes().len());
}

#[cfg(all(feature = "yaml-load", any(feature = "dump-create", feature = "dump-create-rs"), any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "yaml-load", feature = "dump-create", feature = "dump-load"))]
#[test]
fn dump_is_deterministic() {
use super::*;
Expand All @@ -246,7 +246,7 @@ mod tests {
assert_eq!(bin1, bin2);
}

#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "assets", feature = "dump-load"))]
#[test]
fn has_default_themes() {
use crate::highlighting::ThemeSet;
Expand Down
2 changes: 1 addition & 1 deletion src/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'a> Iterator for ScopeRegionIterator<'a> {
}
}

#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "assets", feature = "dump-load"))]
#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/highlighting/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a> Highlighter<'a> {
}
}

#[cfg(all(feature = "assets", feature = "parsing", any(feature = "dump-load", feature = "dump-load-rs")))]
#[cfg(all(feature = "assets", feature = "parsing", feature = "dump-load"))]
#[cfg(test)]
mod tests {
use super::*;
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
2 changes: 1 addition & 1 deletion src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ pub fn start_highlighted_html_snippet(t: &Theme) -> (String, Color) {

#[cfg(all(
feature = "assets",
any(feature = "dump-load", feature = "dump-load-rs")
feature = "dump-load"
))]
#[cfg(test)]
mod tests {
Expand Down
Loading