aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/imp.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-08 11:24:39 +0000
committerAleksey Kladov <[email protected]>2019-02-08 11:34:30 +0000
commit8328e196dd093f85e51420fa27d9d9bcdf65e866 (patch)
tree6fea69cad7871bdf32c18666625c9a9312a6c297 /crates/ra_ide_api/src/imp.rs
parente4a6343e47a7dc87192b762b3b2ebd100240d194 (diff)
move diagnostics to a separate file
Diffstat (limited to 'crates/ra_ide_api/src/imp.rs')
-rw-r--r--crates/ra_ide_api/src/imp.rs93
1 files changed, 0 insertions, 93 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
deleted file mode 100644
index a351c9373..000000000
--- a/crates/ra_ide_api/src/imp.rs
+++ /dev/null
@@ -1,93 +0,0 @@
1use hir::{
2 self, Problem, source_binder
3};
4use ra_ide_api_light::{self, LocalEdit, Severity};
5use ra_db::SourceDatabase;
6
7use crate::{
8 db, Diagnostic, FileId, FilePosition, FileSystemEdit,
9 SourceChange, SourceFileEdit,
10};
11
12impl db::RootDatabase {
13 pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
14 let syntax = self.parse(file_id);
15
16 let mut res = ra_ide_api_light::diagnostics(&syntax)
17 .into_iter()
18 .map(|d| Diagnostic {
19 range: d.range,
20 message: d.msg,
21 severity: d.severity,
22 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
23 })
24 .collect::<Vec<_>>();
25 if let Some(m) = source_binder::module_from_file_id(self, file_id) {
26 for (name_node, problem) in m.problems(self) {
27 let source_root = self.file_source_root(file_id);
28 let diag = match problem {
29 Problem::UnresolvedModule { candidate } => {
30 let create_file = FileSystemEdit::CreateFile {
31 source_root,
32 path: candidate.clone(),
33 };
34 let fix = SourceChange {
35 label: "create module".to_string(),
36 source_file_edits: Vec::new(),
37 file_system_edits: vec![create_file],
38 cursor_position: None,
39 };
40 Diagnostic {
41 range: name_node.range(),
42 message: "unresolved module".to_string(),
43 severity: Severity::Error,
44 fix: Some(fix),
45 }
46 }
47 Problem::NotDirOwner { move_to, candidate } => {
48 let move_file = FileSystemEdit::MoveFile {
49 src: file_id,
50 dst_source_root: source_root,
51 dst_path: move_to.clone(),
52 };
53 let create_file = FileSystemEdit::CreateFile {
54 source_root,
55 path: move_to.join(candidate),
56 };
57 let fix = SourceChange {
58 label: "move file and create module".to_string(),
59 source_file_edits: Vec::new(),
60 file_system_edits: vec![move_file, create_file],
61 cursor_position: None,
62 };
63 Diagnostic {
64 range: name_node.range(),
65 message: "can't declare module at this location".to_string(),
66 severity: Severity::Error,
67 fix: Some(fix),
68 }
69 }
70 };
71 res.push(diag)
72 }
73 };
74 res
75 }
76}
77
78impl SourceChange {
79 pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange {
80 let file_edit = SourceFileEdit {
81 file_id,
82 edit: edit.edit,
83 };
84 SourceChange {
85 label: edit.label,
86 source_file_edits: vec![file_edit],
87 file_system_edits: vec![],
88 cursor_position: edit
89 .cursor_position
90 .map(|offset| FilePosition { offset, file_id }),
91 }
92 }
93}