From 7fd6a41127dc9a60efe703f7d588f8555b8bffc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Dec 2018 21:18:29 +0300 Subject: Refactor symbol resolve API Introduce ReferenceResolution to avoid nesting to many non-nominal types. --- crates/ra_analysis/src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src/lib.rs') 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 { } } +/// Result of "goto def" query. +#[derive(Debug)] +pub struct ReferenceResolution { + /// The range of the reference itself. Client does not know what constitutes + /// a reference, it handles us only the offset. It's helpful to tell the + /// client where the reference was. + pub reference_range: TextRange, + /// What this reference resolves to. + pub resolves_to: Vec<(FileId, FileSymbol)>, +} + +impl ReferenceResolution { + fn new(reference_range: TextRange) -> ReferenceResolution { + ReferenceResolution { + reference_range, + resolves_to: Vec::new(), + } + } + + fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { + self.resolves_to.push((file_id, symbol)) + } +} + /// Analysis is a snapshot of a world state at a moment in time. It is the main /// entry point for asking semantic information about the world. When the world /// state is advanced using `AnalysisHost::apply_change` method, all existing @@ -236,7 +260,7 @@ impl Analysis { pub fn approximately_resolve_symbol( &self, position: FilePosition, - ) -> Cancelable)>> { + ) -> Cancelable> { self.imp.approximately_resolve_symbol(position) } pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { -- cgit v1.2.3