diff options
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 416f114b4..56ed872d5 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -56,17 +56,16 @@ mod tests; | |||
56 | use std::sync::Arc; | 56 | use std::sync::Arc; |
57 | 57 | ||
58 | use rustc_hash::FxHashMap; | 58 | use rustc_hash::FxHashMap; |
59 | use relative_path::RelativePathBuf; | ||
60 | use ra_arena::{Arena, RawId, impl_arena_id}; | 59 | use ra_arena::{Arena, RawId, impl_arena_id}; |
61 | use ra_db::{FileId, Edition}; | 60 | use ra_db::{FileId, Edition}; |
62 | use ra_syntax::{AstNode, AstPtr, ast}; | ||
63 | use test_utils::tested_by; | 61 | use test_utils::tested_by; |
64 | 62 | ||
65 | use crate::{ | 63 | use crate::{ |
66 | ModuleDef, Name, Crate, Module, | 64 | ModuleDef, Name, Crate, Module, |
67 | DefDatabase, Path, PathKind, HirFileId, | 65 | DefDatabase, Path, PathKind, HirFileId, |
68 | ids::{SourceItemId, SourceFileItemId, MacroCallId}, | 66 | ids::{SourceItemId, SourceFileItemId, MacroCallId}, |
69 | diagnostics::{Diagnostics, UnresolvedModule}, | 67 | diagnostics::DiagnosticSink, |
68 | nameres::diagnostics::DefDiagnostic, | ||
70 | }; | 69 | }; |
71 | 70 | ||
72 | pub(crate) use self::raw::{RawItems, ImportId, ImportSourceMap}; | 71 | pub(crate) use self::raw::{RawItems, ImportId, ImportSourceMap}; |
@@ -228,7 +227,7 @@ impl CrateDefMap { | |||
228 | &self, | 227 | &self, |
229 | db: &impl DefDatabase, | 228 | db: &impl DefDatabase, |
230 | module: CrateModuleId, | 229 | module: CrateModuleId, |
231 | sink: &mut Diagnostics, | 230 | sink: &mut DiagnosticSink, |
232 | ) { | 231 | ) { |
233 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) | 232 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) |
234 | } | 233 | } |
@@ -446,30 +445,47 @@ impl CrateDefMap { | |||
446 | } | 445 | } |
447 | } | 446 | } |
448 | 447 | ||
449 | #[derive(Debug, PartialEq, Eq)] | 448 | mod diagnostics { |
450 | enum DefDiagnostic { | 449 | use relative_path::RelativePathBuf; |
451 | UnresolvedModule { | 450 | use ra_syntax::{AstPtr, AstNode, ast}; |
452 | module: CrateModuleId, | 451 | |
453 | declaration: SourceItemId, | 452 | use crate::{ |
454 | candidate: RelativePathBuf, | 453 | SourceItemId, DefDatabase, |
455 | }, | 454 | nameres::CrateModuleId, |
456 | } | 455 | diagnostics::{DiagnosticSink, UnresolvedModule}, |
456 | }; | ||
457 | 457 | ||
458 | impl DefDiagnostic { | 458 | #[derive(Debug, PartialEq, Eq)] |
459 | fn add_to(&self, db: &impl DefDatabase, target_module: CrateModuleId, sink: &mut Diagnostics) { | 459 | pub(super) enum DefDiagnostic { |
460 | match self { | 460 | UnresolvedModule { |
461 | DefDiagnostic::UnresolvedModule { module, declaration, candidate } => { | 461 | module: CrateModuleId, |
462 | if *module != target_module { | 462 | declaration: SourceItemId, |
463 | return; | 463 | candidate: RelativePathBuf, |
464 | }, | ||
465 | } | ||
466 | |||
467 | impl DefDiagnostic { | ||
468 | pub(super) fn add_to( | ||
469 | &self, | ||
470 | db: &impl DefDatabase, | ||
471 | target_module: CrateModuleId, | ||
472 | sink: &mut DiagnosticSink, | ||
473 | ) { | ||
474 | match self { | ||
475 | DefDiagnostic::UnresolvedModule { module, declaration, candidate } => { | ||
476 | if *module != target_module { | ||
477 | return; | ||
478 | } | ||
479 | let syntax = db.file_item(*declaration); | ||
480 | let decl = ast::Module::cast(&syntax).unwrap(); | ||
481 | sink.push(UnresolvedModule { | ||
482 | file: declaration.file_id, | ||
483 | decl: AstPtr::new(&decl), | ||
484 | candidate: candidate.clone(), | ||
485 | }) | ||
464 | } | 486 | } |
465 | let syntax = db.file_item(*declaration); | ||
466 | let decl = ast::Module::cast(&syntax).unwrap(); | ||
467 | sink.push(UnresolvedModule { | ||
468 | file: declaration.file_id, | ||
469 | decl: AstPtr::new(&decl), | ||
470 | candidate: candidate.clone(), | ||
471 | }) | ||
472 | } | 487 | } |
473 | } | 488 | } |
474 | } | 489 | } |
490 | |||
475 | } | 491 | } |