aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-08 18:18:29 +0000
committerAleksey Kladov <[email protected]>2018-12-08 18:18:29 +0000
commit7fd6a41127dc9a60efe703f7d588f8555b8bffc6 (patch)
tree91695d49c0dd47ce0543161b57b8986fa37eeb6b /crates/ra_analysis/src/lib.rs
parent7a79cde107ec71abbc7c715e933f29f7a1fb2b95 (diff)
Refactor symbol resolve API
Introduce ReferenceResolution to avoid nesting to many non-nominal types.
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r--crates/ra_analysis/src/lib.rs26
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)]
183pub 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
192impl 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)>> {