Skip to content

Commit 884f046

Browse files
committed
diagnostics is now a function
1 parent 8328e19 commit 884f046

File tree

2 files changed

+62
-64
lines changed

2 files changed

+62
-64
lines changed

crates/ra_ide_api/src/diagnostics.rs

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,68 @@ use hir::{Problem, source_binder};
22
use ra_ide_api_light::Severity;
33
use ra_db::SourceDatabase;
44

5-
use crate::{db, Diagnostic, FileId, FileSystemEdit, SourceChange};
5+
use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, db::RootDatabase};
66

7-
impl db::RootDatabase {
8-
pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
9-
let syntax = self.parse(file_id);
7+
pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> {
8+
let syntax = db.parse(file_id);
109

11-
let mut res = ra_ide_api_light::diagnostics(&syntax)
12-
.into_iter()
13-
.map(|d| Diagnostic {
14-
range: d.range,
15-
message: d.msg,
16-
severity: d.severity,
17-
fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
18-
})
19-
.collect::<Vec<_>>();
20-
if let Some(m) = source_binder::module_from_file_id(self, file_id) {
21-
for (name_node, problem) in m.problems(self) {
22-
let source_root = self.file_source_root(file_id);
23-
let diag = match problem {
24-
Problem::UnresolvedModule { candidate } => {
25-
let create_file = FileSystemEdit::CreateFile {
26-
source_root,
27-
path: candidate.clone(),
28-
};
29-
let fix = SourceChange {
30-
label: "create module".to_string(),
31-
source_file_edits: Vec::new(),
32-
file_system_edits: vec![create_file],
33-
cursor_position: None,
34-
};
35-
Diagnostic {
36-
range: name_node.range(),
37-
message: "unresolved module".to_string(),
38-
severity: Severity::Error,
39-
fix: Some(fix),
40-
}
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),
4139
}
42-
Problem::NotDirOwner { move_to, candidate } => {
43-
let move_file = FileSystemEdit::MoveFile {
44-
src: file_id,
45-
dst_source_root: source_root,
46-
dst_path: move_to.clone(),
47-
};
48-
let create_file = FileSystemEdit::CreateFile {
49-
source_root,
50-
path: move_to.join(candidate),
51-
};
52-
let fix = SourceChange {
53-
label: "move file and create module".to_string(),
54-
source_file_edits: Vec::new(),
55-
file_system_edits: vec![move_file, create_file],
56-
cursor_position: None,
57-
};
58-
Diagnostic {
59-
range: name_node.range(),
60-
message: "can't declare module at this location".to_string(),
61-
severity: Severity::Error,
62-
fix: Some(fix),
63-
}
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),
6462
}
65-
};
66-
res.push(diag)
67-
}
68-
};
69-
res
70-
}
63+
}
64+
};
65+
res.push(diag)
66+
}
67+
};
68+
res
7169
}

crates/ra_ide_api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ use crate::{
5252
};
5353

5454
pub use crate::{
55+
change::{AnalysisChange, LibraryData},
5556
completion::{CompletionItem, CompletionItemKind, InsertTextFormat},
5657
runnables::{Runnable, RunnableKind},
5758
navigation_target::NavigationTarget,
58-
change::{AnalysisChange, LibraryData},
5959
};
6060
pub use ra_ide_api_light::{
6161
Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit,
@@ -373,7 +373,7 @@ impl Analysis {
373373

374374
/// Computes the set of diagnostics for the given file.
375375
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))
377377
}
378378

379379
/// Computes the type of the expression at the given position.

0 commit comments

Comments
 (0)