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>
This commit is contained in:
bors[bot] 2021-04-09 12:24:03 +00:00 committed by GitHub
commit a6b65cf516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,7 @@
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,12 +159,14 @@ 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(),
)
Diagnostic::hint(range, d.message())
.with_fix(d.fix(&sema))
.with_code(Some(d.code())),
);