]> git.lizzy.rs Git - rust.git/commitdiff
Better naming and docs
authorKirill Bulatov <mail4score@gmail.com>
Tue, 11 Aug 2020 14:15:11 +0000 (17:15 +0300)
committerKirill Bulatov <mail4score@gmail.com>
Tue, 11 Aug 2020 14:52:05 +0000 (17:52 +0300)
crates/ra_hir/src/semantics.rs
crates/ra_hir_def/src/diagnostics.rs
crates/ra_hir_expand/src/diagnostics.rs
crates/ra_hir_ty/src/diagnostics.rs
crates/ra_ide/src/diagnostics.rs
crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs

index 2dfe69039fb72a325130a5df12b2c7affee7ddfa..e3c417b41be78c91a6fb98fef36ba73e613d3d1a 100644 (file)
@@ -138,8 +138,8 @@ pub fn original_range(&self, node: &SyntaxNode) -> FileRange {
         self.imp.original_range(node)
     }
 
-    pub fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
-        self.imp.diagnostics_presentation_range(diagnostics)
+    pub fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
+        self.imp.diagnostics_display_range(diagnostics)
     }
 
     pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
@@ -369,8 +369,8 @@ fn original_range(&self, node: &SyntaxNode) -> FileRange {
         original_range(self.db, node.as_ref())
     }
 
-    fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
-        let src = diagnostics.presentation();
+    fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
+        let src = diagnostics.display_source();
         let root = self.db.parse_or_expand(src.file_id).unwrap();
         let node = src.value.to_node(&root);
         self.cache(root, src.file_id);
index 9435c72544b6b3920ce1e67c4d6859982497ca4d..71d177070dd6c91ebfa71cf941fe7ebf47bb9b1f 100644 (file)
@@ -18,7 +18,7 @@ impl Diagnostic for UnresolvedModule {
     fn message(&self) -> String {
         "unresolved module".to_string()
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile::new(self.file, self.decl.clone().into())
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
index cc7dc3af22c22b2369a21c08f6fb1851e006b632..b138500e7342533b6a9d65684760e82fc6ace215 100644 (file)
@@ -22,8 +22,8 @@
 
 pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
     fn message(&self) -> String;
-    /// A presentation source of the diagnostics, to use in highlighting and similar actions
-    fn presentation(&self) -> InFile<SyntaxNodePtr>;
+    /// Used in highlighting and related purposes
+    fn display_source(&self) -> InFile<SyntaxNodePtr>;
     fn as_any(&self) -> &(dyn Any + Send + 'static);
     fn is_experimental(&self) -> bool {
         false
index 24435e8a71f8fdd2234b2e641e95ec64166be51e..7ab7f79db66521019fb39b3ac1fdd48f0bf270f5 100644 (file)
@@ -37,7 +37,7 @@ fn message(&self) -> String {
         "no such field".to_string()
     }
 
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile::new(self.file, self.field.clone().into())
     }
 
@@ -63,7 +63,7 @@ fn message(&self) -> String {
         buf
     }
 
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile {
             file_id: self.file,
             value: self
@@ -95,13 +95,15 @@ fn message(&self) -> String {
         }
         buf
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
-        let value = self
-            .field_list_parent_path
-            .clone()
-            .map(SyntaxNodePtr::from)
-            .unwrap_or_else(|| self.field_list_parent.clone().into());
-        InFile { file_id: self.file, value }
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
+        InFile {
+            file_id: self.file,
+            value: self
+                .field_list_parent_path
+                .clone()
+                .map(SyntaxNodePtr::from)
+                .unwrap_or_else(|| self.field_list_parent.clone().into()),
+        }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
         self
@@ -119,7 +121,7 @@ impl Diagnostic for MissingMatchArms {
     fn message(&self) -> String {
         String::from("Missing match arm")
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.match_expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -137,7 +139,7 @@ impl Diagnostic for MissingOkInTailExpr {
     fn message(&self) -> String {
         "wrap return expression in Ok".to_string()
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -155,7 +157,7 @@ impl Diagnostic for BreakOutsideOfLoop {
     fn message(&self) -> String {
         "break outside of loop".to_string()
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -173,7 +175,7 @@ impl Diagnostic for MissingUnsafe {
     fn message(&self) -> String {
         format!("This operation is unsafe and requires an unsafe function or block")
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -194,7 +196,7 @@ fn message(&self) -> String {
         let s = if self.expected == 1 { "" } else { "s" };
         format!("Expected {} argument{}, found {}", self.expected, s, self.found)
     }
-    fn presentation(&self) -> InFile<SyntaxNodePtr> {
+    fn display_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.call_expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -256,12 +258,11 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
 
         let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default();
         db.diagnostics(|d| {
+            let src = d.display_source();
+            let root = db.parse_or_expand(src.file_id).unwrap();
             // FIXME: macros...
-            let diagnostics_presentation = d.presentation();
-            let root = db.parse_or_expand(diagnostics_presentation.file_id).unwrap();
-
-            let file_id = diagnostics_presentation.file_id.original_file(&db);
-            let range = diagnostics_presentation.value.to_node(&root).text_range();
+            let file_id = src.file_id.original_file(&db);
+            let range = src.value.to_node(&root).text_range();
             let message = d.message().to_owned();
             actual.entry(file_id).or_default().push((range, message));
         });
index 757b76fd40f097487f41ca8f642e0533eb18da2b..1046d7ab374502218f9a8dd2f5d6badc41aabc1c 100644 (file)
@@ -183,7 +183,7 @@ mod tests {
     /// Takes a multi-file input fixture with annotated cursor positions,
     /// and checks that:
     ///  * a diagnostic is produced
-    ///  * this diagnostic fix touches the input cursor position
+    ///  * this diagnostic fix trigger range touches the input cursor position
     ///  * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
     fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
         let after = trim_indent(ra_fixture_after);
index 57b54a61edb4fd4ae9e841bd3f42829caf37eeec..f7c73773f3ac9cecdfaf111243df64f3cae09b58 100644 (file)
@@ -1,4 +1,5 @@
-//! Provides a way to attach fix actions to the
+//! Provides a way to attach fixes to the diagnostics.
+//! The same module also has all curret custom fixes for the diagnostics implemented.
 use crate::Fix;
 use ast::{edit::IndentLevel, make};
 use hir::{