mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
introduce navigation target
This commit is contained in:
parent
a4b4fd7dc5
commit
d25c89f760
3 changed files with 28 additions and 13 deletions
|
@ -21,7 +21,7 @@ use ra_syntax::{
|
|||
|
||||
use crate::{
|
||||
AnalysisChange,
|
||||
Cancelable,
|
||||
Cancelable, NavigationTarget,
|
||||
completion::{CompletionItem, completions},
|
||||
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
||||
Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
|
||||
|
@ -355,9 +355,9 @@ impl AnalysisImpl {
|
|||
Ok(Some((binding, descr)))
|
||||
}
|
||||
}
|
||||
pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
|
||||
let file = self.db.source_file(file_id);
|
||||
let result = match (symbol.description(&file), symbol.docs(&file)) {
|
||||
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||
let file = self.db.source_file(nav.file_id);
|
||||
let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) {
|
||||
(Some(desc), Some(docs)) => {
|
||||
Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs)
|
||||
}
|
||||
|
|
|
@ -244,6 +244,21 @@ impl Query {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NavigationTarget {
|
||||
file_id: FileId,
|
||||
symbol: FileSymbol,
|
||||
}
|
||||
|
||||
impl NavigationTarget {
|
||||
pub fn file_id(&self) -> FileId {
|
||||
self.file_id
|
||||
}
|
||||
pub fn range(&self) -> TextRange {
|
||||
self.symbol.node_range
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of "goto def" query.
|
||||
#[derive(Debug)]
|
||||
pub struct ReferenceResolution {
|
||||
|
@ -252,7 +267,7 @@ pub struct ReferenceResolution {
|
|||
/// client where the reference was.
|
||||
pub reference_range: TextRange,
|
||||
/// What this reference resolves to.
|
||||
pub resolves_to: Vec<(FileId, FileSymbol)>,
|
||||
pub resolves_to: Vec<NavigationTarget>,
|
||||
}
|
||||
|
||||
impl ReferenceResolution {
|
||||
|
@ -264,7 +279,7 @@ impl ReferenceResolution {
|
|||
}
|
||||
|
||||
fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) {
|
||||
self.resolves_to.push((file_id, symbol))
|
||||
self.resolves_to.push(NavigationTarget { file_id, symbol })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,8 +349,8 @@ impl Analysis {
|
|||
pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
|
||||
self.imp.find_all_refs(position)
|
||||
}
|
||||
pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
|
||||
self.imp.doc_text_for(file_id, symbol)
|
||||
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||
self.imp.doc_text_for(nav)
|
||||
}
|
||||
pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||
self.imp.parent_module(position)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue