diagnostics is now a function

This commit is contained in:
Aleksey Kladov 2019-02-08 14:30:21 +03:00
parent 8328e196dd
commit 884f04670a
2 changed files with 62 additions and 64 deletions

View file

@ -2,11 +2,10 @@ use hir::{Problem, source_binder};
use ra_ide_api_light::Severity; use ra_ide_api_light::Severity;
use ra_db::SourceDatabase; use ra_db::SourceDatabase;
use crate::{db, Diagnostic, FileId, FileSystemEdit, SourceChange}; use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, db::RootDatabase};
impl db::RootDatabase { pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> {
pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { let syntax = db.parse(file_id);
let syntax = self.parse(file_id);
let mut res = ra_ide_api_light::diagnostics(&syntax) let mut res = ra_ide_api_light::diagnostics(&syntax)
.into_iter() .into_iter()
@ -17,9 +16,9 @@ impl db::RootDatabase {
fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if let Some(m) = source_binder::module_from_file_id(self, file_id) { if let Some(m) = source_binder::module_from_file_id(db, file_id) {
for (name_node, problem) in m.problems(self) { for (name_node, problem) in m.problems(db) {
let source_root = self.file_source_root(file_id); let source_root = db.file_source_root(file_id);
let diag = match problem { let diag = match problem {
Problem::UnresolvedModule { candidate } => { Problem::UnresolvedModule { candidate } => {
let create_file = FileSystemEdit::CreateFile { let create_file = FileSystemEdit::CreateFile {
@ -67,5 +66,4 @@ impl db::RootDatabase {
} }
}; };
res res
}
} }

View file

@ -52,10 +52,10 @@ use crate::{
}; };
pub use crate::{ pub use crate::{
change::{AnalysisChange, LibraryData},
completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, completion::{CompletionItem, CompletionItemKind, InsertTextFormat},
runnables::{Runnable, RunnableKind}, runnables::{Runnable, RunnableKind},
navigation_target::NavigationTarget, navigation_target::NavigationTarget,
change::{AnalysisChange, LibraryData},
}; };
pub use ra_ide_api_light::{ pub use ra_ide_api_light::{
Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit,
@ -373,7 +373,7 @@ impl Analysis {
/// Computes the set of diagnostics for the given file. /// Computes the set of diagnostics for the given file.
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
self.with_db(|db| db.diagnostics(file_id)) self.with_db(|db| diagnostics::diagnostics(db, file_id))
} }
/// Computes the type of the expression at the given position. /// Computes the type of the expression at the given position.