Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ide::{
ReferenceCategory, Runnable, RunnableKind, SingleResolve, SourceChange, TextEdit,
};
use ide_db::SymbolKind;
use itertools::Itertools;
use lsp_server::ErrorCode;
use lsp_types::{
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
Expand Down Expand Up @@ -1055,9 +1056,8 @@ pub(crate) fn handle_references(
let exclude_imports = snap.config.find_all_refs_exclude_imports();
let exclude_tests = snap.config.find_all_refs_exclude_tests();

let refs = match snap.analysis.find_all_refs(position, None)? {
None => return Ok(None),
Some(refs) => refs,
let Some(refs) = snap.analysis.find_all_refs(position, None)? else {
return Ok(None);
};

let include_declaration = params.context.include_declaration;
Expand All @@ -1084,6 +1084,7 @@ pub(crate) fn handle_references(
})
.chain(decl)
})
.unique()
.filter_map(|frange| to_proto::location(&snap, frange).ok())
.collect();

Expand Down Expand Up @@ -1802,10 +1803,10 @@ fn show_ref_command_link(
.into_iter()
.flat_map(|res| res.references)
.flat_map(|(file_id, ranges)| {
ranges.into_iter().filter_map(move |(range, _)| {
to_proto::location(snap, FileRange { file_id, range }).ok()
})
ranges.into_iter().map(move |(range, _)| FileRange { file_id, range })
})
.unique()
.filter_map(|range| to_proto::location(snap, range).ok())
.collect();
let title = to_proto::reference_title(locations.len());
let command = to_proto::command::show_references(title, &uri, position, locations);
Expand Down
7 changes: 4 additions & 3 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,15 +904,16 @@ pub(crate) fn goto_definition_response(
if snap.config.location_link() {
let links = targets
.into_iter()
.unique_by(|nav| (nav.file_id, nav.full_range, nav.focus_range))
.map(|nav| location_link(snap, src, nav))
.collect::<Cancellable<Vec<_>>>()?;
Ok(links.into())
} else {
let locations = targets
.into_iter()
.map(|nav| {
location(snap, FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() })
})
.map(|nav| FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() })
.unique()
.map(|range| location(snap, range))
.collect::<Cancellable<Vec<_>>>()?;
Ok(locations.into())
}
Expand Down
16 changes: 16 additions & 0 deletions crates/stdx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ pub fn slice_tails<T>(this: &[T]) -> impl Iterator<Item = &[T]> {
(0..this.len()).map(|i| &this[i..])
}

pub trait IsNoneOr {
type Type;
#[allow(clippy::wrong_self_convention)]
fn is_none_or(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
}
#[allow(unstable_name_collisions)]
impl<T> IsNoneOr for Option<T> {
type Type = T;
fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
match self {
Some(v) => f(v),
None => true,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down