Skip to content

Commit a6b65cf

Browse files
Merge #8444
8444: Shrink `unlinked-file` diagnostic to 3 characters r=jonas-schievink a=jonas-schievink Fixes #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 <[email protected]>
2 parents 99ed68a + ac980e9 commit a6b65cf

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

crates/ide/src/diagnostics.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use itertools::Itertools;
2020
use rustc_hash::FxHashSet;
2121
use syntax::{
2222
ast::{self, AstNode},
23-
SyntaxNode, SyntaxNodePtr, TextRange,
23+
SyntaxNode, SyntaxNodePtr, TextRange, TextSize,
2424
};
2525
use text_edit::TextEdit;
2626
use unlinked_file::UnlinkedFile;
@@ -159,14 +159,16 @@ pub(crate) fn diagnostics(
159159
);
160160
})
161161
.on::<UnlinkedFile, _>(|d| {
162+
// Limit diagnostic to the first few characters in the file. This matches how VS Code
163+
// renders it with the full span, but on other editors, and is less invasive.
164+
let range = sema.diagnostics_display_range(d.display_source()).range;
165+
let range = range.intersect(TextRange::up_to(TextSize::of("..."))).unwrap_or(range);
166+
162167
// Override severity and mark as unused.
163168
res.borrow_mut().push(
164-
Diagnostic::hint(
165-
sema.diagnostics_display_range(d.display_source()).range,
166-
d.message(),
167-
)
168-
.with_fix(d.fix(&sema))
169-
.with_code(Some(d.code())),
169+
Diagnostic::hint(range, d.message())
170+
.with_fix(d.fix(&sema))
171+
.with_code(Some(d.code())),
170172
);
171173
})
172174
.on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| {

0 commit comments

Comments
 (0)