aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/diagnostics
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-09 15:04:29 +0100
committerAleksey Kladov <[email protected]>2020-07-09 15:04:29 +0100
commite075e6eef2c275d9b9b511b37dad478285aecb48 (patch)
tree30f30c3e79915e8d6ea5c472f7a4b4ccce75a5d8 /crates/rust-analyzer/src/diagnostics
parentd70f4f5da5cb12c267aa9eb4c0a23d00bdd01608 (diff)
Move diagnostics tests to expect
Diffstat (limited to 'crates/rust-analyzer/src/diagnostics')
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_clippy_pass_by_ref.snap71
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_handles_macro_location.snap36
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_macro_compiler_error.snap51
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_multi_line_fix.snap102
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_incompatible_type_for_trait.snap36
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_mismatched_type.snap36
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable.snap74
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_hint.snap74
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_info.snap74
-rw-r--r--crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_wrong_number_of_parameters.snap55
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs120
11 files changed, 49 insertions, 680 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_clippy_pass_by_ref.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_clippy_pass_by_ref.snap
deleted file mode 100644
index 578b1e128..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_clippy_pass_by_ref.snap
+++ /dev/null
@@ -1,71 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/compiler/mir/tagset.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 41,
12 character: 23,
13 },
14 end: Position {
15 line: 41,
16 character: 28,
17 },
18 },
19 severity: Some(
20 Warning,
21 ),
22 code: Some(
23 String(
24 "trivially_copy_pass_by_ref",
25 ),
26 ),
27 source: Some(
28 "clippy",
29 ),
30 message: "this argument is passed by reference, but would be more efficient if passed by value\n#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]\nfor further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref",
31 related_information: Some(
32 [
33 DiagnosticRelatedInformation {
34 location: Location {
35 uri: "file:///test/compiler/lib.rs",
36 range: Range {
37 start: Position {
38 line: 0,
39 character: 8,
40 },
41 end: Position {
42 line: 0,
43 character: 19,
44 },
45 },
46 },
47 message: "lint level defined here",
48 },
49 DiagnosticRelatedInformation {
50 location: Location {
51 uri: "file:///test/compiler/mir/tagset.rs",
52 range: Range {
53 start: Position {
54 line: 41,
55 character: 23,
56 },
57 end: Position {
58 line: 41,
59 character: 28,
60 },
61 },
62 },
63 message: "consider passing by value instead",
64 },
65 ],
66 ),
67 tags: None,
68 },
69 fixes: [],
70 },
71]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_handles_macro_location.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_handles_macro_location.snap
deleted file mode 100644
index 577cf4b2d..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_handles_macro_location.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/src/main.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 1,
12 character: 4,
13 },
14 end: Position {
15 line: 1,
16 character: 26,
17 },
18 },
19 severity: Some(
20 Error,
21 ),
22 code: Some(
23 String(
24 "E0277",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "can\'t compare `{integer}` with `&str`\nthe trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`",
31 related_information: None,
32 tags: None,
33 },
34 fixes: [],
35 },
36]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_macro_compiler_error.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_macro_compiler_error.snap
deleted file mode 100644
index 22bd23a88..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_macro_compiler_error.snap
+++ /dev/null
@@ -1,51 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/crates/ra_hir_def/src/data.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 79,
12 character: 15,
13 },
14 end: Position {
15 line: 79,
16 character: 41,
17 },
18 },
19 severity: Some(
20 Error,
21 ),
22 code: None,
23 source: Some(
24 "rustc",
25 ),
26 message: "Please register your known path in the path module",
27 related_information: Some(
28 [
29 DiagnosticRelatedInformation {
30 location: Location {
31 uri: "file:///test/crates/ra_hir_def/src/path.rs",
32 range: Range {
33 start: Position {
34 line: 264,
35 character: 8,
36 },
37 end: Position {
38 line: 264,
39 character: 76,
40 },
41 },
42 },
43 message: "Error originated from macro here",
44 },
45 ],
46 ),
47 tags: None,
48 },
49 fixes: [],
50 },
51]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_multi_line_fix.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_multi_line_fix.snap
deleted file mode 100644
index 1a0ac4f42..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_multi_line_fix.snap
+++ /dev/null
@@ -1,102 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/src/main.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 3,
12 character: 4,
13 },
14 end: Position {
15 line: 3,
16 character: 5,
17 },
18 },
19 severity: Some(
20 Warning,
21 ),
22 code: Some(
23 String(
24 "let_and_return",
25 ),
26 ),
27 source: Some(
28 "clippy",
29 ),
30 message: "returning the result of a let binding from a block\n`#[warn(clippy::let_and_return)]` on by default\nfor further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return",
31 related_information: Some(
32 [
33 DiagnosticRelatedInformation {
34 location: Location {
35 uri: "file:///test/src/main.rs",
36 range: Range {
37 start: Position {
38 line: 2,
39 character: 4,
40 },
41 end: Position {
42 line: 2,
43 character: 30,
44 },
45 },
46 },
47 message: "unnecessary let binding",
48 },
49 ],
50 ),
51 tags: None,
52 },
53 fixes: [
54 CodeAction {
55 title: "return the expression directly",
56 id: None,
57 group: None,
58 kind: Some(
59 "quickfix",
60 ),
61 command: None,
62 edit: Some(
63 SnippetWorkspaceEdit {
64 changes: Some(
65 {
66 "file:///test/src/main.rs": [
67 TextEdit {
68 range: Range {
69 start: Position {
70 line: 2,
71 character: 4,
72 },
73 end: Position {
74 line: 2,
75 character: 30,
76 },
77 },
78 new_text: "",
79 },
80 TextEdit {
81 range: Range {
82 start: Position {
83 line: 3,
84 character: 4,
85 },
86 end: Position {
87 line: 3,
88 character: 5,
89 },
90 },
91 new_text: "(0..10).collect()",
92 },
93 ],
94 },
95 ),
96 document_changes: None,
97 },
98 ),
99 },
100 ],
101 },
102]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_incompatible_type_for_trait.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_incompatible_type_for_trait.snap
deleted file mode 100644
index cc608dafe..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_incompatible_type_for_trait.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/compiler/ty/list_iter.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 51,
12 character: 4,
13 },
14 end: Position {
15 line: 51,
16 character: 47,
17 },
18 },
19 severity: Some(
20 Error,
21 ),
22 code: Some(
23 String(
24 "E0053",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "method `next` has an incompatible type for trait\nexpected type `fn(&mut ty::list_iter::ListIterator<\'list, M>) -> std::option::Option<&ty::Ref<M>>`\n found type `fn(&ty::list_iter::ListIterator<\'list, M>) -> std::option::Option<&\'list ty::Ref<M>>`",
31 related_information: None,
32 tags: None,
33 },
34 fixes: [],
35 },
36]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_mismatched_type.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_mismatched_type.snap
deleted file mode 100644
index 4d2a8625e..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_mismatched_type.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/runtime/compiler_support.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 47,
12 character: 64,
13 },
14 end: Position {
15 line: 47,
16 character: 69,
17 },
18 },
19 severity: Some(
20 Error,
21 ),
22 code: Some(
23 String(
24 "E0308",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "mismatched types\nexpected usize, found u32",
31 related_information: None,
32 tags: None,
33 },
34 fixes: [],
35 },
36]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable.snap
deleted file mode 100644
index e35941c76..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable.snap
+++ /dev/null
@@ -1,74 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/driver/subcommand/repl.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 290,
12 character: 8,
13 },
14 end: Position {
15 line: 290,
16 character: 11,
17 },
18 },
19 severity: Some(
20 Warning,
21 ),
22 code: Some(
23 String(
24 "unused_variables",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "unused variable: `foo`\n#[warn(unused_variables)] on by default",
31 related_information: None,
32 tags: Some(
33 [
34 Unnecessary,
35 ],
36 ),
37 },
38 fixes: [
39 CodeAction {
40 title: "consider prefixing with an underscore",
41 id: None,
42 group: None,
43 kind: Some(
44 "quickfix",
45 ),
46 command: None,
47 edit: Some(
48 SnippetWorkspaceEdit {
49 changes: Some(
50 {
51 "file:///test/driver/subcommand/repl.rs": [
52 TextEdit {
53 range: Range {
54 start: Position {
55 line: 290,
56 character: 8,
57 },
58 end: Position {
59 line: 290,
60 character: 11,
61 },
62 },
63 new_text: "_foo",
64 },
65 ],
66 },
67 ),
68 document_changes: None,
69 },
70 ),
71 },
72 ],
73 },
74]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_hint.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_hint.snap
deleted file mode 100644
index b6a7bcf60..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_hint.snap
+++ /dev/null
@@ -1,74 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/driver/subcommand/repl.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 290,
12 character: 8,
13 },
14 end: Position {
15 line: 290,
16 character: 11,
17 },
18 },
19 severity: Some(
20 Hint,
21 ),
22 code: Some(
23 String(
24 "unused_variables",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "unused variable: `foo`\n#[warn(unused_variables)] on by default",
31 related_information: None,
32 tags: Some(
33 [
34 Unnecessary,
35 ],
36 ),
37 },
38 fixes: [
39 CodeAction {
40 title: "consider prefixing with an underscore",
41 id: None,
42 group: None,
43 kind: Some(
44 "quickfix",
45 ),
46 command: None,
47 edit: Some(
48 SnippetWorkspaceEdit {
49 changes: Some(
50 {
51 "file:///test/driver/subcommand/repl.rs": [
52 TextEdit {
53 range: Range {
54 start: Position {
55 line: 290,
56 character: 8,
57 },
58 end: Position {
59 line: 290,
60 character: 11,
61 },
62 },
63 new_text: "_foo",
64 },
65 ],
66 },
67 ),
68 document_changes: None,
69 },
70 ),
71 },
72 ],
73 },
74]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_info.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_info.snap
deleted file mode 100644
index 8c248faf2..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_unused_variable_as_info.snap
+++ /dev/null
@@ -1,74 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/driver/subcommand/repl.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 290,
12 character: 8,
13 },
14 end: Position {
15 line: 290,
16 character: 11,
17 },
18 },
19 severity: Some(
20 Information,
21 ),
22 code: Some(
23 String(
24 "unused_variables",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "unused variable: `foo`\n#[warn(unused_variables)] on by default",
31 related_information: None,
32 tags: Some(
33 [
34 Unnecessary,
35 ],
36 ),
37 },
38 fixes: [
39 CodeAction {
40 title: "consider prefixing with an underscore",
41 id: None,
42 group: None,
43 kind: Some(
44 "quickfix",
45 ),
46 command: None,
47 edit: Some(
48 SnippetWorkspaceEdit {
49 changes: Some(
50 {
51 "file:///test/driver/subcommand/repl.rs": [
52 TextEdit {
53 range: Range {
54 start: Position {
55 line: 290,
56 character: 8,
57 },
58 end: Position {
59 line: 290,
60 character: 11,
61 },
62 },
63 new_text: "_foo",
64 },
65 ],
66 },
67 ),
68 document_changes: None,
69 },
70 ),
71 },
72 ],
73 },
74]
diff --git a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_wrong_number_of_parameters.snap b/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_wrong_number_of_parameters.snap
deleted file mode 100644
index 3ece40eaf..000000000
--- a/crates/rust-analyzer/src/diagnostics/snapshots/rust_analyzer__diagnostics__to_proto__tests__snap_rustc_wrong_number_of_parameters.snap
+++ /dev/null
@@ -1,55 +0,0 @@
1---
2source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3expression: diag
4---
5[
6 MappedRustDiagnostic {
7 url: "file:///test/compiler/ty/select.rs",
8 diagnostic: Diagnostic {
9 range: Range {
10 start: Position {
11 line: 103,
12 character: 17,
13 },
14 end: Position {
15 line: 103,
16 character: 29,
17 },
18 },
19 severity: Some(
20 Error,
21 ),
22 code: Some(
23 String(
24 "E0061",
25 ),
26 ),
27 source: Some(
28 "rustc",
29 ),
30 message: "this function takes 2 parameters but 3 parameters were supplied\nexpected 2 parameters",
31 related_information: Some(
32 [
33 DiagnosticRelatedInformation {
34 location: Location {
35 uri: "file:///test/compiler/ty/select.rs",
36 range: Range {
37 start: Position {
38 line: 218,
39 character: 4,
40 },
41 end: Position {
42 line: 230,
43 character: 5,
44 },
45 },
46 },
47 message: "defined here",
48 },
49 ],
50 ),
51 tags: None,
52 },
53 fixes: [],
54 },
55]
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index ded96c58a..808a23b17 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -256,13 +256,23 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
256mod tests { 256mod tests {
257 use super::*; 257 use super::*;
258 258
259 fn parse_diagnostic(val: &str) -> flycheck::Diagnostic { 259 use expect::{expect_file, ExpectFile};
260 serde_json::from_str::<flycheck::Diagnostic>(val).unwrap() 260
261 // TODO: inlay hints config order
262 fn check(diagnostics_json: &str, expect: ExpectFile) {
263 check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect)
264 }
265
266 fn check_with_config(config: DiagnosticsConfig, diagnostics_json: &str, expect: ExpectFile) {
267 let diagnostic: flycheck::Diagnostic = serde_json::from_str(diagnostics_json).unwrap();
268 let workspace_root = Path::new("/test/");
269 let actual = map_rust_diagnostic_to_lsp(&config, &diagnostic, workspace_root);
270 expect.assert_debug_eq(&actual)
261 } 271 }
262 272
263 #[test] 273 #[test]
264 fn snap_rustc_incompatible_type_for_trait() { 274 fn rustc_incompatible_type_for_trait() {
265 let diag = parse_diagnostic( 275 check(
266 r##"{ 276 r##"{
267 "message": "method `next` has an incompatible type for trait", 277 "message": "method `next` has an incompatible type for trait",
268 "code": { 278 "code": {
@@ -306,16 +316,13 @@ mod tests {
306 "rendered": "error[E0053]: method `next` has an incompatible type for trait\n --> compiler/ty/list_iter.rs:52:5\n |\n52 | fn next(&self) -> Option<&'list ty::Ref<M>> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability\n |\n = note: expected type `fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>`\n found type `fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>`\n\n" 316 "rendered": "error[E0053]: method `next` has an incompatible type for trait\n --> compiler/ty/list_iter.rs:52:5\n |\n52 | fn next(&self) -> Option<&'list ty::Ref<M>> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability\n |\n = note: expected type `fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>`\n found type `fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>`\n\n"
307 } 317 }
308 "##, 318 "##,
319 expect_file!["crates/rust-analyzer/test_data/rustc_incompatible_type_for_trait.txt"],
309 ); 320 );
310
311 let workspace_root = Path::new("/test/");
312 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
313 insta::assert_debug_snapshot!(diag);
314 } 321 }
315 322
316 #[test] 323 #[test]
317 fn snap_rustc_unused_variable() { 324 fn rustc_unused_variable() {
318 let diag = parse_diagnostic( 325 check(
319 r##"{ 326 r##"{
320 "message": "unused variable: `foo`", 327 "message": "unused variable: `foo`",
321 "code": { 328 "code": {
@@ -388,17 +395,18 @@ mod tests {
388 ], 395 ],
389 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n" 396 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n"
390 }"##, 397 }"##,
398 expect_file!["crates/rust-analyzer/test_data/rustc_unused_variable.txt"],
391 ); 399 );
392
393 let workspace_root = Path::new("/test/");
394 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
395 insta::assert_debug_snapshot!(diag);
396 } 400 }
397 401
398 #[test] 402 #[test]
399 #[cfg(not(windows))] 403 #[cfg(not(windows))]
400 fn snap_rustc_unused_variable_as_info() { 404 fn rustc_unused_variable_as_info() {
401 let diag = parse_diagnostic( 405 check_with_config(
406 DiagnosticsConfig {
407 warnings_as_info: vec!["unused_variables".to_string()],
408 ..DiagnosticsConfig::default()
409 },
402 r##"{ 410 r##"{
403 "message": "unused variable: `foo`", 411 "message": "unused variable: `foo`",
404 "code": { 412 "code": {
@@ -471,22 +479,18 @@ mod tests {
471 ], 479 ],
472 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n" 480 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n"
473 }"##, 481 }"##,
482 expect_file!["crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt"],
474 ); 483 );
475
476 let config = DiagnosticsConfig {
477 warnings_as_info: vec!["unused_variables".to_string()],
478 ..DiagnosticsConfig::default()
479 };
480
481 let workspace_root = Path::new("/test/");
482 let diag = map_rust_diagnostic_to_lsp(&config, &diag, workspace_root);
483 insta::assert_debug_snapshot!(diag);
484 } 484 }
485 485
486 #[test] 486 #[test]
487 #[cfg(not(windows))] 487 #[cfg(not(windows))]
488 fn snap_rustc_unused_variable_as_hint() { 488 fn rustc_unused_variable_as_hint() {
489 let diag = parse_diagnostic( 489 check_with_config(
490 DiagnosticsConfig {
491 warnings_as_hint: vec!["unused_variables".to_string()],
492 ..DiagnosticsConfig::default()
493 },
490 r##"{ 494 r##"{
491 "message": "unused variable: `foo`", 495 "message": "unused variable: `foo`",
492 "code": { 496 "code": {
@@ -559,21 +563,13 @@ mod tests {
559 ], 563 ],
560 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n" 564 "rendered": "warning: unused variable: `foo`\n --> driver/subcommand/repl.rs:291:9\n |\n291 | let foo = 42;\n | ^^^ help: consider prefixing with an underscore: `_foo`\n |\n = note: #[warn(unused_variables)] on by default\n\n"
561 }"##, 565 }"##,
566 expect_file!["crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt"],
562 ); 567 );
563
564 let config = DiagnosticsConfig {
565 warnings_as_hint: vec!["unused_variables".to_string()],
566 ..DiagnosticsConfig::default()
567 };
568
569 let workspace_root = Path::new("/test/");
570 let diag = map_rust_diagnostic_to_lsp(&config, &diag, workspace_root);
571 insta::assert_debug_snapshot!(diag);
572 } 568 }
573 569
574 #[test] 570 #[test]
575 fn snap_rustc_wrong_number_of_parameters() { 571 fn rustc_wrong_number_of_parameters() {
576 let diag = parse_diagnostic( 572 check(
577 r##"{ 573 r##"{
578 "message": "this function takes 2 parameters but 3 parameters were supplied", 574 "message": "this function takes 2 parameters but 3 parameters were supplied",
579 "code": { 575 "code": {
@@ -688,16 +684,13 @@ mod tests {
688 "children": [], 684 "children": [],
689 "rendered": "error[E0061]: this function takes 2 parameters but 3 parameters were supplied\n --> compiler/ty/select.rs:104:18\n |\n104 | self.add_evidence(target_fixed, evidence_fixed, false);\n | ^^^^^^^^^^^^ expected 2 parameters\n...\n219 | / pub fn add_evidence(\n220 | | &mut self,\n221 | | target_poly: &ty::Ref<ty::Poly>,\n222 | | evidence_poly: &ty::Ref<ty::Poly>,\n... |\n230 | | }\n231 | | }\n | |_____- defined here\n\n" 685 "rendered": "error[E0061]: this function takes 2 parameters but 3 parameters were supplied\n --> compiler/ty/select.rs:104:18\n |\n104 | self.add_evidence(target_fixed, evidence_fixed, false);\n | ^^^^^^^^^^^^ expected 2 parameters\n...\n219 | / pub fn add_evidence(\n220 | | &mut self,\n221 | | target_poly: &ty::Ref<ty::Poly>,\n222 | | evidence_poly: &ty::Ref<ty::Poly>,\n... |\n230 | | }\n231 | | }\n | |_____- defined here\n\n"
690 }"##, 686 }"##,
687 expect_file!["crates/rust-analyzer/test_data/rustc_wrong_number_of_parameters.txt"],
691 ); 688 );
692
693 let workspace_root = Path::new("/test/");
694 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
695 insta::assert_debug_snapshot!(diag);
696 } 689 }
697 690
698 #[test] 691 #[test]
699 fn snap_clippy_pass_by_ref() { 692 fn clippy_pass_by_ref() {
700 let diag = parse_diagnostic( 693 check(
701 r##"{ 694 r##"{
702 "message": "this argument is passed by reference, but would be more efficient if passed by value", 695 "message": "this argument is passed by reference, but would be more efficient if passed by value",
703 "code": { 696 "code": {
@@ -808,16 +801,13 @@ mod tests {
808 ], 801 ],
809 "rendered": "warning: this argument is passed by reference, but would be more efficient if passed by value\n --> compiler/mir/tagset.rs:42:24\n |\n42 | pub fn is_disjoint(&self, other: Self) -> bool {\n | ^^^^^ help: consider passing by value instead: `self`\n |\nnote: lint level defined here\n --> compiler/lib.rs:1:9\n |\n1 | #![warn(clippy::all)]\n | ^^^^^^^^^^^\n = note: #[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref\n\n" 802 "rendered": "warning: this argument is passed by reference, but would be more efficient if passed by value\n --> compiler/mir/tagset.rs:42:24\n |\n42 | pub fn is_disjoint(&self, other: Self) -> bool {\n | ^^^^^ help: consider passing by value instead: `self`\n |\nnote: lint level defined here\n --> compiler/lib.rs:1:9\n |\n1 | #![warn(clippy::all)]\n | ^^^^^^^^^^^\n = note: #[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref\n\n"
810 }"##, 803 }"##,
804 expect_file!["crates/rust-analyzer/test_data/clippy_pass_by_ref.txt"],
811 ); 805 );
812
813 let workspace_root = Path::new("/test/");
814 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
815 insta::assert_debug_snapshot!(diag);
816 } 806 }
817 807
818 #[test] 808 #[test]
819 fn snap_rustc_mismatched_type() { 809 fn rustc_mismatched_type() {
820 let diag = parse_diagnostic( 810 check(
821 r##"{ 811 r##"{
822 "message": "mismatched types", 812 "message": "mismatched types",
823 "code": { 813 "code": {
@@ -851,16 +841,13 @@ mod tests {
851 "children": [], 841 "children": [],
852 "rendered": "error[E0308]: mismatched types\n --> runtime/compiler_support.rs:48:65\n |\n48 | let layout = alloc::Layout::from_size_align_unchecked(size, align);\n | ^^^^^ expected usize, found u32\n\n" 842 "rendered": "error[E0308]: mismatched types\n --> runtime/compiler_support.rs:48:65\n |\n48 | let layout = alloc::Layout::from_size_align_unchecked(size, align);\n | ^^^^^ expected usize, found u32\n\n"
853 }"##, 843 }"##,
844 expect_file!["crates/rust-analyzer/test_data/rustc_mismatched_type.txt"],
854 ); 845 );
855
856 let workspace_root = Path::new("/test/");
857 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
858 insta::assert_debug_snapshot!(diag);
859 } 846 }
860 847
861 #[test] 848 #[test]
862 fn snap_handles_macro_location() { 849 fn handles_macro_location() {
863 let diag = parse_diagnostic( 850 check(
864 r##"{ 851 r##"{
865 "rendered": "error[E0277]: can't compare `{integer}` with `&str`\n --> src/main.rs:2:5\n |\n2 | assert_eq!(1, \"love\");\n | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == &str`\n |\n = help: the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`\n = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\n\n", 852 "rendered": "error[E0277]: can't compare `{integer}` with `&str`\n --> src/main.rs:2:5\n |\n2 | assert_eq!(1, \"love\");\n | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == &str`\n |\n = help: the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`\n = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\n\n",
866 "children": [ 853 "children": [
@@ -1122,16 +1109,13 @@ mod tests {
1122 } 1109 }
1123 ] 1110 ]
1124 }"##, 1111 }"##,
1112 expect_file!["crates/rust-analyzer/test_data/handles_macro_location.txt"],
1125 ); 1113 );
1126
1127 let workspace_root = Path::new("/test/");
1128 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
1129 insta::assert_debug_snapshot!(diag);
1130 } 1114 }
1131 1115
1132 #[test] 1116 #[test]
1133 fn snap_macro_compiler_error() { 1117 fn macro_compiler_error() {
1134 let diag = parse_diagnostic( 1118 check(
1135 r##"{ 1119 r##"{
1136 "rendered": "error: Please register your known path in the path module\n --> crates/ra_hir_def/src/path.rs:265:9\n |\n265 | compile_error!(\"Please register your known path in the path module\")\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | \n ::: crates/ra_hir_def/src/data.rs:80:16\n |\n80 | let path = path![std::future::Future];\n | -------------------------- in this macro invocation\n\n", 1120 "rendered": "error: Please register your known path in the path module\n --> crates/ra_hir_def/src/path.rs:265:9\n |\n265 | compile_error!(\"Please register your known path in the path module\")\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | \n ::: crates/ra_hir_def/src/data.rs:80:16\n |\n80 | let path = path![std::future::Future];\n | -------------------------- in this macro invocation\n\n",
1137 "children": [], 1121 "children": [],
@@ -1351,16 +1335,13 @@ mod tests {
1351 ] 1335 ]
1352 } 1336 }
1353 "##, 1337 "##,
1338 expect_file!["crates/rust-analyzer/test_data/macro_compiler_error.txt"],
1354 ); 1339 );
1355
1356 let workspace_root = Path::new("/test/");
1357 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
1358 insta::assert_debug_snapshot!(diag);
1359 } 1340 }
1360 1341
1361 #[test] 1342 #[test]
1362 fn snap_multi_line_fix() { 1343 fn snap_multi_line_fix() {
1363 let diag = parse_diagnostic( 1344 check(
1364 r##"{ 1345 r##"{
1365 "rendered": "warning: returning the result of a let binding from a block\n --> src/main.rs:4:5\n |\n3 | let a = (0..10).collect();\n | -------------------------- unnecessary let binding\n4 | a\n | ^\n |\n = note: `#[warn(clippy::let_and_return)]` on by default\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return\nhelp: return the expression directly\n |\n3 | \n4 | (0..10).collect()\n |\n\n", 1346 "rendered": "warning: returning the result of a let binding from a block\n --> src/main.rs:4:5\n |\n3 | let a = (0..10).collect();\n | -------------------------- unnecessary let binding\n4 | a\n | ^\n |\n = note: `#[warn(clippy::let_and_return)]` on by default\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return\nhelp: return the expression directly\n |\n3 | \n4 | (0..10).collect()\n |\n\n",
1366 "children": [ 1347 "children": [
@@ -1484,10 +1465,7 @@ mod tests {
1484 ] 1465 ]
1485 } 1466 }
1486 "##, 1467 "##,
1468 expect_file!["crates/rust-analyzer/test_data/snap_multi_line_fix.txt"],
1487 ); 1469 );
1488
1489 let workspace_root = Path::new("/test/");
1490 let diag = map_rust_diagnostic_to_lsp(&DiagnosticsConfig::default(), &diag, workspace_root);
1491 insta::assert_debug_snapshot!(diag);
1492 } 1470 }
1493} 1471}