mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
Remove confusing API
This commit is contained in:
parent
34072d53b6
commit
af7e300041
4 changed files with 32 additions and 27 deletions
|
@ -11,7 +11,7 @@ use ra_syntax::{
|
||||||
TextRange,
|
TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{FileRange, FileSymbol};
|
use crate::FileSymbol;
|
||||||
|
|
||||||
use super::short_label::ShortLabel;
|
use super::short_label::ShortLabel;
|
||||||
|
|
||||||
|
@ -47,6 +47,19 @@ impl NavigationTarget {
|
||||||
pub fn range(&self) -> TextRange {
|
pub fn range(&self) -> TextRange {
|
||||||
self.focus_range.unwrap_or(self.full_range)
|
self.focus_range.unwrap_or(self.full_range)
|
||||||
}
|
}
|
||||||
|
/// A "most interesting" range withing the `full_range`.
|
||||||
|
///
|
||||||
|
/// Typically, `full_range` is the whole syntax node,
|
||||||
|
/// including doc comments, and `focus_range` is the range of the identifier.
|
||||||
|
pub fn focus_range(&self) -> Option<TextRange> {
|
||||||
|
self.focus_range
|
||||||
|
}
|
||||||
|
pub fn full_range(&self) -> TextRange {
|
||||||
|
self.full_range
|
||||||
|
}
|
||||||
|
pub fn file_id(&self) -> FileId {
|
||||||
|
self.file_id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &SmolStr {
|
pub fn name(&self) -> &SmolStr {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -60,19 +73,6 @@ impl NavigationTarget {
|
||||||
self.kind
|
self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_id(&self) -> FileId {
|
|
||||||
self.file_id
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: inconsistent
|
|
||||||
pub fn file_range(&self) -> FileRange {
|
|
||||||
FileRange { file_id: self.file_id, range: self.full_range }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn full_range(&self) -> TextRange {
|
|
||||||
self.full_range
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn docs(&self) -> Option<&str> {
|
pub fn docs(&self) -> Option<&str> {
|
||||||
self.docs.as_deref()
|
self.docs.as_deref()
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,6 @@ impl NavigationTarget {
|
||||||
self.description.as_deref()
|
self.description.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A "most interesting" range withing the `full_range`.
|
|
||||||
///
|
|
||||||
/// Typically, `full_range` is the whole syntax node,
|
|
||||||
/// including doc comments, and `focus_range` is the range of the identifier.
|
|
||||||
pub fn focus_range(&self) -> Option<TextRange> {
|
|
||||||
self.focus_range
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
|
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
|
||||||
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
||||||
if let Some(src) = module.declaration_source(db) {
|
if let Some(src) = module.declaration_source(db) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn impls_for_trait(
|
||||||
mod tests {
|
mod tests {
|
||||||
use ra_db::FileRange;
|
use ra_db::FileRange;
|
||||||
|
|
||||||
use crate::mock_analysis::{analysis_and_position, MockAnalysis};
|
use crate::mock_analysis::MockAnalysis;
|
||||||
|
|
||||||
fn check(ra_fixture: &str) {
|
fn check(ra_fixture: &str) {
|
||||||
let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
|
let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
|
||||||
|
|
|
@ -330,11 +330,12 @@ pub(crate) fn handle_workspace_symbol(
|
||||||
fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
|
fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for nav in snap.analysis.symbol_search(query)? {
|
for nav in snap.analysis.symbol_search(query)? {
|
||||||
|
let container_name = nav.container_name().map(|v| v.to_string());
|
||||||
let info = SymbolInformation {
|
let info = SymbolInformation {
|
||||||
name: nav.name().to_string(),
|
name: nav.name().to_string(),
|
||||||
kind: to_proto::symbol_kind(nav.kind()),
|
kind: to_proto::symbol_kind(nav.kind()),
|
||||||
location: to_proto::location(snap, nav.file_range())?,
|
location: to_proto::location_from_nav(snap, nav)?,
|
||||||
container_name: nav.container_name().map(|v| v.to_string()),
|
container_name,
|
||||||
deprecated: None,
|
deprecated: None,
|
||||||
};
|
};
|
||||||
res.push(info);
|
res.push(info);
|
||||||
|
@ -1213,8 +1214,8 @@ fn show_impl_command_link(
|
||||||
let position = to_proto::position(&line_index, position.offset);
|
let position = to_proto::position(&line_index, position.offset);
|
||||||
let locations: Vec<_> = nav_data
|
let locations: Vec<_> = nav_data
|
||||||
.info
|
.info
|
||||||
.iter()
|
.into_iter()
|
||||||
.filter_map(|it| to_proto::location(snap, it.file_range()).ok())
|
.filter_map(|nav| to_proto::location_from_nav(snap, nav).ok())
|
||||||
.collect();
|
.collect();
|
||||||
let title = implementation_title(locations.len());
|
let title = implementation_title(locations.len());
|
||||||
let command = show_references_command(title, &uri, position, locations);
|
let command = show_references_command(title, &uri, position, locations);
|
||||||
|
|
|
@ -446,6 +446,18 @@ pub(crate) fn location(
|
||||||
Ok(loc)
|
Ok(loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perefer using `location_link`, if the client has the cap.
|
||||||
|
pub(crate) fn location_from_nav(
|
||||||
|
snap: &GlobalStateSnapshot,
|
||||||
|
nav: NavigationTarget,
|
||||||
|
) -> Result<lsp_types::Location> {
|
||||||
|
let url = url(snap, nav.file_id());
|
||||||
|
let line_index = snap.analysis.file_line_index(nav.file_id())?;
|
||||||
|
let range = range(&line_index, nav.full_range());
|
||||||
|
let loc = lsp_types::Location::new(url, range);
|
||||||
|
Ok(loc)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn location_link(
|
pub(crate) fn location_link(
|
||||||
snap: &GlobalStateSnapshot,
|
snap: &GlobalStateSnapshot,
|
||||||
src: Option<FileRange>,
|
src: Option<FileRange>,
|
||||||
|
|
Loading…
Reference in a new issue