From ac980e96e57b9db67191cef21f0b84e9133e0bca Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Apr 2021 14:22:38 +0200 Subject: Shrink `unlinked-file` diagnostic to 3 characters --- crates/ide/src/diagnostics.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index dd42116a7..0ace80a1e 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::(|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::(|d| { -- cgit v1.2.3