From 637c795b3c9a56795977ade0cedbc7a9fb7dc453 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Thu, 12 Mar 2020 15:01:53 +0100 Subject: Correctly handle multi-line fixes from cargo/clippy --- ...watch__conv__test__snap_clippy_pass_by_ref.snap | 2 +- ...rgo_watch__conv__test__snap_multi_line_fix.snap | 112 +++++++++++++++++ ...ch__conv__test__snap_rustc_unused_variable.snap | 2 +- crates/ra_cargo_watch/src/conv/test.rs | 134 +++++++++++++++++++++ 4 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_multi_line_fix.snap (limited to 'crates/ra_cargo_watch/src/conv') diff --git a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap index 95ca163dc..47801ae79 100644 --- a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap +++ b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap @@ -63,7 +63,7 @@ MappedRustDiagnostic { }, fixes: [ CodeAction { - title: "consider passing by value instead: \'self\'", + title: "consider passing by value instead", kind: Some( "quickfix", ), diff --git a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_multi_line_fix.snap b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_multi_line_fix.snap new file mode 100644 index 000000000..23c4f5a2c --- /dev/null +++ b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_multi_line_fix.snap @@ -0,0 +1,112 @@ +--- +source: crates/ra_cargo_watch/src/conv/test.rs +expression: diag +--- +MappedRustDiagnostic { + location: Location { + uri: "file:///test/src/main.rs", + range: Range { + start: Position { + line: 3, + character: 4, + }, + end: Position { + line: 3, + character: 5, + }, + }, + }, + diagnostic: Diagnostic { + range: Range { + start: Position { + line: 3, + character: 4, + }, + end: Position { + line: 3, + character: 5, + }, + }, + severity: Some( + Warning, + ), + code: Some( + String( + "let_and_return", + ), + ), + source: Some( + "clippy", + ), + 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", + related_information: Some( + [ + DiagnosticRelatedInformation { + location: Location { + uri: "file:///test/src/main.rs", + range: Range { + start: Position { + line: 2, + character: 4, + }, + end: Position { + line: 2, + character: 30, + }, + }, + }, + message: "unnecessary let binding", + }, + ], + ), + tags: None, + }, + fixes: [ + CodeAction { + title: "return the expression directly", + kind: Some( + "quickfix", + ), + diagnostics: None, + edit: Some( + WorkspaceEdit { + changes: Some( + { + "file:///test/src/main.rs": [ + TextEdit { + range: Range { + start: Position { + line: 2, + character: 4, + }, + end: Position { + line: 2, + character: 30, + }, + }, + new_text: "", + }, + TextEdit { + range: Range { + start: Position { + line: 3, + character: 4, + }, + end: Position { + line: 3, + character: 5, + }, + }, + new_text: "(0..10).collect()", + }, + ], + }, + ), + document_changes: None, + }, + ), + command: None, + is_preferred: None, + }, + ], +} diff --git a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_rustc_unused_variable.snap b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_rustc_unused_variable.snap index 3e1fe736c..8bab09540 100644 --- a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_rustc_unused_variable.snap +++ b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_rustc_unused_variable.snap @@ -48,7 +48,7 @@ MappedRustDiagnostic { }, fixes: [ CodeAction { - title: "consider prefixing with an underscore: \'_foo\'", + title: "consider prefixing with an underscore", kind: Some( "quickfix", ), diff --git a/crates/ra_cargo_watch/src/conv/test.rs b/crates/ra_cargo_watch/src/conv/test.rs index 6b86525b8..c880dcdc3 100644 --- a/crates/ra_cargo_watch/src/conv/test.rs +++ b/crates/ra_cargo_watch/src/conv/test.rs @@ -936,3 +936,137 @@ fn snap_macro_compiler_error() { let diag = map_rust_diagnostic_to_lsp(&diag, &workspace_root).expect("couldn't map diagnostic"); insta::assert_debug_snapshot!(diag); } + +#[test] +#[cfg(not(windows))] +fn snap_multi_line_fix() { + let diag = parse_diagnostic( + r##"{ + "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", + "children": [ + { + "children": [], + "code": null, + "level": "note", + "message": "`#[warn(clippy::let_and_return)]` on by default", + "rendered": null, + "spans": [] + }, + { + "children": [], + "code": null, + "level": "help", + "message": "for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return", + "rendered": null, + "spans": [] + }, + { + "children": [], + "code": null, + "level": "help", + "message": "return the expression directly", + "rendered": null, + "spans": [ + { + "byte_end": 55, + "byte_start": 29, + "column_end": 31, + "column_start": 5, + "expansion": null, + "file_name": "src/main.rs", + "is_primary": true, + "label": null, + "line_end": 3, + "line_start": 3, + "suggested_replacement": "", + "suggestion_applicability": "MachineApplicable", + "text": [ + { + "highlight_end": 31, + "highlight_start": 5, + "text": " let a = (0..10).collect();" + } + ] + }, + { + "byte_end": 61, + "byte_start": 60, + "column_end": 6, + "column_start": 5, + "expansion": null, + "file_name": "src/main.rs", + "is_primary": true, + "label": null, + "line_end": 4, + "line_start": 4, + "suggested_replacement": "(0..10).collect()", + "suggestion_applicability": "MachineApplicable", + "text": [ + { + "highlight_end": 6, + "highlight_start": 5, + "text": " a" + } + ] + } + ] + } + ], + "code": { + "code": "clippy::let_and_return", + "explanation": null + }, + "level": "warning", + "message": "returning the result of a let binding from a block", + "spans": [ + { + "byte_end": 55, + "byte_start": 29, + "column_end": 31, + "column_start": 5, + "expansion": null, + "file_name": "src/main.rs", + "is_primary": false, + "label": "unnecessary let binding", + "line_end": 3, + "line_start": 3, + "suggested_replacement": null, + "suggestion_applicability": null, + "text": [ + { + "highlight_end": 31, + "highlight_start": 5, + "text": " let a = (0..10).collect();" + } + ] + }, + { + "byte_end": 61, + "byte_start": 60, + "column_end": 6, + "column_start": 5, + "expansion": null, + "file_name": "src/main.rs", + "is_primary": true, + "label": null, + "line_end": 4, + "line_start": 4, + "suggested_replacement": null, + "suggestion_applicability": null, + "text": [ + { + "highlight_end": 6, + "highlight_start": 5, + "text": " a" + } + ] + } + ] + } + "##, + ); + + let workspace_root = PathBuf::from("/test/"); + let diag = map_rust_diagnostic_to_lsp(&diag, &workspace_root).expect("couldn't map diagnostic"); + insta::assert_debug_snapshot!(diag); +} -- cgit v1.2.3