Skip to content

Commit 0e3581e

Browse files
committed
NavTarget doesn't assume that it points to a symbol
1 parent 53f81e4 commit 0e3581e

File tree

7 files changed

+196
-81
lines changed

7 files changed

+196
-81
lines changed

crates/ide/src/display/navigation_target.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub enum SymbolKind {
3535
TypeAlias,
3636
Trait,
3737
Macro,
38-
// Do we actually need this?
39-
DocTest,
4038
}
4139

4240
/// `NavigationTarget` represents and element in the editor's UI which you can
@@ -64,7 +62,7 @@ pub struct NavigationTarget {
6462
/// Clients should place the cursor on this range when navigating to this target.
6563
pub focus_range: Option<TextRange>,
6664
pub name: SmolStr,
67-
pub kind: SymbolKind,
65+
pub kind: Option<SymbolKind>,
6866
pub container_name: Option<SmolStr>,
6967
pub description: Option<String>,
7068
pub docs: Option<Documentation>,
@@ -110,8 +108,13 @@ impl NavigationTarget {
110108

111109
#[cfg(test)]
112110
pub(crate) fn debug_render(&self) -> String {
113-
let mut buf =
114-
format!("{} {:?} {:?} {:?}", self.name, self.kind, self.file_id, self.full_range);
111+
let mut buf = format!(
112+
"{} {:?} {:?} {:?}",
113+
self.name,
114+
self.kind.unwrap(),
115+
self.file_id,
116+
self.full_range
117+
);
115118
if let Some(focus_range) = self.focus_range {
116119
buf.push_str(&format!(" {:?}", focus_range))
117120
}
@@ -146,7 +149,7 @@ impl NavigationTarget {
146149
NavigationTarget {
147150
file_id,
148151
name,
149-
kind,
152+
kind: Some(kind),
150153
full_range,
151154
focus_range,
152155
container_name: None,
@@ -161,7 +164,7 @@ impl ToNav for FileSymbol {
161164
NavigationTarget {
162165
file_id: self.file_id,
163166
name: self.name.clone(),
164-
kind: match self.kind {
167+
kind: Some(match self.kind {
165168
FileSymbolKind::Function => SymbolKind::Function,
166169
FileSymbolKind::Struct => SymbolKind::Struct,
167170
FileSymbolKind::Enum => SymbolKind::Enum,
@@ -171,7 +174,7 @@ impl ToNav for FileSymbol {
171174
FileSymbolKind::Const => SymbolKind::Const,
172175
FileSymbolKind::Static => SymbolKind::Static,
173176
FileSymbolKind::Macro => SymbolKind::Macro,
174-
},
177+
}),
175178
full_range: self.range,
176179
focus_range: self.name_range,
177180
container_name: self.container_name.clone(),
@@ -386,7 +389,7 @@ impl ToNav for hir::Local {
386389
NavigationTarget {
387390
file_id: full_range.file_id,
388391
name,
389-
kind: SymbolKind::Local,
392+
kind: Some(SymbolKind::Local),
390393
full_range: full_range.range,
391394
focus_range: None,
392395
container_name: None,
@@ -410,7 +413,7 @@ impl ToNav for hir::TypeParam {
410413
NavigationTarget {
411414
file_id: src.file_id.original_file(db),
412415
name: self.name(db).to_string().into(),
413-
kind: SymbolKind::TypeParam,
416+
kind: Some(SymbolKind::TypeParam),
414417
full_range,
415418
focus_range,
416419
container_name: None,
@@ -427,7 +430,7 @@ impl ToNav for hir::LifetimeParam {
427430
NavigationTarget {
428431
file_id: src.file_id.original_file(db),
429432
name: self.name(db).to_string().into(),
430-
kind: SymbolKind::LifetimeParam,
433+
kind: Some(SymbolKind::LifetimeParam),
431434
full_range,
432435
focus_range: Some(full_range),
433436
container_name: None,
@@ -488,7 +491,9 @@ fn foo() { enum FooInner { } }
488491
5..13,
489492
),
490493
name: "FooInner",
491-
kind: Enum,
494+
kind: Some(
495+
Enum,
496+
),
492497
container_name: None,
493498
description: Some(
494499
"enum FooInner",
@@ -504,7 +509,9 @@ fn foo() { enum FooInner { } }
504509
34..42,
505510
),
506511
name: "FooInner",
507-
kind: Enum,
512+
kind: Some(
513+
Enum,
514+
),
508515
container_name: Some(
509516
"foo",
510517
),

crates/ide/src/goto_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn self_to_nav_target(self_param: ast::SelfParam, file_id: FileId) -> Option<Nav
8686
full_range: self_param.syntax().text_range(),
8787
focus_range: Some(self_token.text_range()),
8888
name: self_token.text().clone(),
89-
kind: SymbolKind::SelfParam,
89+
kind: Some(SymbolKind::SelfParam),
9090
container_name: None,
9191
description: None,
9292
docs: None,

0 commit comments

Comments
 (0)