Refactor SSR so that placeholders store a Var

This allows lookup of placeholder bindings given a placeholder without
needing to create a Var instance.
This commit is contained in:
David Lattimore 2020-08-06 11:30:52 +10:00
parent 674af600f1
commit c84f98385a
4 changed files with 26 additions and 18 deletions

View file

@ -2,7 +2,7 @@
//! process of matching, placeholder values are recorded.
use crate::{
parsing::{Constraint, NodeKind, Placeholder},
parsing::{Constraint, NodeKind, Placeholder, Var},
resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
SsrMatches,
};
@ -56,10 +56,6 @@ pub struct Match {
pub(crate) rendered_template_paths: FxHashMap<SyntaxNode, hir::ModPath>,
}
/// Represents a `$var` in an SSR query.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct Var(pub String);
/// Information about a placeholder bound in a match.
#[derive(Debug)]
pub(crate) struct PlaceholderMatch {
@ -182,10 +178,9 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
// We validated the range for the node when we started the match, so the placeholder
// probably can't fail range validation, but just to be safe...
self.validate_range(&original_range)?;
matches_out.placeholder_values.insert(
Var(placeholder.ident.to_string()),
PlaceholderMatch::new(code, original_range),
);
matches_out
.placeholder_values
.insert(placeholder.ident.clone(), PlaceholderMatch::new(code, original_range));
}
return Ok(());
}
@ -487,7 +482,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
}
if let Phase::Second(match_out) = phase {
match_out.placeholder_values.insert(
Var(placeholder.ident.to_string()),
placeholder.ident.clone(),
PlaceholderMatch::from_range(FileRange {
file_id: self.sema.original_range(code).file_id,
range: first_matched_token