diff options
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index dc815a483..f5d627b6e 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -218,10 +218,7 @@ mod tests { | |||
218 | use stdx::trim_indent; | 218 | use stdx::trim_indent; |
219 | use test_utils::assert_eq_text; | 219 | use test_utils::assert_eq_text; |
220 | 220 | ||
221 | use crate::{ | 221 | use crate::{fixture, DiagnosticsConfig}; |
222 | mock_analysis::{analysis_and_position, single_file, MockAnalysis}, | ||
223 | DiagnosticsConfig, | ||
224 | }; | ||
225 | 222 | ||
226 | /// Takes a multi-file input fixture with annotated cursor positions, | 223 | /// Takes a multi-file input fixture with annotated cursor positions, |
227 | /// and checks that: | 224 | /// and checks that: |
@@ -231,7 +228,7 @@ mod tests { | |||
231 | fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { | 228 | fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { |
232 | let after = trim_indent(ra_fixture_after); | 229 | let after = trim_indent(ra_fixture_after); |
233 | 230 | ||
234 | let (analysis, file_position) = analysis_and_position(ra_fixture_before); | 231 | let (analysis, file_position) = fixture::position(ra_fixture_before); |
235 | let diagnostic = analysis | 232 | let diagnostic = analysis |
236 | .diagnostics(&DiagnosticsConfig::default(), file_position.file_id) | 233 | .diagnostics(&DiagnosticsConfig::default(), file_position.file_id) |
237 | .unwrap() | 234 | .unwrap() |
@@ -260,7 +257,7 @@ mod tests { | |||
260 | /// which has a fix that can apply to other files. | 257 | /// which has a fix that can apply to other files. |
261 | fn check_apply_diagnostic_fix_in_other_file(ra_fixture_before: &str, ra_fixture_after: &str) { | 258 | fn check_apply_diagnostic_fix_in_other_file(ra_fixture_before: &str, ra_fixture_after: &str) { |
262 | let ra_fixture_after = &trim_indent(ra_fixture_after); | 259 | let ra_fixture_after = &trim_indent(ra_fixture_after); |
263 | let (analysis, file_pos) = analysis_and_position(ra_fixture_before); | 260 | let (analysis, file_pos) = fixture::position(ra_fixture_before); |
264 | let current_file_id = file_pos.file_id; | 261 | let current_file_id = file_pos.file_id; |
265 | let diagnostic = analysis | 262 | let diagnostic = analysis |
266 | .diagnostics(&DiagnosticsConfig::default(), current_file_id) | 263 | .diagnostics(&DiagnosticsConfig::default(), current_file_id) |
@@ -282,9 +279,7 @@ mod tests { | |||
282 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics | 279 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics |
283 | /// apply to the file containing the cursor. | 280 | /// apply to the file containing the cursor. |
284 | fn check_no_diagnostics(ra_fixture: &str) { | 281 | fn check_no_diagnostics(ra_fixture: &str) { |
285 | let mock = MockAnalysis::with_files(ra_fixture); | 282 | let (analysis, files) = fixture::files(ra_fixture); |
286 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); | ||
287 | let analysis = mock.analysis(); | ||
288 | let diagnostics = files | 283 | let diagnostics = files |
289 | .into_iter() | 284 | .into_iter() |
290 | .flat_map(|file_id| { | 285 | .flat_map(|file_id| { |
@@ -295,7 +290,7 @@ mod tests { | |||
295 | } | 290 | } |
296 | 291 | ||
297 | fn check_expect(ra_fixture: &str, expect: Expect) { | 292 | fn check_expect(ra_fixture: &str, expect: Expect) { |
298 | let (analysis, file_id) = single_file(ra_fixture); | 293 | let (analysis, file_id) = fixture::file(ra_fixture); |
299 | let diagnostics = analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap(); | 294 | let diagnostics = analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap(); |
300 | expect.assert_debug_eq(&diagnostics) | 295 | expect.assert_debug_eq(&diagnostics) |
301 | } | 296 | } |
@@ -304,7 +299,7 @@ mod tests { | |||
304 | fn test_wrap_return_type() { | 299 | fn test_wrap_return_type() { |
305 | check_fix( | 300 | check_fix( |
306 | r#" | 301 | r#" |
307 | //- /main.rs | 302 | //- /main.rs crate:main deps:core |
308 | use core::result::Result::{self, Ok, Err}; | 303 | use core::result::Result::{self, Ok, Err}; |
309 | 304 | ||
310 | fn div(x: i32, y: i32) -> Result<i32, ()> { | 305 | fn div(x: i32, y: i32) -> Result<i32, ()> { |
@@ -313,7 +308,7 @@ fn div(x: i32, y: i32) -> Result<i32, ()> { | |||
313 | } | 308 | } |
314 | x / y<|> | 309 | x / y<|> |
315 | } | 310 | } |
316 | //- /core/lib.rs | 311 | //- /core/lib.rs crate:core |
317 | pub mod result { | 312 | pub mod result { |
318 | pub enum Result<T, E> { Ok(T), Err(E) } | 313 | pub enum Result<T, E> { Ok(T), Err(E) } |
319 | } | 314 | } |
@@ -335,7 +330,7 @@ fn div(x: i32, y: i32) -> Result<i32, ()> { | |||
335 | fn test_wrap_return_type_handles_generic_functions() { | 330 | fn test_wrap_return_type_handles_generic_functions() { |
336 | check_fix( | 331 | check_fix( |
337 | r#" | 332 | r#" |
338 | //- /main.rs | 333 | //- /main.rs crate:main deps:core |
339 | use core::result::Result::{self, Ok, Err}; | 334 | use core::result::Result::{self, Ok, Err}; |
340 | 335 | ||
341 | fn div<T>(x: T) -> Result<T, i32> { | 336 | fn div<T>(x: T) -> Result<T, i32> { |
@@ -344,7 +339,7 @@ fn div<T>(x: T) -> Result<T, i32> { | |||
344 | } | 339 | } |
345 | <|>x | 340 | <|>x |
346 | } | 341 | } |
347 | //- /core/lib.rs | 342 | //- /core/lib.rs crate:core |
348 | pub mod result { | 343 | pub mod result { |
349 | pub enum Result<T, E> { Ok(T), Err(E) } | 344 | pub enum Result<T, E> { Ok(T), Err(E) } |
350 | } | 345 | } |
@@ -366,7 +361,7 @@ fn div<T>(x: T) -> Result<T, i32> { | |||
366 | fn test_wrap_return_type_handles_type_aliases() { | 361 | fn test_wrap_return_type_handles_type_aliases() { |
367 | check_fix( | 362 | check_fix( |
368 | r#" | 363 | r#" |
369 | //- /main.rs | 364 | //- /main.rs crate:main deps:core |
370 | use core::result::Result::{self, Ok, Err}; | 365 | use core::result::Result::{self, Ok, Err}; |
371 | 366 | ||
372 | type MyResult<T> = Result<T, ()>; | 367 | type MyResult<T> = Result<T, ()>; |
@@ -377,7 +372,7 @@ fn div(x: i32, y: i32) -> MyResult<i32> { | |||
377 | } | 372 | } |
378 | x <|>/ y | 373 | x <|>/ y |
379 | } | 374 | } |
380 | //- /core/lib.rs | 375 | //- /core/lib.rs crate:core |
381 | pub mod result { | 376 | pub mod result { |
382 | pub enum Result<T, E> { Ok(T), Err(E) } | 377 | pub enum Result<T, E> { Ok(T), Err(E) } |
383 | } | 378 | } |
@@ -401,12 +396,12 @@ fn div(x: i32, y: i32) -> MyResult<i32> { | |||
401 | fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { | 396 | fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { |
402 | check_no_diagnostics( | 397 | check_no_diagnostics( |
403 | r#" | 398 | r#" |
404 | //- /main.rs | 399 | //- /main.rs crate:main deps:core |
405 | use core::result::Result::{self, Ok, Err}; | 400 | use core::result::Result::{self, Ok, Err}; |
406 | 401 | ||
407 | fn foo() -> Result<(), i32> { 0 } | 402 | fn foo() -> Result<(), i32> { 0 } |
408 | 403 | ||
409 | //- /core/lib.rs | 404 | //- /core/lib.rs crate:core |
410 | pub mod result { | 405 | pub mod result { |
411 | pub enum Result<T, E> { Ok(T), Err(E) } | 406 | pub enum Result<T, E> { Ok(T), Err(E) } |
412 | } | 407 | } |
@@ -418,14 +413,14 @@ pub mod result { | |||
418 | fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { | 413 | fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { |
419 | check_no_diagnostics( | 414 | check_no_diagnostics( |
420 | r#" | 415 | r#" |
421 | //- /main.rs | 416 | //- /main.rs crate:main deps:core |
422 | use core::result::Result::{self, Ok, Err}; | 417 | use core::result::Result::{self, Ok, Err}; |
423 | 418 | ||
424 | enum SomeOtherEnum { Ok(i32), Err(String) } | 419 | enum SomeOtherEnum { Ok(i32), Err(String) } |
425 | 420 | ||
426 | fn foo() -> SomeOtherEnum { 0 } | 421 | fn foo() -> SomeOtherEnum { 0 } |
427 | 422 | ||
428 | //- /core/lib.rs | 423 | //- /core/lib.rs crate:core |
429 | pub mod result { | 424 | pub mod result { |
430 | pub enum Result<T, E> { Ok(T), Err(E) } | 425 | pub enum Result<T, E> { Ok(T), Err(E) } |
431 | } | 426 | } |
@@ -567,7 +562,7 @@ fn test_fn() { | |||
567 | file_system_edits: [ | 562 | file_system_edits: [ |
568 | CreateFile { | 563 | CreateFile { |
569 | anchor: FileId( | 564 | anchor: FileId( |
570 | 1, | 565 | 0, |
571 | ), | 566 | ), |
572 | dst: "foo.rs", | 567 | dst: "foo.rs", |
573 | }, | 568 | }, |
@@ -787,7 +782,7 @@ struct Foo { | |||
787 | let mut config = DiagnosticsConfig::default(); | 782 | let mut config = DiagnosticsConfig::default(); |
788 | config.disabled.insert("unresolved-module".into()); | 783 | config.disabled.insert("unresolved-module".into()); |
789 | 784 | ||
790 | let (analysis, file_id) = single_file(r#"mod foo;"#); | 785 | let (analysis, file_id) = fixture::file(r#"mod foo;"#); |
791 | 786 | ||
792 | let diagnostics = analysis.diagnostics(&config, file_id).unwrap(); | 787 | let diagnostics = analysis.diagnostics(&config, file_id).unwrap(); |
793 | assert!(diagnostics.is_empty()); | 788 | assert!(diagnostics.is_empty()); |