introduce navigation target

This commit is contained in:
Aleksey Kladov 2019-01-02 16:53:40 +03:00
parent a4b4fd7dc5
commit d25c89f760
3 changed files with 28 additions and 13 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -213,9 +213,9 @@ pub fn handle_goto_definition(
Some(it) => it,
};
let mut res = Vec::new();
for (file_id, symbol) in rr.resolves_to {
let line_index = world.analysis().file_line_index(file_id);
let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
for nav in rr.resolves_to {
let line_index = world.analysis().file_line_index(nav.file_id());
let location = to_location(nav.file_id(), nav.range(), &world, &line_index)?;
res.push(location)
}
Ok(Some(req::GotoDefinitionResponse::Array(res)))
@ -517,8 +517,8 @@ pub fn handle_hover(
Some(it) => it,
};
let mut result = Vec::new();
for (file_id, symbol) in rr.resolves_to {
if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? {
for nav in rr.resolves_to {
if let Some(docs) = world.analysis().doc_text_for(nav)? {
result.push(docs);
}
}