diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 18:20:11 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 18:20:11 +0000 |
commit | 97b07ac393caebaa76099f97672ad4399c0ceda6 (patch) | |
tree | fa7a1b323011fc2e2a1b9edc3191b424b9bb9e90 /crates/ra_analysis/src/lib.rs | |
parent | 51f669606cfbd29f3e9a3695810ead4124f49e84 (diff) | |
parent | 7fd6a41127dc9a60efe703f7d588f8555b8bffc6 (diff) |
Merge #265
265: Refactor symbol resolve API r=matklad a=matklad
Introduce ReferenceResolution to avoid nesting to many non-nominal
types.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index d33f3e4ca..eaf24cb36 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -178,6 +178,30 @@ impl Query { | |||
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | /// Result of "goto def" query. | ||
182 | #[derive(Debug)] | ||
183 | pub struct ReferenceResolution { | ||
184 | /// The range of the reference itself. Client does not know what constitutes | ||
185 | /// a reference, it handles us only the offset. It's helpful to tell the | ||
186 | /// client where the reference was. | ||
187 | pub reference_range: TextRange, | ||
188 | /// What this reference resolves to. | ||
189 | pub resolves_to: Vec<(FileId, FileSymbol)>, | ||
190 | } | ||
191 | |||
192 | impl ReferenceResolution { | ||
193 | fn new(reference_range: TextRange) -> ReferenceResolution { | ||
194 | ReferenceResolution { | ||
195 | reference_range, | ||
196 | resolves_to: Vec::new(), | ||
197 | } | ||
198 | } | ||
199 | |||
200 | fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { | ||
201 | self.resolves_to.push((file_id, symbol)) | ||
202 | } | ||
203 | } | ||
204 | |||
181 | /// Analysis is a snapshot of a world state at a moment in time. It is the main | 205 | /// Analysis is a snapshot of a world state at a moment in time. It is the main |
182 | /// entry point for asking semantic information about the world. When the world | 206 | /// entry point for asking semantic information about the world. When the world |
183 | /// state is advanced using `AnalysisHost::apply_change` method, all existing | 207 | /// state is advanced using `AnalysisHost::apply_change` method, all existing |
@@ -236,7 +260,7 @@ impl Analysis { | |||
236 | pub fn approximately_resolve_symbol( | 260 | pub fn approximately_resolve_symbol( |
237 | &self, | 261 | &self, |
238 | position: FilePosition, | 262 | position: FilePosition, |
239 | ) -> Cancelable<Option<(TextRange, Vec<(FileId, FileSymbol)>)>> { | 263 | ) -> Cancelable<Option<ReferenceResolution>> { |
240 | self.imp.approximately_resolve_symbol(position) | 264 | self.imp.approximately_resolve_symbol(position) |
241 | } | 265 | } |
242 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 266 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |