mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
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:
parent
674af600f1
commit
c84f98385a
4 changed files with 26 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue