aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-09 08:56:58 +0000
committerGitHub <[email protected]>2020-03-09 08:56:58 +0000
commitbeb4f4954179998e317db33e47a48a9bb7374977 (patch)
treee2af54ce707bfcdd0a0cd3fc5d547f43fc9fb7d1 /crates/ra_mbe/src
parent30062da6284052deac04c759540f81d5b326689c (diff)
parentafdf08e964345ac4a884a5630772611ba81f6969 (diff)
Merge #3513
3513: Completion in macros r=matklad a=flodiebold I experimented a bit with completion in macros. It's kind of working, but there are a lot of rough edges. - I'm trying to expand the macro call with the inserted fake token. This requires some hacky additions on the HIR level to be able to do "hypothetical" expansions. There should probably be a nicer API for this, if we want to do it this way. I'm not sure whether it's worth it, because we still can't do a lot if the original macro call didn't expand in nearly the same way. E.g. if we have something like `println!("", x<|>)` the expansions will look the same and everything is fine; but in that case we could maybe have achieved the same result in a simpler way. If we have something like `m!(<|>)` where `m!()` doesn't even expand or expands to something very different, we don't really know what to do anyway. - Relatedly, there are a lot of cases where this doesn't work because either the original call or the hypothetical call doesn't expand. E.g. if we have `m!(x.<|>)` the original token tree doesn't parse as an expression; if we have `m!(match x { <|> })` the hypothetical token tree doesn't parse. It would be nice if we could have better error recovery in these cases. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/mbe_expander/matcher.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs
index ffba03898..49c53183a 100644
--- a/crates/ra_mbe/src/mbe_expander/matcher.rs
+++ b/crates/ra_mbe/src/mbe_expander/matcher.rs
@@ -247,6 +247,7 @@ impl<'a> TtIter<'a> {
247 ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind); 247 ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind);
248 248
249 if !sink.cursor.is_root() || sink.error { 249 if !sink.cursor.is_root() || sink.error {
250 // FIXME better recovery in this case would help completion inside macros immensely
250 return Err(()); 251 return Err(());
251 } 252 }
252 253
@@ -375,7 +376,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> Result<Option<Fragment>, Ex
375 return Ok(Some(Fragment::Tokens(tt))); 376 return Ok(Some(Fragment::Tokens(tt)));
376 } 377 }
377 }; 378 };
378 let tt = input.expect_fragment(fragment).map_err(|()| err!())?; 379 let tt =
380 input.expect_fragment(fragment).map_err(|()| err!("fragment did not parse as {}", kind))?;
379 let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; 381 let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) };
380 Ok(Some(fragment)) 382 Ok(Some(fragment))
381} 383}