Skip to content

Commit

Permalink
Add ambiguities ranges to snippets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivorforce committed Apr 26, 2024
1 parent d24ec91 commit f77f06c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/resolver/ambiguous.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::ops::Range;

pub use abstract_call::AmbiguousAbstractCall;
pub use function_call::{AmbiguousFunctionCall, AmbiguousFunctionCandidate};
Expand All @@ -16,4 +17,6 @@ pub enum AmbiguityResult<V> {

pub trait ResolverAmbiguity: Display {
fn attempt_to_resolve(&mut self, expressions: &mut ImperativeResolver) -> RResult<AmbiguityResult<()>>;

fn get_position(&self) -> Range<usize>;
}
4 changes: 4 additions & 0 deletions src/resolver/ambiguous/abstract_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ impl ResolverAmbiguity for AmbiguousAbstractCall {
}
})
}

fn get_position(&self) -> Range<usize> {
self.range.clone()
}
}
6 changes: 5 additions & 1 deletion src/resolver/ambiguous/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl AmbiguousFunctionCall {

impl Display for AmbiguousFunctionCall {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Ambiguous function call ({} candidates): {}", self.candidates.len(), self.representation.name)
write!(f, "Ambiguous function call ({} candidates).", self.candidates.len())
}
}

Expand Down Expand Up @@ -144,4 +144,8 @@ impl ResolverAmbiguity for AmbiguousFunctionCall {
}
}
}

fn get_position(&self) -> Range<usize> {
self.range.clone()
}
}
2 changes: 1 addition & 1 deletion src/resolver/imperative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl <'a> ImperativeResolver<'a> {
RuntimeError::error(format!("Ambiguous ({} times)", self.ambiguities.len()).as_str())
.with_notes(
self.ambiguities.iter()
.map(|x| RuntimeError::info(x.to_string().as_str()))
.map(|x| RuntimeError::warning(x.to_string().as_str()).in_range(x.get_position()))
)
.to_array()
);
Expand Down

0 comments on commit f77f06c

Please sign in to comment.