aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests/macros.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-09 09:04:00 +0100
committerGitHub <[email protected]>2019-09-09 09:04:00 +0100
commit1db08a54c20c244718e2378272c72ae5c6651f06 (patch)
tree90fe99eb39d045d9bac34cc200a74d0410d51763 /crates/ra_hir/src/nameres/tests/macros.rs
parent72259b67bf2393bec1faf6a9f95a575d6fe9cfea (diff)
parent9ed21d65fb6727f6de4961dfa440981864451af6 (diff)
Merge #1784
1784: Support textual scoped macros r=matklad a=uHOOCCOOHu Refactor the old simulation with `global_macro_scope`. Now it is quite accurate to resolve textual scoped macros. - Expand textual scoped macros in item and non-item place. - Support `#[macro_use]` on `mod`. - Textual scoped macros are collected into `nameres::ModuleScope`, so I think it makes #1727 easier to fix. - It is implemented in a simple way to `clone()` current scoped macro ids into sub-modules. Though only indices are cloned, it will still increase some resolving time. Well, I've not bench-marked yet. In my test with vscode extension, it can now successfully expand `dbg!` from `std` without `std::` prefix. "Goto definition" also works. Screenshot here: <img width="281" alt="Screenshot_20190907_043442" src="https://user-images.githubusercontent.com/14816024/64458794-ddb47900-d128-11e9-95e3-1c8569978825.png"> Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres/tests/macros.rs')
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs108
1 files changed, 105 insertions, 3 deletions
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index c62152d26..ebc4d6890 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -268,12 +268,114 @@ fn prelude_cycle() {
268 ); 268 );
269 assert_snapshot!(map, @r###" 269 assert_snapshot!(map, @r###"
270 ⋮crate 270 ⋮crate
271 ⋮foo: t
272 ⋮prelude: t 271 ⋮prelude: t
273 272
274 ⋮crate::prelude 273 ⋮crate::prelude
275 ⋮declare_mod: m 274 ⋮declare_mod: m
276 275 "###);
277 ⋮crate::foo 276}
277
278#[test]
279fn plain_macros_are_legacy_textual_scoped() {
280 let map = def_map(
281 r#"
282 //- /main.rs
283 mod m1;
284 bar!(NotFoundNotMacroUse);
285
286 mod m2 {
287 foo!(NotFoundBeforeInside2);
288 }
289
290 macro_rules! foo {
291 ($x:ident) => { struct $x; }
292 }
293 foo!(Ok);
294
295 mod m3;
296 foo!(OkShadowStop);
297 bar!(NotFoundMacroUseStop);
298
299 #[macro_use]
300 mod m5 {
301 #[macro_use]
302 mod m6 {
303 macro_rules! foo {
304 ($x:ident) => { fn $x() {} }
305 }
306 }
307 }
308 foo!(ok_double_macro_use_shadow);
309
310 baz!(NotFoundBefore);
311 #[macro_use]
312 mod m7 {
313 macro_rules! baz {
314 ($x:ident) => { struct $x; }
315 }
316 }
317 baz!(OkAfter);
318
319 //- /m1.rs
320 foo!(NotFoundBeforeInside1);
321 macro_rules! bar {
322 ($x:ident) => { struct $x; }
323 }
324
325 //- /m3/mod.rs
326 foo!(OkAfterInside);
327 macro_rules! foo {
328 ($x:ident) => { fn $x() {} }
329 }
330 foo!(ok_shadow);
331
332 #[macro_use]
333 mod m4;
334 bar!(OkMacroUse);
335
336 //- /m3/m4.rs
337 foo!(ok_shadow_deep);
338 macro_rules! bar {
339 ($x:ident) => { struct $x; }
340 }
341 "#,
342 );
343 assert_snapshot!(map, @r###"
344 ⋮crate
345 ⋮Ok: t v
346 ⋮OkAfter: t v
347 ⋮OkShadowStop: t v
348 ⋮foo: m
349 ⋮m1: t
350 ⋮m2: t
351 ⋮m3: t
352 ⋮m5: t
353 ⋮m7: t
354 ⋮ok_double_macro_use_shadow: v
355
356 ⋮crate::m7
357 ⋮baz: m
358
359 ⋮crate::m1
360 ⋮bar: m
361
362 ⋮crate::m5
363 ⋮m6: t
364
365 ⋮crate::m5::m6
366 ⋮foo: m
367
368 ⋮crate::m2
369
370 ⋮crate::m3
371 ⋮OkAfterInside: t v
372 ⋮OkMacroUse: t v
373 ⋮foo: m
374 ⋮m4: t
375 ⋮ok_shadow: v
376
377 ⋮crate::m3::m4
378 ⋮bar: m
379 ⋮ok_shadow_deep: v
278 "###); 380 "###);
279} 381}