aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs31
-rw-r--r--crates/ra_mbe/src/tests.rs2
2 files changed, 28 insertions, 5 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index a3715b1d4..e3cde9eed 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -149,6 +149,10 @@ impl TokenMap {
149 } 149 }
150 } 150 }
151 } 151 }
152
153 fn remove_delim(&mut self, token_id: tt::TokenId) {
154 self.entries.retain(|(tid, _)| *tid != token_id);
155 }
152} 156}
153 157
154/// Returns the textual content of a doc comment block as a quoted string 158/// Returns the textual content of a doc comment block as a quoted string
@@ -245,8 +249,15 @@ impl TokenIdAlloc {
245 token_id 249 token_id
246 } 250 }
247 251
248 fn close_delim(&mut self, id: tt::TokenId, close_abs_range: TextRange) { 252 fn close_delim(&mut self, id: tt::TokenId, close_abs_range: Option<TextRange>) {
249 self.map.update_close_delim(id, close_abs_range - self.global_offset); 253 match close_abs_range {
254 None => {
255 self.map.remove_delim(id);
256 }
257 Some(close) => {
258 self.map.update_close_delim(id, close - self.global_offset);
259 }
260 }
250 } 261 }
251} 262}
252 263
@@ -318,10 +329,22 @@ trait TokenConvertor {
318 self.collect_leaf(&mut subtree.token_trees); 329 self.collect_leaf(&mut subtree.token_trees);
319 } 330 }
320 let last_range = match self.bump() { 331 let last_range = match self.bump() {
321 None => return, 332 None => {
333 // For error resilience, we insert an char punct for the opening delim here
334 self.id_alloc().close_delim(id, None);
335 let leaf: tt::Leaf = tt::Punct {
336 id: self.id_alloc().alloc(range),
337 char: token.to_char().unwrap(),
338 spacing: tt::Spacing::Alone,
339 }
340 .into();
341 result.push(leaf.into());
342 result.extend(subtree.token_trees);
343 return;
344 }
322 Some(it) => it.1, 345 Some(it) => it.1,
323 }; 346 };
324 self.id_alloc().close_delim(id, last_range); 347 self.id_alloc().close_delim(id, Some(last_range));
325 subtree.into() 348 subtree.into()
326 } else { 349 } else {
327 let spacing = match self.peek() { 350 let spacing = match self.peek() {
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index a3f242e49..a7fcea0ac 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -1694,5 +1694,5 @@ fn test_expand_bad_literal() {
1694 macro_rules! foo { ($i:literal) => {}; } 1694 macro_rules! foo { ($i:literal) => {}; }
1695 "#, 1695 "#,
1696 ) 1696 )
1697 .assert_expand_err(r#"foo!(&k");"#, &ExpandError::ConversionError); 1697 .assert_expand_err(r#"foo!(&k");"#, &ExpandError::BindingError("".into()));
1698} 1698}