From de05c3d406fb91dea736769c91cbc35f24abf761 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 4 Dec 2021 19:59:05 -0800 Subject: [PATCH] Refactor away unnecessary Vec --- crates/rust-analyzer/src/diagnostics.rs | 4 ++-- crates/rust-analyzer/src/diagnostics/to_proto.rs | 8 ++++---- crates/rust-analyzer/src/main_loop.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index 2f63c26ce516..c0dab4588930 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs @@ -43,7 +43,7 @@ pub(crate) fn add_check_diagnostic( &mut self, file_id: FileId, diagnostic: lsp_types::Diagnostic, - fixes: Vec, + fix: Option, ) { let diagnostics = self.check.entry(file_id).or_default(); for existing_diagnostic in diagnostics.iter() { @@ -56,7 +56,7 @@ pub(crate) fn add_check_diagnostic( check_fixes .entry(file_id) .or_default() - .extend(fixes.into_iter().map(|action| Fix { range: diagnostic.range, action })); + .extend(fix.into_iter().map(|action| Fix { range: diagnostic.range, action })); diagnostics.push(diagnostic); self.changes.insert(file_id); } diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 4739cabae55f..48af9c186dc0 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -192,7 +192,7 @@ fn map_rust_child_diagnostic( pub(crate) struct MappedRustDiagnostic { pub(crate) url: lsp_types::Url, pub(crate) diagnostic: lsp_types::Diagnostic, - pub(crate) fixes: Vec, + pub(crate) fix: Option, } /// Converts a Rust root diagnostic to LSP form @@ -349,7 +349,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( diagnostics.push(MappedRustDiagnostic { url: secondary_location.uri, diagnostic, - fixes: Vec::new(), + fix: None, }); } @@ -378,7 +378,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( tags: if tags.is_empty() { None } else { Some(tags.clone()) }, data: None, }, - fixes: Vec::new(), + fix: None, }); // Emit hint-level diagnostics for all `related_information` entries such as "help"s. @@ -395,7 +395,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( } diagnostics.push(MappedRustDiagnostic { url: sub.related.location.uri.clone(), - fixes: sub.suggested_fix.iter().cloned().collect(), + fix: sub.suggested_fix.clone(), diagnostic: lsp_types::Diagnostic { range: sub.related.location.range, severity: Some(lsp_types::DiagnosticSeverity::Hint), diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0c48b22bdbaa..c05a97eeed7c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -370,7 +370,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> { Ok(file_id) => self.diagnostics.add_check_diagnostic( file_id, diag.diagnostic, - diag.fixes, + diag.fix, ), Err(err) => { tracing::error!(