aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-23 21:31:59 +0100
committerAleksey Kladov <[email protected]>2021-05-25 15:49:59 +0100
commit5c9f31d4c28478b4373e6cf5ec155745c840ee3f (patch)
tree6d105121d271c7532170875feafaadcd7ad500ba /crates/ide
parentb7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2 (diff)
internal: move diagnostics to hir
The idea here is to eventually get rid of `dyn Diagnostic` and `DiagnosticSink` infrastructure altogether, and just have a `enum hir::Diagnostic` instead. The problem with `dyn Diagnostic` is that it is defined in the lowest level of the stack (hir_expand), but is used by the highest level (ide). As a first step, we free hir_expand and hir_def from `dyn Diagnostic` and kick the can up to `hir_ty`, as an intermediate state. The plan is then to move DiagnosticSink similarly to the hir crate, and, as final third step, remove its usage from the ide. One currently unsolved problem is testing. You can notice that the test which checks precise diagnostic ranges, unresolved_import_in_use_tree, was moved to the ide layer. Logically, only IDE should have the infra to render a specific range. At the same time, the range is determined with the data produced in hir_def and hir crates, so this layering is rather unfortunate. Working on hir_def shouldn't require compiling `ide` for testing.
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs65
1 files changed, 45 insertions, 20 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 27d347dbd..dcac7c76d 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)]
301mod tests { 301mod 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
@@ -396,26 +396,51 @@ mod tests {
396 expect.assert_debug_eq(&diagnostics) 396 expect.assert_debug_eq(&diagnostics)
397 } 397 }
398 398
399 pub(crate) fn check_diagnostics(ra_fixture: &str) {
400 let (analysis, file_id) = fixture::file(ra_fixture);
401 let diagnostics = analysis
402 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id)
403 .unwrap();
404
405 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
406 let actual = diagnostics.into_iter().map(|d| (d.range, d.message)).collect::<Vec<_>>();
407 assert_eq!(expected, actual);
408 }
409
399 #[test] 410 #[test]
400 fn test_unresolved_macro_range() { 411 fn test_unresolved_macro_range() {
401 check_expect( 412 check_diagnostics(
402 r#"foo::bar!(92);"#, 413 r#"
403 expect![[r#" 414foo::bar!(92);
404 [ 415 //^^^ unresolved macro `foo::bar!`
405 Diagnostic { 416"#,
406 message: "unresolved macro `foo::bar!`", 417 );
407 range: 5..8, 418 }
408 severity: Error, 419
409 fixes: None, 420 #[test]
410 unused: false, 421 fn unresolved_import_in_use_tree() {
411 code: Some( 422 // Only the relevant part of a nested `use` item should be highlighted.
412 DiagnosticCode( 423 check_diagnostics(
413 "unresolved-macro-call", 424 r#"
414 ), 425use does_exist::{Exists, DoesntExist};
415 ), 426 //^^^^^^^^^^^ unresolved import
416 }, 427
417 ] 428use {does_not_exist::*, does_exist};
418 "#]], 429 //^^^^^^^^^^^^^^^^^ unresolved import
430
431use does_not_exist::{
432 a,
433 //^ unresolved import
434 b,
435 //^ unresolved import
436 c,
437 //^ unresolved import
438};
439
440mod does_exist {
441 pub struct Exists;
442}
443"#,
419 ); 444 );
420 } 445 }
421 446