2
2
//! Protocol. This module specifically handles requests.
3
3
4
4
use std:: {
5
- collections:: HashSet ,
6
5
fs,
7
6
io:: Write as _,
8
7
path:: PathBuf ,
@@ -14,10 +13,10 @@ use anyhow::Context;
14
13
use ide:: {
15
14
AnnotationConfig , AssistKind , AssistResolveStrategy , Cancellable , FilePosition , FileRange ,
16
15
HoverAction , HoverGotoTypeData , InlayFieldsToResolve , Query , RangeInfo , RangeLimit ,
17
- ReferenceCategory , ReferenceSearchResult , Runnable , RunnableKind , SingleResolve , SourceChange ,
18
- TextEdit ,
16
+ ReferenceCategory , Runnable , RunnableKind , SingleResolve , SourceChange , TextEdit ,
19
17
} ;
20
18
use ide_db:: SymbolKind ;
19
+ use itertools:: Itertools ;
21
20
use lsp_server:: ErrorCode ;
22
21
use lsp_types:: {
23
22
CallHierarchyIncomingCall , CallHierarchyIncomingCallsParams , CallHierarchyItem ,
@@ -30,8 +29,6 @@ use lsp_types::{
30
29
} ;
31
30
use project_model:: { ManifestPath , ProjectWorkspace , TargetKind } ;
32
31
use serde_json:: json;
33
- #[ allow( unused_imports) ]
34
- use stdx:: IsNoneOr ;
35
32
use stdx:: { format_to, never} ;
36
33
use syntax:: { algo, ast, AstNode , TextRange , TextSize } ;
37
34
use triomphe:: Arc ;
@@ -1059,10 +1056,9 @@ pub(crate) fn handle_references(
1059
1056
let exclude_imports = snap. config . find_all_refs_exclude_imports ( ) ;
1060
1057
let exclude_tests = snap. config . find_all_refs_exclude_tests ( ) ;
1061
1058
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 {
1063
1060
return Ok ( None ) ;
1064
1061
} ;
1065
- deduplicate_declarations ( & mut refs) ;
1066
1062
1067
1063
let include_declaration = params. context . include_declaration ;
1068
1064
let locations = refs
@@ -1088,23 +1084,13 @@ pub(crate) fn handle_references(
1088
1084
} )
1089
1085
. chain ( decl)
1090
1086
} )
1087
+ . unique ( )
1091
1088
. filter_map ( |frange| to_proto:: location ( & snap, frange) . ok ( ) )
1092
1089
. collect ( ) ;
1093
1090
1094
1091
Ok ( Some ( locations) )
1095
1092
}
1096
1093
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
-
1108
1094
pub ( crate ) fn handle_formatting (
1109
1095
snap : GlobalStateSnapshot ,
1110
1096
params : lsp_types:: DocumentFormattingParams ,
@@ -1809,21 +1795,18 @@ fn show_ref_command_link(
1809
1795
position : & FilePosition ,
1810
1796
) -> Option < lsp_ext:: CommandLinkGroup > {
1811
1797
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 ) {
1816
1799
let uri = to_proto:: url ( snap, position. file_id ) ;
1817
1800
let line_index = snap. file_line_index ( position. file_id ) . ok ( ) ?;
1818
1801
let position = to_proto:: position ( & line_index, position. offset ) ;
1819
1802
let locations: Vec < _ > = ref_search_res
1820
1803
. into_iter ( )
1821
1804
. flat_map ( |res| res. references )
1822
1805
. 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 } )
1826
1807
} )
1808
+ . unique ( )
1809
+ . filter_map ( |range| to_proto:: location ( snap, range) . ok ( ) )
1827
1810
. collect ( ) ;
1828
1811
let title = to_proto:: reference_title ( locations. len ( ) ) ;
1829
1812
let command = to_proto:: command:: show_references ( title, & uri, position, locations) ;
0 commit comments