Skip to content

Commit

Permalink
[fea-rs] Move max_n_errors into Opt struct
Browse files Browse the repository at this point in the history
This is in anticipation of adding additional Opts (specifically for only
compiling certain tables) and I'd like `Opts` to be the source of truth
for user configuration.
  • Loading branch information
cmyr committed Feb 6, 2024
1 parent 8f4c99a commit 2214fa0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 2 additions & 10 deletions fea-rs/src/compile/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct Compiler<'a, F: FeatureProvider, V: VariationInfo> {
// variable fonts only
var_info: Option<&'a V>,
feature_writer: Option<&'a F>,
// this is not in `Opts` because it is specific to the compiler struct;
// if you're compiling manually you are responsible for handling warnings.
print_warnings: bool,
max_n_errors: usize,
opts: Opts,
Expand Down Expand Up @@ -95,16 +97,6 @@ impl<'a, F: FeatureProvider, V: VariationInfo> Compiler<'a, F, V> {
self
}

/// Specify a maximum number of messages to print when errors occur.
///
/// Default is some arbitrary 'reasonable' number (currently 100.) To
/// suppress errors, pass `0`. To print all errors, pass a number as large
/// as the number of errors you intend to write.
pub fn max_error_messages(mut self, max_n_errors: usize) -> Self {
self.max_n_errors = max_n_errors;
self
}

/// Specify an explicit project root.
///
/// This is useful in cases where import resolution is based on an explicit
Expand Down
25 changes: 24 additions & 1 deletion fea-rs/src/compile/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
// a very important part of our API, and a more natural place for us to specify
// options is in the 'Compiler' struct itself.

const DEFAULT_N_MESSAGES_TO_PRINT: usize = 100;

/// Options for configuring compilation behaviour.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct Opts {
pub(crate) make_post_table: bool,
pub(crate) max_n_errors: usize,
}

impl Opts {
Expand All @@ -22,4 +25,24 @@ impl Opts {
self.make_post_table = flag;
self
}

/// Specify the number of errors to print when printing a [`DiagnosticSet`].
///
/// Default is some arbitrary 'reasonable' number (currently 100.) To
/// suppress errors, pass `0`. For 'all errors', pass `usize::MAX`.
///
/// [`DiagnosticSet`]: crate::DiagnosticSet
pub fn max_error_messages(mut self, max_n_errors: usize) -> Self {
self.max_n_errors = max_n_errors;
self
}
}

impl Default for Opts {
fn default() -> Self {
Self {
make_post_table: false,
max_n_errors: DEFAULT_N_MESSAGES_TO_PRINT,
}
}
}
2 changes: 1 addition & 1 deletion fea-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod util;
mod tests;

pub use common::{GlyphIdent, GlyphMap, GlyphName, GlyphSet};
pub use compile::Compiler;
pub use compile::{Compiler, Opts};
pub use diagnostic::{Diagnostic, DiagnosticSet, Level};
pub use parse::{ParseTree, TokenSet};
pub use token_tree::{typed, Kind, Node, NodeOrToken, Token};

0 comments on commit 2214fa0

Please sign in to comment.