diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-08 11:37:05 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-08 11:37:05 +0000 |
commit | b5fc999e7dafa8217d77088ae10bff96e767a3e9 (patch) | |
tree | 7fb47d6afa2eca87d2cd330e8e39af2ce3615dd5 /crates/ra_ide_api/src/diagnostics.rs | |
parent | 9a1d2a46c249fa81294c156b9e23b624e14495cd (diff) | |
parent | 884f04670aea239f06fe5b6ff7a9f2073034f8bc (diff) |
Merge #765
765: Jettison `imp` module r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/diagnostics.rs')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs new file mode 100644 index 000000000..a499ac7c6 --- /dev/null +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -0,0 +1,69 @@ | |||
1 | use hir::{Problem, source_binder}; | ||
2 | use ra_ide_api_light::Severity; | ||
3 | use ra_db::SourceDatabase; | ||
4 | |||
5 | use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, db::RootDatabase}; | ||
6 | |||
7 | pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> { | ||
8 | let syntax = db.parse(file_id); | ||
9 | |||
10 | let mut res = ra_ide_api_light::diagnostics(&syntax) | ||
11 | .into_iter() | ||
12 | .map(|d| Diagnostic { | ||
13 | range: d.range, | ||
14 | message: d.msg, | ||
15 | severity: d.severity, | ||
16 | fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), | ||
17 | }) | ||
18 | .collect::<Vec<_>>(); | ||
19 | if let Some(m) = source_binder::module_from_file_id(db, file_id) { | ||
20 | for (name_node, problem) in m.problems(db) { | ||
21 | let source_root = db.file_source_root(file_id); | ||
22 | let diag = match problem { | ||
23 | Problem::UnresolvedModule { candidate } => { | ||
24 | let create_file = FileSystemEdit::CreateFile { | ||
25 | source_root, | ||
26 | path: candidate.clone(), | ||
27 | }; | ||
28 | let fix = SourceChange { | ||
29 | label: "create module".to_string(), | ||
30 | source_file_edits: Vec::new(), | ||
31 | file_system_edits: vec![create_file], | ||
32 | cursor_position: None, | ||
33 | }; | ||
34 | Diagnostic { | ||
35 | range: name_node.range(), | ||
36 | message: "unresolved module".to_string(), | ||
37 | severity: Severity::Error, | ||
38 | fix: Some(fix), | ||
39 | } | ||
40 | } | ||
41 | Problem::NotDirOwner { move_to, candidate } => { | ||
42 | let move_file = FileSystemEdit::MoveFile { | ||
43 | src: file_id, | ||
44 | dst_source_root: source_root, | ||
45 | dst_path: move_to.clone(), | ||
46 | }; | ||
47 | let create_file = FileSystemEdit::CreateFile { | ||
48 | source_root, | ||
49 | path: move_to.join(candidate), | ||
50 | }; | ||
51 | let fix = SourceChange { | ||
52 | label: "move file and create module".to_string(), | ||
53 | source_file_edits: Vec::new(), | ||
54 | file_system_edits: vec![move_file, create_file], | ||
55 | cursor_position: None, | ||
56 | }; | ||
57 | Diagnostic { | ||
58 | range: name_node.range(), | ||
59 | message: "can't declare module at this location".to_string(), | ||
60 | severity: Severity::Error, | ||
61 | fix: Some(fix), | ||
62 | } | ||
63 | } | ||
64 | }; | ||
65 | res.push(diag) | ||
66 | } | ||
67 | }; | ||
68 | res | ||
69 | } | ||