diff options
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 27d347dbd..6cf5810fa 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -299,10 +299,10 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist { | |||
299 | 299 | ||
300 | #[cfg(test)] | 300 | #[cfg(test)] |
301 | mod tests { | 301 | mod tests { |
302 | use expect_test::{expect, Expect}; | 302 | use expect_test::Expect; |
303 | use ide_assists::AssistResolveStrategy; | 303 | use ide_assists::AssistResolveStrategy; |
304 | use stdx::trim_indent; | 304 | use stdx::trim_indent; |
305 | use test_utils::assert_eq_text; | 305 | use test_utils::{assert_eq_text, extract_annotations}; |
306 | 306 | ||
307 | use crate::{fixture, DiagnosticsConfig}; | 307 | use crate::{fixture, DiagnosticsConfig}; |
308 | 308 | ||
@@ -311,6 +311,7 @@ mod tests { | |||
311 | /// * a diagnostic is produced | 311 | /// * a diagnostic is produced |
312 | /// * the first diagnostic fix trigger range touches the input cursor position | 312 | /// * the first diagnostic fix trigger range touches the input cursor position |
313 | /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied | 313 | /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied |
314 | #[track_caller] | ||
314 | pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { | 315 | pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { |
315 | check_nth_fix(0, ra_fixture_before, ra_fixture_after); | 316 | check_nth_fix(0, ra_fixture_before, ra_fixture_after); |
316 | } | 317 | } |
@@ -325,6 +326,7 @@ mod tests { | |||
325 | } | 326 | } |
326 | } | 327 | } |
327 | 328 | ||
329 | #[track_caller] | ||
328 | fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) { | 330 | fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) { |
329 | let after = trim_indent(ra_fixture_after); | 331 | let after = trim_indent(ra_fixture_after); |
330 | 332 | ||
@@ -396,26 +398,51 @@ mod tests { | |||
396 | expect.assert_debug_eq(&diagnostics) | 398 | expect.assert_debug_eq(&diagnostics) |
397 | } | 399 | } |
398 | 400 | ||
401 | pub(crate) fn check_diagnostics(ra_fixture: &str) { | ||
402 | let (analysis, file_id) = fixture::file(ra_fixture); | ||
403 | let diagnostics = analysis | ||
404 | .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id) | ||
405 | .unwrap(); | ||
406 | |||
407 | let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); | ||
408 | let actual = diagnostics.into_iter().map(|d| (d.range, d.message)).collect::<Vec<_>>(); | ||
409 | assert_eq!(expected, actual); | ||
410 | } | ||
411 | |||
399 | #[test] | 412 | #[test] |
400 | fn test_unresolved_macro_range() { | 413 | fn test_unresolved_macro_range() { |
401 | check_expect( | 414 | check_diagnostics( |
402 | r#"foo::bar!(92);"#, | 415 | r#" |
403 | expect![[r#" | 416 | foo::bar!(92); |
404 | [ | 417 | //^^^ unresolved macro `foo::bar!` |
405 | Diagnostic { | 418 | "#, |
406 | message: "unresolved macro `foo::bar!`", | 419 | ); |
407 | range: 5..8, | 420 | } |
408 | severity: Error, | 421 | |
409 | fixes: None, | 422 | #[test] |
410 | unused: false, | 423 | fn unresolved_import_in_use_tree() { |
411 | code: Some( | 424 | // Only the relevant part of a nested `use` item should be highlighted. |
412 | DiagnosticCode( | 425 | check_diagnostics( |
413 | "unresolved-macro-call", | 426 | r#" |
414 | ), | 427 | use does_exist::{Exists, DoesntExist}; |
415 | ), | 428 | //^^^^^^^^^^^ unresolved import |
416 | }, | 429 | |
417 | ] | 430 | use {does_not_exist::*, does_exist}; |
418 | "#]], | 431 | //^^^^^^^^^^^^^^^^^ unresolved import |
432 | |||
433 | use does_not_exist::{ | ||
434 | a, | ||
435 | //^ unresolved import | ||
436 | b, | ||
437 | //^ unresolved import | ||
438 | c, | ||
439 | //^ unresolved import | ||
440 | }; | ||
441 | |||
442 | mod does_exist { | ||
443 | pub struct Exists; | ||
444 | } | ||
445 | "#, | ||
419 | ); | 446 | ); |
420 | } | 447 | } |
421 | 448 | ||