diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-17 15:38:33 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-17 15:38:33 +0000 |
commit | 982f72c022b45629e6adbaef22884359d3495ecf (patch) | |
tree | cc1a13dcf026a72d76496fb8ee2643619560f471 /crates/ra_ide_api/tests | |
parent | f937d11ad892036fa93b25a2c19d10dcebe4ab24 (diff) | |
parent | fd5307e60d268423f7026db28b15bd2b31575396 (diff) |
Merge #844
844: Refactor find_all_refs to return ReferenceSearchResult r=vipentti a=vipentti
This refactors `find_all_refs` to return a new `ReferenceSearchResult` based on feedback in #839.
There are few questions/notes regarding the refactor:
1. Introducing `NavigationTarget::from_bind_pat` this simply forwards the call to `NavigationTarget::from_named`, could we just expose `from_named` directly as `pub(crate)` ?
2. Added an utility method `NavigationTarget::range` since there were few places where you would use `self.focus_range.unwrap_or(self.full_range)`
3. Implementing `IntoIterator` for `ReferenceSearchResult`. This turns `ReferenceSearchResult` into an iterator over `FileRanges` and allows previous code to mostly stay as it was based on the order that `find_all_refs` previously had (declaration first and then the references). I'm not sure if there is a way of doing the conversion to `IntoIter` without the allocation of a new vector
4. Is it possible to have a binding without a name? I'm not sure if the `NavigationTarget::from_bind_pat` can cause some edge-cases that previously were ok
This fixes #835.
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/tests')
-rw-r--r-- | crates/ra_ide_api/tests/test/main.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 0526f7584..a83fbe07b 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use insta::assert_debug_snapshot_matches; | 1 | use insta::assert_debug_snapshot_matches; |
2 | use ra_ide_api::{ | 2 | use ra_ide_api::{ |
3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, | 3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, |
4 | AnalysisChange, CrateGraph, Edition::Edition2018, FileId, Query, NavigationTarget | 4 | AnalysisChange, CrateGraph, Edition::Edition2018, Query, NavigationTarget, |
5 | ReferenceSearchResult, | ||
5 | }; | 6 | }; |
6 | use ra_syntax::{TextRange, SmolStr}; | 7 | use ra_syntax::{TextRange, SmolStr}; |
7 | 8 | ||
@@ -44,9 +45,9 @@ fn test_resolve_crate_root() { | |||
44 | assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); | 45 | assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); |
45 | } | 46 | } |
46 | 47 | ||
47 | fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { | 48 | fn get_all_refs(text: &str) -> ReferenceSearchResult { |
48 | let (analysis, position) = single_file_with_position(text); | 49 | let (analysis, position) = single_file_with_position(text); |
49 | analysis.find_all_refs(position).unwrap() | 50 | analysis.find_all_refs(position).unwrap().unwrap() |
50 | } | 51 | } |
51 | 52 | ||
52 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | 53 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { |