aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/parsing.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-07-22 07:46:29 +0100
committerDavid Lattimore <[email protected]>2020-07-24 12:34:00 +0100
commit757f755c29e041fd319af466d7d0418f54cb090a (patch)
tree30d94206c5009730855a2ceaebdf364963358928 /crates/ra_ssr/src/parsing.rs
parent3975952601888d9f77e466c12e8e389748984b33 (diff)
SSR: Match paths based on what they resolve to
Also render template paths appropriately for their context.
Diffstat (limited to 'crates/ra_ssr/src/parsing.rs')
-rw-r--r--crates/ra_ssr/src/parsing.rs17
1 files changed, 1 insertions, 16 deletions
diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ra_ssr/src/parsing.rs
index cf7fb517f..2d6f4e514 100644
--- a/crates/ra_ssr/src/parsing.rs
+++ b/crates/ra_ssr/src/parsing.rs
@@ -7,7 +7,7 @@
7 7
8use crate::errors::bail; 8use crate::errors::bail;
9use crate::{SsrError, SsrPattern, SsrRule}; 9use crate::{SsrError, SsrPattern, SsrRule};
10use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken, T}; 10use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, SyntaxNode, T};
11use rustc_hash::{FxHashMap, FxHashSet}; 11use rustc_hash::{FxHashMap, FxHashSet};
12use std::str::FromStr; 12use std::str::FromStr;
13 13
@@ -16,7 +16,6 @@ pub(crate) struct ParsedRule {
16 pub(crate) placeholders_by_stand_in: FxHashMap<SmolStr, Placeholder>, 16 pub(crate) placeholders_by_stand_in: FxHashMap<SmolStr, Placeholder>,
17 pub(crate) pattern: SyntaxNode, 17 pub(crate) pattern: SyntaxNode,
18 pub(crate) template: Option<SyntaxNode>, 18 pub(crate) template: Option<SyntaxNode>,
19 pub(crate) index: usize,
20} 19}
21 20
22#[derive(Debug)] 21#[derive(Debug)]
@@ -93,16 +92,11 @@ impl RuleBuilder {
93 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(), 92 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(),
94 pattern: pattern.syntax().clone(), 93 pattern: pattern.syntax().clone(),
95 template: Some(template.syntax().clone()), 94 template: Some(template.syntax().clone()),
96 // For now we give the rule an index of 0. It's given a proper index when the rule
97 // is added to the SsrMatcher. Using an Option<usize>, instead would be slightly
98 // more correct, but we delete this field from ParsedRule in a subsequent commit.
99 index: 0,
100 }), 95 }),
101 (Ok(pattern), None) => self.rules.push(ParsedRule { 96 (Ok(pattern), None) => self.rules.push(ParsedRule {
102 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(), 97 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(),
103 pattern: pattern.syntax().clone(), 98 pattern: pattern.syntax().clone(),
104 template: None, 99 template: None,
105 index: 0,
106 }), 100 }),
107 _ => {} 101 _ => {}
108 } 102 }
@@ -171,15 +165,6 @@ impl RawPattern {
171 } 165 }
172} 166}
173 167
174impl ParsedRule {
175 pub(crate) fn get_placeholder(&self, token: &SyntaxToken) -> Option<&Placeholder> {
176 if token.kind() != SyntaxKind::IDENT {
177 return None;
178 }
179 self.placeholders_by_stand_in.get(token.text())
180 }
181}
182
183impl FromStr for SsrPattern { 168impl FromStr for SsrPattern {
184 type Err = SsrError; 169 type Err = SsrError;
185 170