Don't parse child modules when doing diagnostics

This commit is contained in:
Aleksey Kladov 2020-01-15 14:42:57 +01:00
parent 4a9e4ec7e1
commit 21ea62d292
2 changed files with 10 additions and 3 deletions

View file

@ -7,7 +7,6 @@ use hir_def::{
builtin_type::BuiltinType,
docs::Documentation,
expr::{BindingAnnotation, Pat, PatId},
nameres::ModuleSource,
per_ns::PerNs,
resolver::HasResolver,
type_ref::{Mutability, TypeRef},
@ -193,13 +192,14 @@ impl Module {
pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
let _p = profile("Module::diagnostics");
db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink);
let crate_def_map = db.crate_def_map(self.id.krate);
crate_def_map.add_diagnostics(db, self.id.local_id, sink);
for decl in self.declarations(db) {
match decl {
crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
crate::ModuleDef::Module(m) => {
// Only add diagnostics from inline modules
if let ModuleSource::Module(_) = m.definition_source(db).value {
if crate_def_map[m.id.local_id].origin.is_inline() {
m.diagnostics(db, sink)
}
}

View file

@ -145,6 +145,13 @@ impl ModuleOrigin {
}
}
pub fn is_inline(&self) -> bool {
match self {
ModuleOrigin::Inline { .. } => true,
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false,
}
}
/// Returns a node which defines this module.
/// That is, a file or a `mod foo {}` with items.
fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> {