From 884f04670aea239f06fe5b6ff7a9f2073034f8bc Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Fri, 8 Feb 2019 14:30:21 +0300
Subject: diagnostics is now a function

---
 crates/ra_ide_api/src/diagnostics.rs | 122 +++++++++++++++++------------------
 crates/ra_ide_api/src/lib.rs         |   4 +-
 2 files changed, 62 insertions(+), 64 deletions(-)

(limited to 'crates/ra_ide_api/src')

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};
 use ra_ide_api_light::Severity;
 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(&self, file_id: FileId) -> Vec<Diagnostic> {
-        let syntax = self.parse(file_id);
+pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> {
+    let syntax = db.parse(file_id);
 
-        let mut res = ra_ide_api_light::diagnostics(&syntax)
-            .into_iter()
-            .map(|d| Diagnostic {
-                range: d.range,
-                message: d.msg,
-                severity: d.severity,
-                fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
-            })
-            .collect::<Vec<_>>();
-        if let Some(m) = source_binder::module_from_file_id(self, file_id) {
-            for (name_node, problem) in m.problems(self) {
-                let source_root = self.file_source_root(file_id);
-                let diag = match problem {
-                    Problem::UnresolvedModule { candidate } => {
-                        let create_file = FileSystemEdit::CreateFile {
-                            source_root,
-                            path: candidate.clone(),
-                        };
-                        let fix = SourceChange {
-                            label: "create module".to_string(),
-                            source_file_edits: Vec::new(),
-                            file_system_edits: vec![create_file],
-                            cursor_position: None,
-                        };
-                        Diagnostic {
-                            range: name_node.range(),
-                            message: "unresolved module".to_string(),
-                            severity: Severity::Error,
-                            fix: Some(fix),
-                        }
+    let mut res = ra_ide_api_light::diagnostics(&syntax)
+        .into_iter()
+        .map(|d| Diagnostic {
+            range: d.range,
+            message: d.msg,
+            severity: d.severity,
+            fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
+        })
+        .collect::<Vec<_>>();
+    if let Some(m) = source_binder::module_from_file_id(db, file_id) {
+        for (name_node, problem) in m.problems(db) {
+            let source_root = db.file_source_root(file_id);
+            let diag = match problem {
+                Problem::UnresolvedModule { candidate } => {
+                    let create_file = FileSystemEdit::CreateFile {
+                        source_root,
+                        path: candidate.clone(),
+                    };
+                    let fix = SourceChange {
+                        label: "create module".to_string(),
+                        source_file_edits: Vec::new(),
+                        file_system_edits: vec![create_file],
+                        cursor_position: None,
+                    };
+                    Diagnostic {
+                        range: name_node.range(),
+                        message: "unresolved module".to_string(),
+                        severity: Severity::Error,
+                        fix: Some(fix),
                     }
-                    Problem::NotDirOwner { move_to, candidate } => {
-                        let move_file = FileSystemEdit::MoveFile {
-                            src: file_id,
-                            dst_source_root: source_root,
-                            dst_path: move_to.clone(),
-                        };
-                        let create_file = FileSystemEdit::CreateFile {
-                            source_root,
-                            path: move_to.join(candidate),
-                        };
-                        let fix = SourceChange {
-                            label: "move file and create module".to_string(),
-                            source_file_edits: Vec::new(),
-                            file_system_edits: vec![move_file, create_file],
-                            cursor_position: None,
-                        };
-                        Diagnostic {
-                            range: name_node.range(),
-                            message: "can't declare module at this location".to_string(),
-                            severity: Severity::Error,
-                            fix: Some(fix),
-                        }
+                }
+                Problem::NotDirOwner { move_to, candidate } => {
+                    let move_file = FileSystemEdit::MoveFile {
+                        src: file_id,
+                        dst_source_root: source_root,
+                        dst_path: move_to.clone(),
+                    };
+                    let create_file = FileSystemEdit::CreateFile {
+                        source_root,
+                        path: move_to.join(candidate),
+                    };
+                    let fix = SourceChange {
+                        label: "move file and create module".to_string(),
+                        source_file_edits: Vec::new(),
+                        file_system_edits: vec![move_file, create_file],
+                        cursor_position: None,
+                    };
+                    Diagnostic {
+                        range: name_node.range(),
+                        message: "can't declare module at this location".to_string(),
+                        severity: Severity::Error,
+                        fix: Some(fix),
                     }
-                };
-                res.push(diag)
-            }
-        };
-        res
-    }
+                }
+            };
+            res.push(diag)
+        }
+    };
+    res
 }
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::{
 };
 
 pub use crate::{
+    change::{AnalysisChange, LibraryData},
     completion::{CompletionItem, CompletionItemKind, InsertTextFormat},
     runnables::{Runnable, RunnableKind},
     navigation_target::NavigationTarget,
-    change::{AnalysisChange, LibraryData},
 };
 pub use ra_ide_api_light::{
     Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit,
@@ -373,7 +373,7 @@ impl Analysis {
 
     /// Computes the set of diagnostics for the given file.
     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.
-- 
cgit v1.2.3