diagnostics

This commit is contained in:
Aleksey Kladov 2019-03-21 22:13:11 +03:00
parent 4132fbf3a0
commit 7e8f17188e
6 changed files with 74 additions and 6 deletions

View file

@ -3,7 +3,7 @@ use hir::{Problem, source_binder};
use ra_db::SourceDatabase;
use ra_syntax::{
Location, SourceFile, SyntaxKind, TextRange, SyntaxNode,
ast::{self, AstNode},
ast::{self, AstNode, NameOwner},
};
use ra_text_edit::{TextEdit, TextEditBuilder};
@ -134,6 +134,13 @@ fn check_module(
file_id: FileId,
module: hir::Module,
) {
for decl in module.declarations(db) {
match decl {
hir::ModuleDef::Function(f) => check_function(acc, db, f),
_ => (),
}
}
let source_root = db.file_source_root(file_id);
for (name_node, problem) in module.problems(db) {
let diag = match problem {
@ -153,6 +160,27 @@ fn check_module(
}
}
fn check_function(acc: &mut Vec<Diagnostic>, db: &RootDatabase, function: hir::Function) {
let (_file_id, fn_def) = function.source(db);
let source_file = fn_def.syntax().ancestors().find_map(ast::SourceFile::cast).unwrap();
let source_map = function.body_source_map(db);
for d in function.diagnostics(db) {
match d {
hir::diagnostics::FunctionDiagnostic::NoSuchField { expr, field } => {
if let Some(field) = source_map.field_syntax(expr, field) {
let field = field.to_node(&source_file);
acc.push(Diagnostic {
message: "no such field".into(),
range: field.syntax().range(),
severity: Severity::Error,
fix: None,
})
}
}
}
}
}
#[cfg(test)]
mod tests {
use test_utils::assert_eq_text;