aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-12 14:51:02 +0000
committerLukas Wirth <[email protected]>2021-01-12 14:51:02 +0000
commit2c1777a2e264e58fccd5ace94b238c8a497ddbda (patch)
treee7d47c95c6bcdeecd5f321f4ca969d04ca90dff7 /crates/rust-analyzer
parentfbdb32adfc49e0d69b7fd8e44135bea59382d2cb (diff)
Ensure uniqueness of file ids in reference search via hashmap
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r--crates/rust-analyzer/src/handlers.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index d862f370a..2cc57f022 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -12,7 +12,6 @@ use ide::{
12 FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, LineIndex, NavigationTarget, 12 FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, LineIndex, NavigationTarget,
13 Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, SymbolKind, TextEdit, 13 Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, SymbolKind, TextEdit,
14}; 14};
15use ide_db::search::FileReferences;
16use itertools::Itertools; 15use itertools::Itertools;
17use lsp_server::ErrorCode; 16use lsp_server::ErrorCode;
18use lsp_types::{ 17use lsp_types::{
@@ -813,18 +812,14 @@ pub(crate) fn handle_references(
813 }; 812 };
814 813
815 let locations = if params.context.include_declaration { 814 let locations = if params.context.include_declaration {
816 let mut locations = Vec::default(); 815 refs.references_with_declaration()
817 refs.into_iter().for_each(|it| { 816 .file_ranges()
818 locations.extend( 817 .filter_map(|frange| to_proto::location(&snap, frange).ok())
819 it.file_ranges().filter_map(|frange| to_proto::location(&snap, frange).ok()), 818 .collect()
820 )
821 });
822 locations
823 } else { 819 } else {
824 // Only iterate over the references if include_declaration was false 820 // Only iterate over the references if include_declaration was false
825 refs.references() 821 refs.references()
826 .iter() 822 .file_ranges()
827 .flat_map(FileReferences::file_ranges)
828 .filter_map(|frange| to_proto::location(&snap, frange).ok()) 823 .filter_map(|frange| to_proto::location(&snap, frange).ok())
829 .collect() 824 .collect()
830 }; 825 };
@@ -1181,8 +1176,7 @@ pub(crate) fn handle_code_lens_resolve(
1181 .unwrap_or(None) 1176 .unwrap_or(None)
1182 .map(|r| { 1177 .map(|r| {
1183 r.references() 1178 r.references()
1184 .iter() 1179 .file_ranges()
1185 .flat_map(FileReferences::file_ranges)
1186 .filter_map(|frange| to_proto::location(&snap, frange).ok()) 1180 .filter_map(|frange| to_proto::location(&snap, frange).ok())
1187 .collect_vec() 1181 .collect_vec()
1188 }) 1182 })
@@ -1227,11 +1221,11 @@ pub(crate) fn handle_document_highlight(
1227 }; 1221 };
1228 1222
1229 let res = refs 1223 let res = refs
1230 .into_iter() 1224 .references_with_declaration()
1231 .find(|refs| refs.file_id == position.file_id) 1225 .references
1226 .get(&position.file_id)
1232 .map(|file_refs| { 1227 .map(|file_refs| {
1233 file_refs 1228 file_refs
1234 .references
1235 .into_iter() 1229 .into_iter()
1236 .map(|r| DocumentHighlight { 1230 .map(|r| DocumentHighlight {
1237 range: to_proto::range(&line_index, r.range), 1231 range: to_proto::range(&line_index, r.range),