diff options
Diffstat (limited to 'crates/ra_hir/src/module/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 98 |
1 files changed, 1 insertions, 97 deletions
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 768836b65..5e4bb7669 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -312,7 +312,6 @@ where | |||
312 | let mut segments = import.path.segments.iter().enumerate(); | 312 | let mut segments = import.path.segments.iter().enumerate(); |
313 | 313 | ||
314 | let mut curr = match import.path.kind { | 314 | let mut curr = match import.path.kind { |
315 | // TODO: handle extern crates | ||
316 | PathKind::Plain => { | 315 | PathKind::Plain => { |
317 | let root_id = module_id.crate_root(&self.module_tree); | 316 | let root_id = module_id.crate_root(&self.module_tree); |
318 | let file_id = root_id.source(&self.module_tree).file_id(); | 317 | let file_id = root_id.source(&self.module_tree).file_id(); |
@@ -389,99 +388,4 @@ where | |||
389 | } | 388 | } |
390 | 389 | ||
391 | #[cfg(test)] | 390 | #[cfg(test)] |
392 | mod tests { | 391 | mod tests; |
393 | use std::sync::Arc; | ||
394 | |||
395 | use salsa::Database; | ||
396 | use ra_db::FilesDatabase; | ||
397 | use ra_syntax::SmolStr; | ||
398 | |||
399 | use crate::{ | ||
400 | self as hir, | ||
401 | db::HirDatabase, | ||
402 | mock::MockDatabase, | ||
403 | }; | ||
404 | |||
405 | fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) { | ||
406 | let (db, pos) = MockDatabase::with_position(fixture); | ||
407 | let source_root = db.file_source_root(pos.file_id); | ||
408 | let module = hir::source_binder::module_from_position(&db, pos) | ||
409 | .unwrap() | ||
410 | .unwrap(); | ||
411 | let module_id = module.module_id; | ||
412 | (db.item_map(source_root).unwrap(), module_id) | ||
413 | } | ||
414 | |||
415 | #[test] | ||
416 | fn test_item_map() { | ||
417 | let (item_map, module_id) = item_map( | ||
418 | " | ||
419 | //- /lib.rs | ||
420 | mod foo; | ||
421 | |||
422 | use crate::foo::bar::Baz; | ||
423 | <|> | ||
424 | |||
425 | //- /foo/mod.rs | ||
426 | pub mod bar; | ||
427 | |||
428 | //- /foo/bar.rs | ||
429 | pub struct Baz; | ||
430 | ", | ||
431 | ); | ||
432 | let name = SmolStr::from("Baz"); | ||
433 | let resolution = &item_map.per_module[&module_id].items[&name]; | ||
434 | assert!(resolution.def_id.is_some()); | ||
435 | } | ||
436 | |||
437 | #[test] | ||
438 | fn typing_inside_a_function_should_not_invalidate_item_map() { | ||
439 | let (mut db, pos) = MockDatabase::with_position( | ||
440 | " | ||
441 | //- /lib.rs | ||
442 | mod foo;<|> | ||
443 | |||
444 | use crate::foo::bar::Baz; | ||
445 | |||
446 | fn foo() -> i32 { | ||
447 | 1 + 1 | ||
448 | } | ||
449 | //- /foo/mod.rs | ||
450 | pub mod bar; | ||
451 | |||
452 | //- /foo/bar.rs | ||
453 | pub struct Baz; | ||
454 | ", | ||
455 | ); | ||
456 | let source_root = db.file_source_root(pos.file_id); | ||
457 | { | ||
458 | let events = db.log_executed(|| { | ||
459 | db.item_map(source_root).unwrap(); | ||
460 | }); | ||
461 | assert!(format!("{:?}", events).contains("item_map")) | ||
462 | } | ||
463 | |||
464 | let new_text = " | ||
465 | mod foo; | ||
466 | |||
467 | use crate::foo::bar::Baz; | ||
468 | |||
469 | fn foo() -> i32 { 92 } | ||
470 | " | ||
471 | .to_string(); | ||
472 | |||
473 | db.query_mut(ra_db::FileTextQuery) | ||
474 | .set(pos.file_id, Arc::new(new_text)); | ||
475 | |||
476 | { | ||
477 | let events = db.log_executed(|| { | ||
478 | db.item_map(source_root).unwrap(); | ||
479 | }); | ||
480 | assert!( | ||
481 | !format!("{:?}", events).contains("_item_map"), | ||
482 | "{:#?}", | ||
483 | events | ||
484 | ) | ||
485 | } | ||
486 | } | ||
487 | } | ||