diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 122 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 4 |
2 files changed, 62 insertions, 64 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index c6ca91af8..a499ac7c6 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -2,70 +2,68 @@ use hir::{Problem, source_binder}; | |||
2 | use ra_ide_api_light::Severity; | 2 | use ra_ide_api_light::Severity; |
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | 4 | ||
5 | use crate::{db, Diagnostic, FileId, FileSystemEdit, SourceChange}; | 5 | use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, db::RootDatabase}; |
6 | 6 | ||
7 | impl db::RootDatabase { | 7 | pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> { |
8 | pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | 8 | let syntax = db.parse(file_id); |
9 | let syntax = self.parse(file_id); | ||
10 | 9 | ||
11 | let mut res = ra_ide_api_light::diagnostics(&syntax) | 10 | let mut res = ra_ide_api_light::diagnostics(&syntax) |
12 | .into_iter() | 11 | .into_iter() |
13 | .map(|d| Diagnostic { | 12 | .map(|d| Diagnostic { |
14 | range: d.range, | 13 | range: d.range, |
15 | message: d.msg, | 14 | message: d.msg, |
16 | severity: d.severity, | 15 | severity: d.severity, |
17 | fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), | 16 | fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), |
18 | }) | 17 | }) |
19 | .collect::<Vec<_>>(); | 18 | .collect::<Vec<_>>(); |
20 | if let Some(m) = source_binder::module_from_file_id(self, file_id) { | 19 | if let Some(m) = source_binder::module_from_file_id(db, file_id) { |
21 | for (name_node, problem) in m.problems(self) { | 20 | for (name_node, problem) in m.problems(db) { |
22 | let source_root = self.file_source_root(file_id); | 21 | let source_root = db.file_source_root(file_id); |
23 | let diag = match problem { | 22 | let diag = match problem { |
24 | Problem::UnresolvedModule { candidate } => { | 23 | Problem::UnresolvedModule { candidate } => { |
25 | let create_file = FileSystemEdit::CreateFile { | 24 | let create_file = FileSystemEdit::CreateFile { |
26 | source_root, | 25 | source_root, |
27 | path: candidate.clone(), | 26 | path: candidate.clone(), |
28 | }; | 27 | }; |
29 | let fix = SourceChange { | 28 | let fix = SourceChange { |
30 | label: "create module".to_string(), | 29 | label: "create module".to_string(), |
31 | source_file_edits: Vec::new(), | 30 | source_file_edits: Vec::new(), |
32 | file_system_edits: vec![create_file], | 31 | file_system_edits: vec![create_file], |
33 | cursor_position: None, | 32 | cursor_position: None, |
34 | }; | 33 | }; |
35 | Diagnostic { | 34 | Diagnostic { |
36 | range: name_node.range(), | 35 | range: name_node.range(), |
37 | message: "unresolved module".to_string(), | 36 | message: "unresolved module".to_string(), |
38 | severity: Severity::Error, | 37 | severity: Severity::Error, |
39 | fix: Some(fix), | 38 | fix: Some(fix), |
40 | } | ||
41 | } | 39 | } |
42 | Problem::NotDirOwner { move_to, candidate } => { | 40 | } |
43 | let move_file = FileSystemEdit::MoveFile { | 41 | Problem::NotDirOwner { move_to, candidate } => { |
44 | src: file_id, | 42 | let move_file = FileSystemEdit::MoveFile { |
45 | dst_source_root: source_root, | 43 | src: file_id, |
46 | dst_path: move_to.clone(), | 44 | dst_source_root: source_root, |
47 | }; | 45 | dst_path: move_to.clone(), |
48 | let create_file = FileSystemEdit::CreateFile { | 46 | }; |
49 | source_root, | 47 | let create_file = FileSystemEdit::CreateFile { |
50 | path: move_to.join(candidate), | 48 | source_root, |
51 | }; | 49 | path: move_to.join(candidate), |
52 | let fix = SourceChange { | 50 | }; |
53 | label: "move file and create module".to_string(), | 51 | let fix = SourceChange { |
54 | source_file_edits: Vec::new(), | 52 | label: "move file and create module".to_string(), |
55 | file_system_edits: vec![move_file, create_file], | 53 | source_file_edits: Vec::new(), |
56 | cursor_position: None, | 54 | file_system_edits: vec![move_file, create_file], |
57 | }; | 55 | cursor_position: None, |
58 | Diagnostic { | 56 | }; |
59 | range: name_node.range(), | 57 | Diagnostic { |
60 | message: "can't declare module at this location".to_string(), | 58 | range: name_node.range(), |
61 | severity: Severity::Error, | 59 | message: "can't declare module at this location".to_string(), |
62 | fix: Some(fix), | 60 | severity: Severity::Error, |
63 | } | 61 | fix: Some(fix), |
64 | } | 62 | } |
65 | }; | 63 | } |
66 | res.push(diag) | 64 | }; |
67 | } | 65 | res.push(diag) |
68 | }; | 66 | } |
69 | res | 67 | }; |
70 | } | 68 | res |
71 | } | 69 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 312b11a82..1f43b7623 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -52,10 +52,10 @@ use crate::{ | |||
52 | }; | 52 | }; |
53 | 53 | ||
54 | pub use crate::{ | 54 | pub use crate::{ |
55 | change::{AnalysisChange, LibraryData}, | ||
55 | completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, | 56 | completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, |
56 | runnables::{Runnable, RunnableKind}, | 57 | runnables::{Runnable, RunnableKind}, |
57 | navigation_target::NavigationTarget, | 58 | navigation_target::NavigationTarget, |
58 | change::{AnalysisChange, LibraryData}, | ||
59 | }; | 59 | }; |
60 | pub use ra_ide_api_light::{ | 60 | pub use ra_ide_api_light::{ |
61 | Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, | 61 | Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, |
@@ -373,7 +373,7 @@ impl Analysis { | |||
373 | 373 | ||
374 | /// Computes the set of diagnostics for the given file. | 374 | /// Computes the set of diagnostics for the given file. |
375 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 375 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
376 | self.with_db(|db| db.diagnostics(file_id)) | 376 | self.with_db(|db| diagnostics::diagnostics(db, file_id)) |
377 | } | 377 | } |
378 | 378 | ||
379 | /// Computes the type of the expression at the given position. | 379 | /// Computes the type of the expression at the given position. |