diff options
Diffstat (limited to 'crates/ide/src/display')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 43 | ||||
-rw-r--r-- | crates/ide/src/display/short_label.rs | 10 |
2 files changed, 17 insertions, 36 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 685052e7f..16fa828ad 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -7,6 +7,7 @@ use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, Mo | |||
7 | use ide_db::{ | 7 | use ide_db::{ |
8 | base_db::{FileId, FileRange, SourceDatabase}, | 8 | base_db::{FileId, FileRange, SourceDatabase}, |
9 | symbol_index::FileSymbolKind, | 9 | symbol_index::FileSymbolKind, |
10 | SymbolKind, | ||
10 | }; | 11 | }; |
11 | use ide_db::{defs::Definition, RootDatabase}; | 12 | use ide_db::{defs::Definition, RootDatabase}; |
12 | use syntax::{ | 13 | use syntax::{ |
@@ -18,30 +19,6 @@ use crate::FileSymbol; | |||
18 | 19 | ||
19 | use super::short_label::ShortLabel; | 20 | use super::short_label::ShortLabel; |
20 | 21 | ||
21 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
22 | pub enum SymbolKind { | ||
23 | Module, | ||
24 | Impl, | ||
25 | Field, | ||
26 | TypeParam, | ||
27 | ConstParam, | ||
28 | LifetimeParam, | ||
29 | ValueParam, | ||
30 | SelfParam, | ||
31 | Local, | ||
32 | Label, | ||
33 | Function, | ||
34 | Const, | ||
35 | Static, | ||
36 | Struct, | ||
37 | Enum, | ||
38 | Variant, | ||
39 | Union, | ||
40 | TypeAlias, | ||
41 | Trait, | ||
42 | Macro, | ||
43 | } | ||
44 | |||
45 | /// `NavigationTarget` represents and element in the editor's UI which you can | 22 | /// `NavigationTarget` represents and element in the editor's UI which you can |
46 | /// click on to navigate to a particular piece of code. | 23 | /// click on to navigate to a particular piece of code. |
47 | /// | 24 | /// |
@@ -153,8 +130,7 @@ impl NavigationTarget { | |||
153 | node: InFile<&dyn ast::NameOwner>, | 130 | node: InFile<&dyn ast::NameOwner>, |
154 | kind: SymbolKind, | 131 | kind: SymbolKind, |
155 | ) -> NavigationTarget { | 132 | ) -> NavigationTarget { |
156 | let name = | 133 | let name = node.value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into()); |
157 | node.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); | ||
158 | let focus_range = | 134 | let focus_range = |
159 | node.value.name().map(|it| node.with_value(it.syntax()).original_file_range(db).range); | 135 | node.value.name().map(|it| node.with_value(it.syntax()).original_file_range(db).range); |
160 | let frange = node.map(|it| it.syntax()).original_file_range(db); | 136 | let frange = node.map(|it| it.syntax()).original_file_range(db); |
@@ -295,6 +271,7 @@ impl ToNav for hir::Module { | |||
295 | ModuleSource::Module(node) => { | 271 | ModuleSource::Module(node) => { |
296 | (node.syntax(), node.name().map(|it| it.syntax().text_range())) | 272 | (node.syntax(), node.name().map(|it| it.syntax().text_range())) |
297 | } | 273 | } |
274 | ModuleSource::BlockExpr(node) => (node.syntax(), None), | ||
298 | }; | 275 | }; |
299 | let frange = src.with_value(syntax).original_file_range(db); | 276 | let frange = src.with_value(syntax).original_file_range(db); |
300 | NavigationTarget::from_syntax(frange.file_id, name, focus, frange.range, SymbolKind::Module) | 277 | NavigationTarget::from_syntax(frange.file_id, name, focus, frange.range, SymbolKind::Module) |
@@ -400,15 +377,13 @@ impl TryToNav for hir::GenericParam { | |||
400 | impl ToNav for hir::Local { | 377 | impl ToNav for hir::Local { |
401 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 378 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
402 | let src = self.source(db); | 379 | let src = self.source(db); |
403 | let (node, focus_range) = match &src.value { | 380 | let (node, name) = match &src.value { |
404 | Either::Left(bind_pat) => ( | 381 | Either::Left(bind_pat) => (bind_pat.syntax().clone(), bind_pat.name()), |
405 | bind_pat.syntax().clone(), | 382 | Either::Right(it) => (it.syntax().clone(), it.name()), |
406 | bind_pat | ||
407 | .name() | ||
408 | .map(|it| src.with_value(&it.syntax().clone()).original_file_range(db).range), | ||
409 | ), | ||
410 | Either::Right(it) => (it.syntax().clone(), it.self_token().map(|it| it.text_range())), | ||
411 | }; | 383 | }; |
384 | let focus_range = | ||
385 | name.map(|it| src.with_value(&it.syntax().clone()).original_file_range(db).range); | ||
386 | |||
412 | let full_range = src.with_value(&node).original_file_range(db); | 387 | let full_range = src.with_value(&node).original_file_range(db); |
413 | let name = match self.name(db) { | 388 | let name = match self.name(db) { |
414 | Some(it) => it.to_string().into(), | 389 | Some(it) => it.to_string().into(), |
diff --git a/crates/ide/src/display/short_label.rs b/crates/ide/src/display/short_label.rs index 990f740b8..7ac050473 100644 --- a/crates/ide/src/display/short_label.rs +++ b/crates/ide/src/display/short_label.rs | |||
@@ -53,6 +53,12 @@ impl ShortLabel for ast::SourceFile { | |||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | impl ShortLabel for ast::BlockExpr { | ||
57 | fn short_label(&self) -> Option<String> { | ||
58 | None | ||
59 | } | ||
60 | } | ||
61 | |||
56 | impl ShortLabel for ast::TypeAlias { | 62 | impl ShortLabel for ast::TypeAlias { |
57 | fn short_label(&self) -> Option<String> { | 63 | fn short_label(&self) -> Option<String> { |
58 | short_label_from_node(self, "type ") | 64 | short_label_from_node(self, "type ") |
@@ -90,7 +96,7 @@ impl ShortLabel for ast::Variant { | |||
90 | impl ShortLabel for ast::ConstParam { | 96 | impl ShortLabel for ast::ConstParam { |
91 | fn short_label(&self) -> Option<String> { | 97 | fn short_label(&self) -> Option<String> { |
92 | let mut buf = "const ".to_owned(); | 98 | let mut buf = "const ".to_owned(); |
93 | buf.push_str(self.name()?.text().as_str()); | 99 | buf.push_str(self.name()?.text()); |
94 | if let Some(type_ref) = self.ty() { | 100 | if let Some(type_ref) = self.ty() { |
95 | format_to!(buf, ": {}", type_ref.syntax()); | 101 | format_to!(buf, ": {}", type_ref.syntax()); |
96 | } | 102 | } |
@@ -117,6 +123,6 @@ where | |||
117 | { | 123 | { |
118 | let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default(); | 124 | let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default(); |
119 | buf.push_str(label); | 125 | buf.push_str(label); |
120 | buf.push_str(node.name()?.text().as_str()); | 126 | buf.push_str(node.name()?.text()); |
121 | Some(buf) | 127 | Some(buf) |
122 | } | 128 | } |