From 96da53fc567f52cf3cb5417f8e5e222529a30db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 22 Mar 2020 16:45:15 +0200 Subject: Only include machine-applicable suggestions --- crates/ra_cargo_watch/src/conv.rs | 14 +++--- ...watch__conv__test__snap_clippy_pass_by_ref.snap | 52 +++++++--------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index c6f8ca329..817543deb 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs @@ -1,7 +1,8 @@ //! This module provides the functionality needed to convert diagnostics from //! `cargo check` json format to the LSP diagnostic format. use cargo_metadata::diagnostic::{ - Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion, + Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, + DiagnosticSpanMacroExpansion, }; use lsp_types::{ CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, @@ -136,10 +137,13 @@ fn map_rust_child_diagnostic( let mut edit_map: HashMap> = HashMap::new(); for &span in &spans { - if let Some(suggested_replacement) = &span.suggested_replacement { - let location = map_span_to_location(span, workspace_root); - let edit = TextEdit::new(location.range, suggested_replacement.clone()); - edit_map.entry(location.uri).or_default().push(edit); + match (&span.suggestion_applicability, &span.suggested_replacement) { + (Some(Applicability::MachineApplicable), Some(suggested_replacement)) => { + let location = map_span_to_location(span, workspace_root); + let edit = TextEdit::new(location.range, suggested_replacement.clone()); + edit_map.entry(location.uri).or_default().push(edit); + } + _ => {} } } 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 9e8f4eff4..a59fa84fa 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 @@ -58,44 +58,26 @@ expression: diag }, message: "lint level defined here", }, + DiagnosticRelatedInformation { + location: Location { + uri: "file:///test/compiler/mir/tagset.rs", + range: Range { + start: Position { + line: 41, + character: 23, + }, + end: Position { + line: 41, + character: 28, + }, + }, + }, + message: "consider passing by value instead", + }, ], ), tags: None, }, - fixes: [ - CodeAction { - title: "consider passing by value instead", - kind: Some( - "quickfix", - ), - diagnostics: None, - edit: Some( - WorkspaceEdit { - changes: Some( - { - "file:///test/compiler/mir/tagset.rs": [ - TextEdit { - range: Range { - start: Position { - line: 41, - character: 23, - }, - end: Position { - line: 41, - character: 28, - }, - }, - new_text: "self", - }, - ], - }, - ), - document_changes: None, - }, - ), - command: None, - is_preferred: None, - }, - ], + fixes: [], }, ] -- cgit v1.2.3