Skip to content

Commit af7e300

Browse files
committed
Remove confusing API
1 parent 34072d5 commit af7e300

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

crates/ra_ide/src/display/navigation_target.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ra_syntax::{
1111
TextRange,
1212
};
1313

14-
use crate::{FileRange, FileSymbol};
14+
use crate::FileSymbol;
1515

1616
use super::short_label::ShortLabel;
1717

@@ -47,6 +47,19 @@ impl NavigationTarget {
4747
pub fn range(&self) -> TextRange {
4848
self.focus_range.unwrap_or(self.full_range)
4949
}
50+
/// A "most interesting" range withing the `full_range`.
51+
///
52+
/// Typically, `full_range` is the whole syntax node,
53+
/// including doc comments, and `focus_range` is the range of the identifier.
54+
pub fn focus_range(&self) -> Option<TextRange> {
55+
self.focus_range
56+
}
57+
pub fn full_range(&self) -> TextRange {
58+
self.full_range
59+
}
60+
pub fn file_id(&self) -> FileId {
61+
self.file_id
62+
}
5063

5164
pub fn name(&self) -> &SmolStr {
5265
&self.name
@@ -60,19 +73,6 @@ impl NavigationTarget {
6073
self.kind
6174
}
6275

63-
pub fn file_id(&self) -> FileId {
64-
self.file_id
65-
}
66-
67-
// TODO: inconsistent
68-
pub fn file_range(&self) -> FileRange {
69-
FileRange { file_id: self.file_id, range: self.full_range }
70-
}
71-
72-
pub fn full_range(&self) -> TextRange {
73-
self.full_range
74-
}
75-
7676
pub fn docs(&self) -> Option<&str> {
7777
self.docs.as_deref()
7878
}
@@ -81,14 +81,6 @@ impl NavigationTarget {
8181
self.description.as_deref()
8282
}
8383

84-
/// A "most interesting" range withing the `full_range`.
85-
///
86-
/// Typically, `full_range` is the whole syntax node,
87-
/// including doc comments, and `focus_range` is the range of the identifier.
88-
pub fn focus_range(&self) -> Option<TextRange> {
89-
self.focus_range
90-
}
91-
9284
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
9385
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
9486
if let Some(src) = module.declaration_source(db) {

crates/ra_ide/src/goto_implementation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn impls_for_trait(
7676
mod tests {
7777
use ra_db::FileRange;
7878

79-
use crate::mock_analysis::{analysis_and_position, MockAnalysis};
79+
use crate::mock_analysis::MockAnalysis;
8080

8181
fn check(ra_fixture: &str) {
8282
let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);

crates/rust-analyzer/src/handlers.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ pub(crate) fn handle_workspace_symbol(
330330
fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
331331
let mut res = Vec::new();
332332
for nav in snap.analysis.symbol_search(query)? {
333+
let container_name = nav.container_name().map(|v| v.to_string());
333334
let info = SymbolInformation {
334335
name: nav.name().to_string(),
335336
kind: to_proto::symbol_kind(nav.kind()),
336-
location: to_proto::location(snap, nav.file_range())?,
337-
container_name: nav.container_name().map(|v| v.to_string()),
337+
location: to_proto::location_from_nav(snap, nav)?,
338+
container_name,
338339
deprecated: None,
339340
};
340341
res.push(info);
@@ -1213,8 +1214,8 @@ fn show_impl_command_link(
12131214
let position = to_proto::position(&line_index, position.offset);
12141215
let locations: Vec<_> = nav_data
12151216
.info
1216-
.iter()
1217-
.filter_map(|it| to_proto::location(snap, it.file_range()).ok())
1217+
.into_iter()
1218+
.filter_map(|nav| to_proto::location_from_nav(snap, nav).ok())
12181219
.collect();
12191220
let title = implementation_title(locations.len());
12201221
let command = show_references_command(title, &uri, position, locations);

crates/rust-analyzer/src/to_proto.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ pub(crate) fn location(
446446
Ok(loc)
447447
}
448448

449+
/// Perefer using `location_link`, if the client has the cap.
450+
pub(crate) fn location_from_nav(
451+
snap: &GlobalStateSnapshot,
452+
nav: NavigationTarget,
453+
) -> Result<lsp_types::Location> {
454+
let url = url(snap, nav.file_id());
455+
let line_index = snap.analysis.file_line_index(nav.file_id())?;
456+
let range = range(&line_index, nav.full_range());
457+
let loc = lsp_types::Location::new(url, range);
458+
Ok(loc)
459+
}
460+
449461
pub(crate) fn location_link(
450462
snap: &GlobalStateSnapshot,
451463
src: Option<FileRange>,

0 commit comments

Comments
 (0)