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

Add 'plist-load' feature, analogous to existing 'yaml-load' feature #345

Merged
merged 4 commits into from
Aug 19, 2021

Conversation

Enselic
Copy link
Collaborator

@Enselic Enselic commented Aug 10, 2021

Why do this?

The plist package that syntect currently unconditionally depends brings in several dependencies on its own, the heaviest being xml-rs. For use cases where loading of themes is not needed, it is pleasant to not have to compile unneeded dependencies.

This new plist-load feature is very similar to the existing yaml-load feature, both in purpose, and how it is implemented. Whereas yaml-load is for syntax definitions, plist-load is for themes and theme preferences.

Public API is not affected

I have taken care not to change the public API (with all features enabled) with this change.

That the public API has not changed (at least not in terms of added/removed/moved items) can be verified with this little oneliner:

rm -f /tmp/all-*.html && for commit in plist-load-feature  master; do git ch $commit && cargo clean -p syntect && cargo doc --all-features && cp target/doc/syntect/all.html /tmp/all-$commit.html; done && diff -u /tmp/all-*.html | diff-so-fancy

Example of usefulness in practice

To demonstrate that this feature is useful, I recommend to compare the number of dependencies you have to build when you do this:

cp examples/synhtml.rs src/main.rs # temporarily side-step dev-dependencies
cargo run --no-default-features --features html,assets,dump-load,regex-onig -- examples/synhtml.rs

Before this change, you need to build 68 dependencies. After this change, it is only necessary to build 52 dependencies.

Guide to Code Review

I recommend to Code Review each commit in this PR individually.
The first two commits are simple refactorings. The third commit just cuts and pastes code around. The fourth commit introduces the plist-load feature, and also adds an automated CI test for this feature.

Namely to the same file in which FontStyle is declared.

This will make it easier to introduce a theme_load.rs file later.
It is safe to remove because it has never been re-exported as public API.
To make it easier to later introduce a 'plist-load' feature similar
to the existing 'yaml-load' feature, but for themes and not syntaxes.

I have confirmed that this change does not affect the public API.
plist brings in several dependencies, most notably the heavy xml-rs dependency.
So if you don't need to parse theme files, it is nice to be able to skip
this dependency.

For example it brings down the number of dependencies to build from 68 to 52
when building examples/synhtml.rs as a regular app. And build time shrinks
proportionally. Try yourself with:

    cp examples/synhtml.rs src/main.rs # temporarily side-step dev-dependencies
    cargo build --no-default-features --features parsing,html,assets,dump-load,regex-onig
@trishume trishume merged commit 3b1fc12 into trishume:master Aug 19, 2021
@trishume
Copy link
Owner

Thanks, this makes sense!

@Enselic Enselic deleted the plist-load-feature branch October 18, 2021 10:16
Enselic pushed a commit to Enselic/syntect that referenced this pull request Dec 28, 2021
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
Enselic pushed a commit to Enselic/syntect that referenced this pull request Dec 28, 2021
It was 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants