diff options
author | Aleksey Kladov <[email protected]> | 2019-03-23 15:35:14 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-25 07:52:50 +0000 |
commit | 3fb88e95aa5e122a521beec766d5b1264ca4de3b (patch) | |
tree | 17e5815f78f81f04fd462605288e09e82c8caee8 /crates/ra_ide_api | |
parent | fcca35969dd7c63a83ee34c4ce7d54cefdb72bbe (diff) |
switch modules to new diagnostics
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 943fd2f53..254342c0a 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use hir::{Problem, source_binder}; | 2 | use hir::{source_binder, diagnostics::Diagnostic as _}; |
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, |
@@ -28,7 +28,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
28 | } | 28 | } |
29 | 29 | ||
30 | if let Some(m) = source_binder::module_from_file_id(db, file_id) { | 30 | if let Some(m) = source_binder::module_from_file_id(db, file_id) { |
31 | check_module(&mut res, db, file_id, m); | 31 | check_module(&mut res, db, m); |
32 | }; | 32 | }; |
33 | res | 33 | res |
34 | } | 34 | } |
@@ -128,46 +128,40 @@ fn check_struct_shorthand_initialization( | |||
128 | Some(()) | 128 | Some(()) |
129 | } | 129 | } |
130 | 130 | ||
131 | fn check_module( | 131 | fn check_module(acc: &mut Vec<Diagnostic>, db: &RootDatabase, module: hir::Module) { |
132 | acc: &mut Vec<Diagnostic>, | 132 | let mut diagnostics = hir::diagnostics::Diagnostics::default(); |
133 | db: &RootDatabase, | 133 | module.diagnostics(db, &mut diagnostics); |
134 | file_id: FileId, | ||
135 | module: hir::Module, | ||
136 | ) { | ||
137 | for decl in module.declarations(db) { | 134 | for decl in module.declarations(db) { |
138 | match decl { | 135 | match decl { |
139 | hir::ModuleDef::Function(f) => check_function(acc, db, f), | 136 | hir::ModuleDef::Function(f) => f.diagnostics(db, &mut diagnostics), |
140 | _ => (), | 137 | _ => (), |
141 | } | 138 | } |
142 | } | 139 | } |
143 | 140 | ||
144 | let source_root = db.file_source_root(file_id); | 141 | for d in diagnostics.iter() { |
145 | for (name_node, problem) in module.problems(db) { | 142 | if let Some(d) = d.downcast_ref::<hir::diagnostics::UnresolvedModule>() { |
146 | let diag = match problem { | 143 | let source_root = db.file_source_root(d.file().original_file(db)); |
147 | Problem::UnresolvedModule { candidate } => { | 144 | let create_file = FileSystemEdit::CreateFile { source_root, path: d.candidate.clone() }; |
148 | let create_file = | 145 | let fix = SourceChange { |
149 | FileSystemEdit::CreateFile { source_root, path: candidate.clone() }; | 146 | label: "create module".to_string(), |
150 | let fix = SourceChange::file_system_edit("create module", create_file); | 147 | source_file_edits: Vec::new(), |
151 | Diagnostic { | 148 | file_system_edits: vec![create_file], |
152 | range: name_node.range(), | 149 | cursor_position: None, |
153 | message: "unresolved module".to_string(), | 150 | }; |
154 | severity: Severity::Error, | 151 | acc.push(Diagnostic { |
155 | fix: Some(fix), | 152 | range: d.syntax_node().range(), |
156 | } | 153 | message: d.message(), |
157 | } | 154 | severity: Severity::Error, |
158 | }; | 155 | fix: Some(fix), |
159 | acc.push(diag) | 156 | }) |
160 | } | 157 | } else { |
161 | } | 158 | acc.push(Diagnostic { |
162 | 159 | message: d.message(), | |
163 | fn check_function(acc: &mut Vec<Diagnostic>, db: &RootDatabase, function: hir::Function) { | 160 | range: d.syntax_node().range(), |
164 | for d in function.diagnostics(db).iter() { | 161 | severity: Severity::Error, |
165 | acc.push(Diagnostic { | 162 | fix: None, |
166 | message: d.message(), | 163 | }) |
167 | range: d.syntax_node().range(), | 164 | } |
168 | severity: Severity::Error, | ||
169 | fix: None, | ||
170 | }) | ||
171 | } | 165 | } |
172 | } | 166 | } |
173 | 167 | ||