From a1f080138ae6f45088ba48ac4f24834a85d14c66 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 9 Mar 2021 15:45:31 +0100 Subject: Fix unused definitions not being document highlit --- crates/rust-analyzer/src/handlers.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 4f6f250d6..e81fc9926 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1135,20 +1135,13 @@ pub(crate) fn handle_document_highlight( None }; - let res = refs - .references - .get(&position.file_id) - .map(|file_refs| { - file_refs - .into_iter() - .map(|&(range, access)| DocumentHighlight { - range: to_proto::range(&line_index, range), - kind: access.map(to_proto::document_highlight_kind), - }) - .chain(decl) - .collect() - }) - .unwrap_or_default(); + let file_refs = refs.references.get(&position.file_id).map_or(&[][..], Vec::as_slice); + let mut res = Vec::with_capacity(file_refs.len() + 1); + res.extend(decl); + res.extend(file_refs.iter().map(|&(range, access)| DocumentHighlight { + range: to_proto::range(&line_index, range), + kind: access.map(to_proto::document_highlight_kind), + })); Ok(Some(res)) } -- cgit v1.2.3