about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-09 12:24:03 +0000
committerGitHub <noreply@github.com>2021-04-09 12:24:03 +0000
commita6b65cf5169deb6c7b2c02f50e59234c0924b429 (patch)
tree41a32ae3c0a6a19a1ebf16f58163f8662fd8483e
parent99ed68a109c9f7e0dc6a82ccb5bf854d60943957 (diff)
parentac980e96e57b9db67191cef21f0b84e9133e0bca (diff)
downloadrust-a6b65cf5169deb6c7b2c02f50e59234c0924b429.tar.gz
rust-a6b65cf5169deb6c7b2c02f50e59234c0924b429.zip
Merge #8444
8444: Shrink `unlinked-file` diagnostic to 3 characters r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8442

(the diagnostic fires intentionally on `#[cfg]`d modules, but with this won't cover the whole file)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
-rw-r--r--crates/ide/src/diagnostics.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index dd42116a77c..0ace80a1eac 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -20,7 +20,7 @@ use itertools::Itertools;
 use rustc_hash::FxHashSet;
 use syntax::{
     ast::{self, AstNode},
-    SyntaxNode, SyntaxNodePtr, TextRange,
+    SyntaxNode, SyntaxNodePtr, TextRange, TextSize,
 };
 use text_edit::TextEdit;
 use unlinked_file::UnlinkedFile;
@@ -159,14 +159,16 @@ pub(crate) fn diagnostics(
             );
         })
         .on::<UnlinkedFile, _>(|d| {
+            // Limit diagnostic to the first few characters in the file. This matches how VS Code
+            // renders it with the full span, but on other editors, and is less invasive.
+            let range = sema.diagnostics_display_range(d.display_source()).range;
+            let range = range.intersect(TextRange::up_to(TextSize::of("..."))).unwrap_or(range);
+
             // Override severity and mark as unused.
             res.borrow_mut().push(
-                Diagnostic::hint(
-                    sema.diagnostics_display_range(d.display_source()).range,
-                    d.message(),
-                )
-                .with_fix(d.fix(&sema))
-                .with_code(Some(d.code())),
+                Diagnostic::hint(range, d.message())
+                    .with_fix(d.fix(&sema))
+                    .with_code(Some(d.code())),
             );
         })
         .on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| {