aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs43
1 files changed, 31 insertions, 12 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 1c911a8b2..b14f908b7 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -15,6 +15,7 @@ use hir::{
15 diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder}, 15 diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder},
16 InFile, Semantics, 16 InFile, Semantics,
17}; 17};
18use ide_assists::AssistResolveStrategy;
18use ide_db::{base_db::SourceDatabase, RootDatabase}; 19use ide_db::{base_db::SourceDatabase, RootDatabase};
19use itertools::Itertools; 20use itertools::Itertools;
20use rustc_hash::FxHashSet; 21use rustc_hash::FxHashSet;
@@ -84,7 +85,7 @@ pub struct DiagnosticsConfig {
84pub(crate) fn diagnostics( 85pub(crate) fn diagnostics(
85 db: &RootDatabase, 86 db: &RootDatabase,
86 config: &DiagnosticsConfig, 87 config: &DiagnosticsConfig,
87 resolve: bool, 88 resolve: &AssistResolveStrategy,
88 file_id: FileId, 89 file_id: FileId,
89) -> Vec<Diagnostic> { 90) -> Vec<Diagnostic> {
90 let _p = profile::span("diagnostics"); 91 let _p = profile::span("diagnostics");
@@ -212,7 +213,7 @@ pub(crate) fn diagnostics(
212fn diagnostic_with_fix<D: DiagnosticWithFix>( 213fn diagnostic_with_fix<D: DiagnosticWithFix>(
213 d: &D, 214 d: &D,
214 sema: &Semantics<RootDatabase>, 215 sema: &Semantics<RootDatabase>,
215 resolve: bool, 216 resolve: &AssistResolveStrategy,
216) -> Diagnostic { 217) -> Diagnostic {
217 Diagnostic::error(sema.diagnostics_display_range(d.display_source()).range, d.message()) 218 Diagnostic::error(sema.diagnostics_display_range(d.display_source()).range, d.message())
218 .with_fix(d.fix(&sema, resolve)) 219 .with_fix(d.fix(&sema, resolve))
@@ -222,7 +223,7 @@ fn diagnostic_with_fix<D: DiagnosticWithFix>(
222fn warning_with_fix<D: DiagnosticWithFix>( 223fn warning_with_fix<D: DiagnosticWithFix>(
223 d: &D, 224 d: &D,
224 sema: &Semantics<RootDatabase>, 225 sema: &Semantics<RootDatabase>,
225 resolve: bool, 226 resolve: &AssistResolveStrategy,
226) -> Diagnostic { 227) -> Diagnostic {
227 Diagnostic::hint(sema.diagnostics_display_range(d.display_source()).range, d.message()) 228 Diagnostic::hint(sema.diagnostics_display_range(d.display_source()).range, d.message())
228 .with_fix(d.fix(&sema, resolve)) 229 .with_fix(d.fix(&sema, resolve))
@@ -299,6 +300,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
299#[cfg(test)] 300#[cfg(test)]
300mod tests { 301mod tests {
301 use expect_test::{expect, Expect}; 302 use expect_test::{expect, Expect};
303 use ide_assists::AssistResolveStrategy;
302 use stdx::trim_indent; 304 use stdx::trim_indent;
303 use test_utils::assert_eq_text; 305 use test_utils::assert_eq_text;
304 306
@@ -314,7 +316,11 @@ mod tests {
314 316
315 let (analysis, file_position) = fixture::position(ra_fixture_before); 317 let (analysis, file_position) = fixture::position(ra_fixture_before);
316 let diagnostic = analysis 318 let diagnostic = analysis
317 .diagnostics(&DiagnosticsConfig::default(), true, file_position.file_id) 319 .diagnostics(
320 &DiagnosticsConfig::default(),
321 AssistResolveStrategy::All,
322 file_position.file_id,
323 )
318 .unwrap() 324 .unwrap()
319 .pop() 325 .pop()
320 .unwrap(); 326 .unwrap();
@@ -343,7 +349,11 @@ mod tests {
343 fn check_no_fix(ra_fixture: &str) { 349 fn check_no_fix(ra_fixture: &str) {
344 let (analysis, file_position) = fixture::position(ra_fixture); 350 let (analysis, file_position) = fixture::position(ra_fixture);
345 let diagnostic = analysis 351 let diagnostic = analysis
346 .diagnostics(&DiagnosticsConfig::default(), true, file_position.file_id) 352 .diagnostics(
353 &DiagnosticsConfig::default(),
354 AssistResolveStrategy::All,
355 file_position.file_id,
356 )
347 .unwrap() 357 .unwrap()
348 .pop() 358 .pop()
349 .unwrap(); 359 .unwrap();
@@ -357,7 +367,9 @@ mod tests {
357 let diagnostics = files 367 let diagnostics = files
358 .into_iter() 368 .into_iter()
359 .flat_map(|file_id| { 369 .flat_map(|file_id| {
360 analysis.diagnostics(&DiagnosticsConfig::default(), true, file_id).unwrap() 370 analysis
371 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id)
372 .unwrap()
361 }) 373 })
362 .collect::<Vec<_>>(); 374 .collect::<Vec<_>>();
363 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); 375 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics);
@@ -365,8 +377,9 @@ mod tests {
365 377
366 fn check_expect(ra_fixture: &str, expect: Expect) { 378 fn check_expect(ra_fixture: &str, expect: Expect) {
367 let (analysis, file_id) = fixture::file(ra_fixture); 379 let (analysis, file_id) = fixture::file(ra_fixture);
368 let diagnostics = 380 let diagnostics = analysis
369 analysis.diagnostics(&DiagnosticsConfig::default(), true, file_id).unwrap(); 381 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id)
382 .unwrap();
370 expect.assert_debug_eq(&diagnostics) 383 expect.assert_debug_eq(&diagnostics)
371 } 384 }
372 385
@@ -911,11 +924,13 @@ struct Foo {
911 924
912 let (analysis, file_id) = fixture::file(r#"mod foo;"#); 925 let (analysis, file_id) = fixture::file(r#"mod foo;"#);
913 926
914 let diagnostics = analysis.diagnostics(&config, true, file_id).unwrap(); 927 let diagnostics =
928 analysis.diagnostics(&config, AssistResolveStrategy::All, file_id).unwrap();
915 assert!(diagnostics.is_empty()); 929 assert!(diagnostics.is_empty());
916 930
917 let diagnostics = 931 let diagnostics = analysis
918 analysis.diagnostics(&DiagnosticsConfig::default(), true, file_id).unwrap(); 932 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id)
933 .unwrap();
919 assert!(!diagnostics.is_empty()); 934 assert!(!diagnostics.is_empty());
920 } 935 }
921 936
@@ -1022,7 +1037,11 @@ impl TestStruct {
1022 1037
1023 let (analysis, file_position) = fixture::position(input); 1038 let (analysis, file_position) = fixture::position(input);
1024 let diagnostics = analysis 1039 let diagnostics = analysis
1025 .diagnostics(&DiagnosticsConfig::default(), true, file_position.file_id) 1040 .diagnostics(
1041 &DiagnosticsConfig::default(),
1042 AssistResolveStrategy::All,
1043 file_position.file_id,
1044 )
1026 .unwrap(); 1045 .unwrap();
1027 assert_eq!(diagnostics.len(), 1); 1046 assert_eq!(diagnostics.len(), 1);
1028 1047