diff options
author | Aleksey Kladov <[email protected]> | 2019-01-02 13:53:40 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-02 13:53:40 +0000 |
commit | d25c89f7608cb15e8c5ae08a92b6a7a6d6f308b8 (patch) | |
tree | c0897017ca009f4b989ef70b27e3a0dc54ffe63c /crates/ra_analysis | |
parent | a4b4fd7dc50575d015b404532ec9dd13e0a01835 (diff) |
introduce navigation target
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 8 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 23 |
2 files changed, 23 insertions, 8 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index f3b513de1..836fb89f5 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -21,7 +21,7 @@ use ra_syntax::{ | |||
21 | 21 | ||
22 | use crate::{ | 22 | use crate::{ |
23 | AnalysisChange, | 23 | AnalysisChange, |
24 | Cancelable, | 24 | Cancelable, NavigationTarget, |
25 | completion::{CompletionItem, completions}, | 25 | completion::{CompletionItem, completions}, |
26 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, | 26 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, |
27 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, | 27 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, |
@@ -355,9 +355,9 @@ impl AnalysisImpl { | |||
355 | Ok(Some((binding, descr))) | 355 | Ok(Some((binding, descr))) |
356 | } | 356 | } |
357 | } | 357 | } |
358 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { | 358 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { |
359 | let file = self.db.source_file(file_id); | 359 | let file = self.db.source_file(nav.file_id); |
360 | let result = match (symbol.description(&file), symbol.docs(&file)) { | 360 | let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) { |
361 | (Some(desc), Some(docs)) => { | 361 | (Some(desc), Some(docs)) => { |
362 | Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs) | 362 | Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs) |
363 | } | 363 | } |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index ff28271ab..4d8bdb61b 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -244,6 +244,21 @@ impl Query { | |||
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | #[derive(Debug)] | ||
248 | pub struct NavigationTarget { | ||
249 | file_id: FileId, | ||
250 | symbol: FileSymbol, | ||
251 | } | ||
252 | |||
253 | impl NavigationTarget { | ||
254 | pub fn file_id(&self) -> FileId { | ||
255 | self.file_id | ||
256 | } | ||
257 | pub fn range(&self) -> TextRange { | ||
258 | self.symbol.node_range | ||
259 | } | ||
260 | } | ||
261 | |||
247 | /// Result of "goto def" query. | 262 | /// Result of "goto def" query. |
248 | #[derive(Debug)] | 263 | #[derive(Debug)] |
249 | pub struct ReferenceResolution { | 264 | pub struct ReferenceResolution { |
@@ -252,7 +267,7 @@ pub struct ReferenceResolution { | |||
252 | /// client where the reference was. | 267 | /// client where the reference was. |
253 | pub reference_range: TextRange, | 268 | pub reference_range: TextRange, |
254 | /// What this reference resolves to. | 269 | /// What this reference resolves to. |
255 | pub resolves_to: Vec<(FileId, FileSymbol)>, | 270 | pub resolves_to: Vec<NavigationTarget>, |
256 | } | 271 | } |
257 | 272 | ||
258 | impl ReferenceResolution { | 273 | impl ReferenceResolution { |
@@ -264,7 +279,7 @@ impl ReferenceResolution { | |||
264 | } | 279 | } |
265 | 280 | ||
266 | fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { | 281 | fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { |
267 | self.resolves_to.push((file_id, symbol)) | 282 | self.resolves_to.push(NavigationTarget { file_id, symbol }) |
268 | } | 283 | } |
269 | } | 284 | } |
270 | 285 | ||
@@ -334,8 +349,8 @@ impl Analysis { | |||
334 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 349 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
335 | self.imp.find_all_refs(position) | 350 | self.imp.find_all_refs(position) |
336 | } | 351 | } |
337 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { | 352 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { |
338 | self.imp.doc_text_for(file_id, symbol) | 353 | self.imp.doc_text_for(nav) |
339 | } | 354 | } |
340 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 355 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
341 | self.imp.parent_module(position) | 356 | self.imp.parent_module(position) |