aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-30 12:27:13 +0100
committerAleksey Kladov <[email protected]>2020-06-30 12:29:53 +0100
commitaf7e300041b1af68e671446fe22d2b9e5d30f83d (patch)
tree18b444a0d447465a7de75ec5a0153c90b8566a7f /crates
parent34072d53b683805f449bf106d16788f171ca3522 (diff)
Remove confusing API
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs36
-rw-r--r--crates/ra_ide/src/goto_implementation.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs9
-rw-r--r--crates/rust-analyzer/src/to_proto.rs12
4 files changed, 32 insertions, 27 deletions
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index f8a466304..8bf2428ed 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11 TextRange, 11 TextRange,
12}; 12};
13 13
14use crate::{FileRange, FileSymbol}; 14use crate::FileSymbol;
15 15
16use super::short_label::ShortLabel; 16use super::short_label::ShortLabel;
17 17
@@ -47,6 +47,19 @@ impl NavigationTarget {
47 pub fn range(&self) -> TextRange { 47 pub fn range(&self) -> TextRange {
48 self.focus_range.unwrap_or(self.full_range) 48 self.focus_range.unwrap_or(self.full_range)
49 } 49 }
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 }
50 63
51 pub fn name(&self) -> &SmolStr { 64 pub fn name(&self) -> &SmolStr {
52 &self.name 65 &self.name
@@ -60,19 +73,6 @@ impl NavigationTarget {
60 self.kind 73 self.kind
61 } 74 }
62 75
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
76 pub fn docs(&self) -> Option<&str> { 76 pub fn docs(&self) -> Option<&str> {
77 self.docs.as_deref() 77 self.docs.as_deref()
78 } 78 }
@@ -81,14 +81,6 @@ impl NavigationTarget {
81 self.description.as_deref() 81 self.description.as_deref()
82 } 82 }
83 83
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
92 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { 84 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
93 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); 85 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
94 if let Some(src) = module.declaration_source(db) { 86 if let Some(src) = module.declaration_source(db) {
diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs
index 1882789c4..99a7022a4 100644
--- a/crates/ra_ide/src/goto_implementation.rs
+++ b/crates/ra_ide/src/goto_implementation.rs
@@ -76,7 +76,7 @@ fn impls_for_trait(
76mod tests { 76mod tests {
77 use ra_db::FileRange; 77 use ra_db::FileRange;
78 78
79 use crate::mock_analysis::{analysis_and_position, MockAnalysis}; 79 use crate::mock_analysis::MockAnalysis;
80 80
81 fn check(ra_fixture: &str) { 81 fn check(ra_fixture: &str) {
82 let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); 82 let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 0940fcc28..25bcd80af 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -330,11 +330,12 @@ pub(crate) fn handle_workspace_symbol(
330 fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { 330 fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
331 let mut res = Vec::new(); 331 let mut res = Vec::new();
332 for nav in snap.analysis.symbol_search(query)? { 332 for nav in snap.analysis.symbol_search(query)? {
333 let container_name = nav.container_name().map(|v| v.to_string());
333 let info = SymbolInformation { 334 let info = SymbolInformation {
334 name: nav.name().to_string(), 335 name: nav.name().to_string(),
335 kind: to_proto::symbol_kind(nav.kind()), 336 kind: to_proto::symbol_kind(nav.kind()),
336 location: to_proto::location(snap, nav.file_range())?, 337 location: to_proto::location_from_nav(snap, nav)?,
337 container_name: nav.container_name().map(|v| v.to_string()), 338 container_name,
338 deprecated: None, 339 deprecated: None,
339 }; 340 };
340 res.push(info); 341 res.push(info);
@@ -1213,8 +1214,8 @@ fn show_impl_command_link(
1213 let position = to_proto::position(&line_index, position.offset); 1214 let position = to_proto::position(&line_index, position.offset);
1214 let locations: Vec<_> = nav_data 1215 let locations: Vec<_> = nav_data
1215 .info 1216 .info
1216 .iter() 1217 .into_iter()
1217 .filter_map(|it| to_proto::location(snap, it.file_range()).ok()) 1218 .filter_map(|nav| to_proto::location_from_nav(snap, nav).ok())
1218 .collect(); 1219 .collect();
1219 let title = implementation_title(locations.len()); 1220 let title = implementation_title(locations.len());
1220 let command = show_references_command(title, &uri, position, locations); 1221 let command = show_references_command(title, &uri, position, locations);
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index a03222ae9..a0a58f689 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -446,6 +446,18 @@ pub(crate) fn location(
446 Ok(loc) 446 Ok(loc)
447} 447}
448 448
449/// Perefer using `location_link`, if the client has the cap.
450pub(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
449pub(crate) fn location_link( 461pub(crate) fn location_link(
450 snap: &GlobalStateSnapshot, 462 snap: &GlobalStateSnapshot,
451 src: Option<FileRange>, 463 src: Option<FileRange>,