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

Move formatting of explanations into the report formatter #19

Merged
merged 1 commit into from
Jan 12, 2024
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
101 changes: 100 additions & 1 deletion examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use pubgrub::error::PubGrubError;
use pubgrub::range::Range;
use pubgrub::report::Reporter;
use pubgrub::report::{Derived, Reporter};
use pubgrub::solver::{resolve, OfflineDependencyProvider};
use pubgrub::version::SemanticVersion;

Expand Down Expand Up @@ -108,6 +108,105 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
}
}
}

/// Simplest case, we just combine two external incompatibilities.
fn explain_both_external(
&self,
external1: &External<Package, Range<SemanticVersion>>,
external2: &External<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
// TODO: order should be chosen to make it more logical.
format!(
"Because {} and {}, {}.",
self.format_external(external1),
self.format_external(external2),
self.format_terms(current_terms)
)
}

/// Both causes have already been explained so we use their refs.
fn explain_both_ref(
&self,
ref_id1: usize,
derived1: &Derived<Package, Range<SemanticVersion>>,
ref_id2: usize,
derived2: &Derived<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
// TODO: order should be chosen to make it more logical.
format!(
"Because {} ({}) and {} ({}), {}.",
self.format_terms(&derived1.terms),
ref_id1,
self.format_terms(&derived2.terms),
ref_id2,
self.format_terms(current_terms)
)
}

/// One cause is derived (already explained so one-line),
/// the other is a one-line external cause,
/// and finally we conclude with the current incompatibility.
fn explain_ref_and_external(
&self,
ref_id: usize,
derived: &Derived<Package, Range<SemanticVersion>>,
external: &External<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
// TODO: order should be chosen to make it more logical.
format!(
"Because {} ({}) and {}, {}.",
self.format_terms(&derived.terms),
ref_id,
self.format_external(external),
self.format_terms(current_terms)
)
}

/// Add an external cause to the chain of explanations.
fn and_explain_external(
&self,
external: &External<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
format!(
"And because {}, {}.",
self.format_external(external),
self.format_terms(current_terms)
)
}

/// Add an already explained incompat to the chain of explanations.
fn and_explain_ref(
&self,
ref_id: usize,
derived: &Derived<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
format!(
"And because {} ({}), {}.",
self.format_terms(&derived.terms),
ref_id,
self.format_terms(current_terms)
)
}

/// Add an already explained incompat to the chain of explanations.
fn and_explain_prior_and_external(
&self,
prior_external: &External<Package, Range<SemanticVersion>>,
external: &External<Package, Range<SemanticVersion>>,
current_terms: &Map<Package, Term<Range<SemanticVersion>>>,
) -> String {
format!(
"And because {} and {}, {}.",
self.format_external(prior_external),
self.format_external(external),
self.format_terms(current_terms)
)
}
}

fn main() {
Expand Down
Loading