aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-01-08 13:40:41 +0000
committerFlorian Diebold <[email protected]>2019-01-08 14:16:24 +0000
commit946b0ba02c2ab126b1b1d29027e60f21915d631e (patch)
treec1f4896435ecfa48470e08787a24a5e3b73cc4fb /crates/ra_hir/src/nameres.rs
parentd4b44a092f1fd5267a02719667d8d5e22ba0d904 (diff)
Fix name resolution across source roots
It was using the wrong name in that case.
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r--crates/ra_hir/src/nameres.rs48
1 files changed, 41 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 4181bf4b8..20adc9ec4 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -433,6 +433,7 @@ where
433 continue; 433 continue;
434 } 434 }
435 if self.resolve_import(module_id, import)? { 435 if self.resolve_import(module_id, import)? {
436 log::debug!("import {:?} resolved (or definite error)", import);
436 self.processed_imports.insert((module_id, i)); 437 self.processed_imports.insert((module_id, i));
437 } 438 }
438 } 439 }
@@ -440,6 +441,7 @@ where
440 } 441 }
441 442
442 fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> Cancelable<bool> { 443 fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> Cancelable<bool> {
444 log::debug!("resolving import: {:?}", import);
443 let ptr = match import.kind { 445 let ptr = match import.kind {
444 ImportKind::Glob => return Ok(false), 446 ImportKind::Glob => return Ok(false),
445 ImportKind::Named(ptr) => ptr, 447 ImportKind::Named(ptr) => ptr,
@@ -450,8 +452,11 @@ where
450 PathKind::Super => { 452 PathKind::Super => {
451 match module_id.parent(&self.module_tree) { 453 match module_id.parent(&self.module_tree) {
452 Some(it) => it, 454 Some(it) => it,
453 // TODO: error 455 None => {
454 None => return Ok(true), // this can't suddenly resolve if we just resolve some other imports 456 // TODO: error
457 log::debug!("super path in root module");
458 return Ok(true); // this can't suddenly resolve if we just resolve some other imports
459 }
455 } 460 }
456 } 461 }
457 PathKind::Crate => module_id.crate_root(&self.module_tree), 462 PathKind::Crate => module_id.crate_root(&self.module_tree),
@@ -462,13 +467,20 @@ where
462 467
463 let def_id = match self.result.per_module[&curr].items.get(name) { 468 let def_id = match self.result.per_module[&curr].items.get(name) {
464 Some(res) if !res.def_id.is_none() => res.def_id, 469 Some(res) if !res.def_id.is_none() => res.def_id,
465 _ => return Ok(false), 470 _ => {
471 log::debug!("path segment {:?} not found", name);
472 return Ok(false);
473 }
466 }; 474 };
467 475
468 if !is_last { 476 if !is_last {
469 let type_def_id = if let Some(d) = def_id.take(Namespace::Types) { 477 let type_def_id = if let Some(d) = def_id.take(Namespace::Types) {
470 d 478 d
471 } else { 479 } else {
480 log::debug!(
481 "path segment {:?} resolved to value only, but is not last",
482 name
483 );
472 return Ok(false); 484 return Ok(false);
473 }; 485 };
474 curr = match type_def_id.loc(self.db) { 486 curr = match type_def_id.loc(self.db) {
@@ -486,27 +498,49 @@ where
486 segments: import.path.segments[i + 1..].iter().cloned().collect(), 498 segments: import.path.segments[i + 1..].iter().cloned().collect(),
487 kind: PathKind::Crate, 499 kind: PathKind::Crate,
488 }; 500 };
501 log::debug!("resolving {:?} in other source root", path);
489 let def_id = module.resolve_path(self.db, &path)?; 502 let def_id = module.resolve_path(self.db, &path)?;
490 if !def_id.is_none() { 503 if !def_id.is_none() {
504 let name = path.segments.last().unwrap();
491 self.update(module_id, |items| { 505 self.update(module_id, |items| {
492 let res = Resolution { 506 let res = Resolution {
493 def_id: def_id, 507 def_id,
494 import: Some(ptr), 508 import: Some(ptr),
495 }; 509 };
496 items.items.insert(name.clone(), res); 510 items.items.insert(name.clone(), res);
497 }); 511 });
512 log::debug!(
513 "resolved import {:?} ({:?}) cross-source root to {:?}",
514 name,
515 import,
516 def_id.map(|did| did.loc(self.db))
517 );
498 return Ok(true); 518 return Ok(true);
499 } else { 519 } else {
500 return Ok(false); 520 log::debug!("rest of path did not resolve in other source root");
521 return Ok(true);
501 } 522 }
502 } 523 }
503 } 524 }
504 _ => return Ok(true), // this resolved to a non-module, so the path won't ever resolve 525 _ => {
526 log::debug!(
527 "path segment {:?} resolved to non-module {:?}, but is not last",
528 name,
529 type_def_id.loc(self.db)
530 );
531 return Ok(true); // this resolved to a non-module, so the path won't ever resolve
532 }
505 } 533 }
506 } else { 534 } else {
535 log::debug!(
536 "resolved import {:?} ({:?}) within source root to {:?}",
537 name,
538 import,
539 def_id.map(|did| did.loc(self.db))
540 );
507 self.update(module_id, |items| { 541 self.update(module_id, |items| {
508 let res = Resolution { 542 let res = Resolution {
509 def_id: def_id, 543 def_id,
510 import: Some(ptr), 544 import: Some(ptr),
511 }; 545 };
512 items.items.insert(name.clone(), res); 546 items.items.insert(name.clone(), res);