diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 30 |
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}; | |||
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | use ra_syntax::{ | 4 | use 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 | }; |
9 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 9 | use 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 | ||
163 | fn 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)] |
157 | mod tests { | 185 | mod tests { |
158 | use test_utils::assert_eq_text; | 186 | use test_utils::assert_eq_text; |