aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-21 19:13:11 +0000
committerAleksey Kladov <[email protected]>2019-03-25 07:52:12 +0000
commit7e8f17188efcecfdfd1afbbc894a53c65985f836 (patch)
treeaab311a7646f9880adc82607abd227ef07e35d71 /crates/ra_ide_api/src
parent4132fbf3a08c9de2e28a50bc29a2c37a7c1a42fc (diff)
diagnostics
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 156f28ca3..f662f7e2f 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -3,7 +3,7 @@ use hir::{Problem, source_binder};
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_syntax::{ 4use ra_syntax::{
5 Location, SourceFile, SyntaxKind, TextRange, SyntaxNode, 5 Location, SourceFile, SyntaxKind, TextRange, SyntaxNode,
6 ast::{self, AstNode}, 6 ast::{self, AstNode, NameOwner},
7 7
8}; 8};
9use ra_text_edit::{TextEdit, TextEditBuilder}; 9use ra_text_edit::{TextEdit, TextEditBuilder};
@@ -134,6 +134,13 @@ fn check_module(
134 file_id: FileId, 134 file_id: FileId,
135 module: hir::Module, 135 module: hir::Module,
136) { 136) {
137 for decl in module.declarations(db) {
138 match decl {
139 hir::ModuleDef::Function(f) => check_function(acc, db, f),
140 _ => (),
141 }
142 }
143
137 let source_root = db.file_source_root(file_id); 144 let source_root = db.file_source_root(file_id);
138 for (name_node, problem) in module.problems(db) { 145 for (name_node, problem) in module.problems(db) {
139 let diag = match problem { 146 let diag = match problem {
@@ -153,6 +160,27 @@ fn check_module(
153 } 160 }
154} 161}
155 162
163fn check_function(acc: &mut Vec<Diagnostic>, db: &RootDatabase, function: hir::Function) {
164 let (_file_id, fn_def) = function.source(db);
165 let source_file = fn_def.syntax().ancestors().find_map(ast::SourceFile::cast).unwrap();
166 let source_map = function.body_source_map(db);
167 for d in function.diagnostics(db) {
168 match d {
169 hir::diagnostics::FunctionDiagnostic::NoSuchField { expr, field } => {
170 if let Some(field) = source_map.field_syntax(expr, field) {
171 let field = field.to_node(&source_file);
172 acc.push(Diagnostic {
173 message: "no such field".into(),
174 range: field.syntax().range(),
175 severity: Severity::Error,
176 fix: None,
177 })
178 }
179 }
180 }
181 }
182}
183
156#[cfg(test)] 184#[cfg(test)]
157mod tests { 185mod tests {
158 use test_utils::assert_eq_text; 186 use test_utils::assert_eq_text;