22//! Protocol. This module specifically handles requests.
33
44use std:: {
5- collections:: HashSet ,
65 fs,
76 io:: Write as _,
87 path:: PathBuf ,
@@ -14,10 +13,10 @@ use anyhow::Context;
1413use ide:: {
1514 AnnotationConfig , AssistKind , AssistResolveStrategy , Cancellable , FilePosition , FileRange ,
1615 HoverAction , HoverGotoTypeData , InlayFieldsToResolve , Query , RangeInfo , RangeLimit ,
17- ReferenceCategory , ReferenceSearchResult , Runnable , RunnableKind , SingleResolve , SourceChange ,
18- TextEdit ,
16+ ReferenceCategory , Runnable , RunnableKind , SingleResolve , SourceChange , TextEdit ,
1917} ;
2018use ide_db:: SymbolKind ;
19+ use itertools:: Itertools ;
2120use lsp_server:: ErrorCode ;
2221use lsp_types:: {
2322 CallHierarchyIncomingCall , CallHierarchyIncomingCallsParams , CallHierarchyItem ,
@@ -30,8 +29,6 @@ use lsp_types::{
3029} ;
3130use project_model:: { ManifestPath , ProjectWorkspace , TargetKind } ;
3231use serde_json:: json;
33- #[ allow( unused_imports) ]
34- use stdx:: IsNoneOr ;
3532use stdx:: { format_to, never} ;
3633use syntax:: { algo, ast, AstNode , TextRange , TextSize } ;
3734use triomphe:: Arc ;
@@ -1059,10 +1056,9 @@ pub(crate) fn handle_references(
10591056 let exclude_imports = snap. config . find_all_refs_exclude_imports ( ) ;
10601057 let exclude_tests = snap. config . find_all_refs_exclude_tests ( ) ;
10611058
1062- let Some ( mut refs) = snap. analysis . find_all_refs ( position, None ) ? else {
1059+ let Some ( refs) = snap. analysis . find_all_refs ( position, None ) ? else {
10631060 return Ok ( None ) ;
10641061 } ;
1065- deduplicate_declarations ( & mut refs) ;
10661062
10671063 let include_declaration = params. context . include_declaration ;
10681064 let locations = refs
@@ -1088,23 +1084,13 @@ pub(crate) fn handle_references(
10881084 } )
10891085 . chain ( decl)
10901086 } )
1087+ . unique ( )
10911088 . filter_map ( |frange| to_proto:: location ( & snap, frange) . ok ( ) )
10921089 . collect ( ) ;
10931090
10941091 Ok ( Some ( locations) )
10951092}
10961093
1097- fn deduplicate_declarations ( refs : & mut Vec < ReferenceSearchResult > ) {
1098- if refs. iter ( ) . filter ( |decl| decl. declaration . is_some ( ) ) . take ( 2 ) . count ( ) > 1 {
1099- let mut seen_navigation_targets = HashSet :: new ( ) ;
1100- refs. retain ( |res| {
1101- res. declaration
1102- . as_ref ( )
1103- . is_none_or ( |decl| seen_navigation_targets. insert ( decl. nav . clone ( ) ) )
1104- } ) ;
1105- }
1106- }
1107-
11081094pub ( crate ) fn handle_formatting (
11091095 snap : GlobalStateSnapshot ,
11101096 params : lsp_types:: DocumentFormattingParams ,
@@ -1809,21 +1795,18 @@ fn show_ref_command_link(
18091795 position : & FilePosition ,
18101796) -> Option < lsp_ext:: CommandLinkGroup > {
18111797 if snap. config . hover_actions ( ) . references && snap. config . client_commands ( ) . show_reference {
1812- if let Some ( mut ref_search_res) =
1813- snap. analysis . find_all_refs ( * position, None ) . unwrap_or ( None )
1814- {
1815- deduplicate_declarations ( & mut ref_search_res) ;
1798+ if let Some ( ref_search_res) = snap. analysis . find_all_refs ( * position, None ) . unwrap_or ( None ) {
18161799 let uri = to_proto:: url ( snap, position. file_id ) ;
18171800 let line_index = snap. file_line_index ( position. file_id ) . ok ( ) ?;
18181801 let position = to_proto:: position ( & line_index, position. offset ) ;
18191802 let locations: Vec < _ > = ref_search_res
18201803 . into_iter ( )
18211804 . flat_map ( |res| res. references )
18221805 . flat_map ( |( file_id, ranges) | {
1823- ranges. into_iter ( ) . filter_map ( move |( range, _) | {
1824- to_proto:: location ( snap, FileRange { file_id, range } ) . ok ( )
1825- } )
1806+ ranges. into_iter ( ) . map ( move |( range, _) | FileRange { file_id, range } )
18261807 } )
1808+ . unique ( )
1809+ . filter_map ( |range| to_proto:: location ( snap, range) . ok ( ) )
18271810 . collect ( ) ;
18281811 let title = to_proto:: reference_title ( locations. len ( ) ) ;
18291812 let command = to_proto:: command:: show_references ( title, & uri, position, locations) ;
0 commit comments