diff options
author | Aleksey Kladov <[email protected]> | 2020-12-18 18:10:13 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-12-18 18:15:48 +0000 |
commit | 0e3581e8232461baa50191a2c7474a117b649b1b (patch) | |
tree | 4e78794bf926ef2a0878abd6058f2958713725b4 /crates/ide/src/display | |
parent | 53f81e4e8c8307069d89cee58cb12142350b09c2 (diff) |
NavTarget doesn't assume that it points to a symbol
Diffstat (limited to 'crates/ide/src/display')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index ac6346b2b..9b9295955 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -35,8 +35,6 @@ pub enum SymbolKind { | |||
35 | TypeAlias, | 35 | TypeAlias, |
36 | Trait, | 36 | Trait, |
37 | Macro, | 37 | Macro, |
38 | // Do we actually need this? | ||
39 | DocTest, | ||
40 | } | 38 | } |
41 | 39 | ||
42 | /// `NavigationTarget` represents and element in the editor's UI which you can | 40 | /// `NavigationTarget` represents and element in the editor's UI which you can |
@@ -64,7 +62,7 @@ pub struct NavigationTarget { | |||
64 | /// Clients should place the cursor on this range when navigating to this target. | 62 | /// Clients should place the cursor on this range when navigating to this target. |
65 | pub focus_range: Option<TextRange>, | 63 | pub focus_range: Option<TextRange>, |
66 | pub name: SmolStr, | 64 | pub name: SmolStr, |
67 | pub kind: SymbolKind, | 65 | pub kind: Option<SymbolKind>, |
68 | pub container_name: Option<SmolStr>, | 66 | pub container_name: Option<SmolStr>, |
69 | pub description: Option<String>, | 67 | pub description: Option<String>, |
70 | pub docs: Option<Documentation>, | 68 | pub docs: Option<Documentation>, |
@@ -110,8 +108,13 @@ impl NavigationTarget { | |||
110 | 108 | ||
111 | #[cfg(test)] | 109 | #[cfg(test)] |
112 | pub(crate) fn debug_render(&self) -> String { | 110 | pub(crate) fn debug_render(&self) -> String { |
113 | let mut buf = | 111 | let mut buf = format!( |
114 | format!("{} {:?} {:?} {:?}", self.name, self.kind, self.file_id, self.full_range); | 112 | "{} {:?} {:?} {:?}", |
113 | self.name, | ||
114 | self.kind.unwrap(), | ||
115 | self.file_id, | ||
116 | self.full_range | ||
117 | ); | ||
115 | if let Some(focus_range) = self.focus_range { | 118 | if let Some(focus_range) = self.focus_range { |
116 | buf.push_str(&format!(" {:?}", focus_range)) | 119 | buf.push_str(&format!(" {:?}", focus_range)) |
117 | } | 120 | } |
@@ -146,7 +149,7 @@ impl NavigationTarget { | |||
146 | NavigationTarget { | 149 | NavigationTarget { |
147 | file_id, | 150 | file_id, |
148 | name, | 151 | name, |
149 | kind, | 152 | kind: Some(kind), |
150 | full_range, | 153 | full_range, |
151 | focus_range, | 154 | focus_range, |
152 | container_name: None, | 155 | container_name: None, |
@@ -161,7 +164,7 @@ impl ToNav for FileSymbol { | |||
161 | NavigationTarget { | 164 | NavigationTarget { |
162 | file_id: self.file_id, | 165 | file_id: self.file_id, |
163 | name: self.name.clone(), | 166 | name: self.name.clone(), |
164 | kind: match self.kind { | 167 | kind: Some(match self.kind { |
165 | FileSymbolKind::Function => SymbolKind::Function, | 168 | FileSymbolKind::Function => SymbolKind::Function, |
166 | FileSymbolKind::Struct => SymbolKind::Struct, | 169 | FileSymbolKind::Struct => SymbolKind::Struct, |
167 | FileSymbolKind::Enum => SymbolKind::Enum, | 170 | FileSymbolKind::Enum => SymbolKind::Enum, |
@@ -171,7 +174,7 @@ impl ToNav for FileSymbol { | |||
171 | FileSymbolKind::Const => SymbolKind::Const, | 174 | FileSymbolKind::Const => SymbolKind::Const, |
172 | FileSymbolKind::Static => SymbolKind::Static, | 175 | FileSymbolKind::Static => SymbolKind::Static, |
173 | FileSymbolKind::Macro => SymbolKind::Macro, | 176 | FileSymbolKind::Macro => SymbolKind::Macro, |
174 | }, | 177 | }), |
175 | full_range: self.range, | 178 | full_range: self.range, |
176 | focus_range: self.name_range, | 179 | focus_range: self.name_range, |
177 | container_name: self.container_name.clone(), | 180 | container_name: self.container_name.clone(), |
@@ -386,7 +389,7 @@ impl ToNav for hir::Local { | |||
386 | NavigationTarget { | 389 | NavigationTarget { |
387 | file_id: full_range.file_id, | 390 | file_id: full_range.file_id, |
388 | name, | 391 | name, |
389 | kind: SymbolKind::Local, | 392 | kind: Some(SymbolKind::Local), |
390 | full_range: full_range.range, | 393 | full_range: full_range.range, |
391 | focus_range: None, | 394 | focus_range: None, |
392 | container_name: None, | 395 | container_name: None, |
@@ -410,7 +413,7 @@ impl ToNav for hir::TypeParam { | |||
410 | NavigationTarget { | 413 | NavigationTarget { |
411 | file_id: src.file_id.original_file(db), | 414 | file_id: src.file_id.original_file(db), |
412 | name: self.name(db).to_string().into(), | 415 | name: self.name(db).to_string().into(), |
413 | kind: SymbolKind::TypeParam, | 416 | kind: Some(SymbolKind::TypeParam), |
414 | full_range, | 417 | full_range, |
415 | focus_range, | 418 | focus_range, |
416 | container_name: None, | 419 | container_name: None, |
@@ -427,7 +430,7 @@ impl ToNav for hir::LifetimeParam { | |||
427 | NavigationTarget { | 430 | NavigationTarget { |
428 | file_id: src.file_id.original_file(db), | 431 | file_id: src.file_id.original_file(db), |
429 | name: self.name(db).to_string().into(), | 432 | name: self.name(db).to_string().into(), |
430 | kind: SymbolKind::LifetimeParam, | 433 | kind: Some(SymbolKind::LifetimeParam), |
431 | full_range, | 434 | full_range, |
432 | focus_range: Some(full_range), | 435 | focus_range: Some(full_range), |
433 | container_name: None, | 436 | container_name: None, |
@@ -488,7 +491,9 @@ fn foo() { enum FooInner { } } | |||
488 | 5..13, | 491 | 5..13, |
489 | ), | 492 | ), |
490 | name: "FooInner", | 493 | name: "FooInner", |
491 | kind: Enum, | 494 | kind: Some( |
495 | Enum, | ||
496 | ), | ||
492 | container_name: None, | 497 | container_name: None, |
493 | description: Some( | 498 | description: Some( |
494 | "enum FooInner", | 499 | "enum FooInner", |
@@ -504,7 +509,9 @@ fn foo() { enum FooInner { } } | |||
504 | 34..42, | 509 | 34..42, |
505 | ), | 510 | ), |
506 | name: "FooInner", | 511 | name: "FooInner", |
507 | kind: Enum, | 512 | kind: Some( |
513 | Enum, | ||
514 | ), | ||
508 | container_name: Some( | 515 | container_name: Some( |
509 | "foo", | 516 | "foo", |
510 | ), | 517 | ), |