mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
introduce navigation target
This commit is contained in:
parent
a4b4fd7dc5
commit
d25c89f760
@ -21,7 +21,7 @@ use ra_syntax::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AnalysisChange,
|
AnalysisChange,
|
||||||
Cancelable,
|
Cancelable, NavigationTarget,
|
||||||
completion::{CompletionItem, completions},
|
completion::{CompletionItem, completions},
|
||||||
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
||||||
Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
|
Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
|
||||||
@ -355,9 +355,9 @@ impl AnalysisImpl {
|
|||||||
Ok(Some((binding, descr)))
|
Ok(Some((binding, descr)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
|
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||||
let file = self.db.source_file(file_id);
|
let file = self.db.source_file(nav.file_id);
|
||||||
let result = match (symbol.description(&file), symbol.docs(&file)) {
|
let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) {
|
||||||
(Some(desc), Some(docs)) => {
|
(Some(desc), Some(docs)) => {
|
||||||
Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*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.
|
/// Result of "goto def" query.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ReferenceResolution {
|
pub struct ReferenceResolution {
|
||||||
@ -252,7 +267,7 @@ pub struct ReferenceResolution {
|
|||||||
/// client where the reference was.
|
/// client where the reference was.
|
||||||
pub reference_range: TextRange,
|
pub reference_range: TextRange,
|
||||||
/// What this reference resolves to.
|
/// What this reference resolves to.
|
||||||
pub resolves_to: Vec<(FileId, FileSymbol)>,
|
pub resolves_to: Vec<NavigationTarget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReferenceResolution {
|
impl ReferenceResolution {
|
||||||
@ -264,7 +279,7 @@ impl ReferenceResolution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) {
|
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)>> {
|
pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
|
||||||
self.imp.find_all_refs(position)
|
self.imp.find_all_refs(position)
|
||||||
}
|
}
|
||||||
pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
|
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||||
self.imp.doc_text_for(file_id, symbol)
|
self.imp.doc_text_for(nav)
|
||||||
}
|
}
|
||||||
pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
self.imp.parent_module(position)
|
self.imp.parent_module(position)
|
||||||
|
@ -213,9 +213,9 @@ pub fn handle_goto_definition(
|
|||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for (file_id, symbol) in rr.resolves_to {
|
for nav in rr.resolves_to {
|
||||||
let line_index = world.analysis().file_line_index(file_id);
|
let line_index = world.analysis().file_line_index(nav.file_id());
|
||||||
let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
|
let location = to_location(nav.file_id(), nav.range(), &world, &line_index)?;
|
||||||
res.push(location)
|
res.push(location)
|
||||||
}
|
}
|
||||||
Ok(Some(req::GotoDefinitionResponse::Array(res)))
|
Ok(Some(req::GotoDefinitionResponse::Array(res)))
|
||||||
@ -517,8 +517,8 @@ pub fn handle_hover(
|
|||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for (file_id, symbol) in rr.resolves_to {
|
for nav in rr.resolves_to {
|
||||||
if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? {
|
if let Some(docs) = world.analysis().doc_text_for(nav)? {
|
||||||
result.push(docs);
|
result.push(docs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user