aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/display
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/display')
-rw-r--r--crates/ide/src/display/navigation_target.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 9b9295955..cbdd4ecc2 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -1,5 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::fmt;
4
3use either::Either; 5use either::Either;
4use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; 6use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
5use ide_db::{ 7use ide_db::{
@@ -42,7 +44,7 @@ pub enum SymbolKind {
42/// 44///
43/// Typically, a `NavigationTarget` corresponds to some element in the source 45/// Typically, a `NavigationTarget` corresponds to some element in the source
44/// code, like a function or a struct, but this is not strictly required. 46/// code, like a function or a struct, but this is not strictly required.
45#[derive(Debug, Clone, PartialEq, Eq, Hash)] 47#[derive(Clone, PartialEq, Eq, Hash)]
46pub struct NavigationTarget { 48pub struct NavigationTarget {
47 pub file_id: FileId, 49 pub file_id: FileId,
48 /// Range which encompasses the whole element. 50 /// Range which encompasses the whole element.
@@ -68,6 +70,24 @@ pub struct NavigationTarget {
68 pub docs: Option<Documentation>, 70 pub docs: Option<Documentation>,
69} 71}
70 72
73impl fmt::Debug for NavigationTarget {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 let mut f = f.debug_struct("NavigationTarget");
76 macro_rules! opt {
77 ($($name:ident)*) => {$(
78 if let Some(it) = &self.$name {
79 f.field(stringify!($name), it);
80 }
81 )*}
82 }
83 f.field("file_id", &self.file_id).field("full_range", &self.full_range);
84 opt!(focus_range);
85 f.field("name", &self.name);
86 opt!(kind container_name description docs);
87 f.finish()
88 }
89}
90
71pub(crate) trait ToNav { 91pub(crate) trait ToNav {
72 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget; 92 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget;
73} 93}
@@ -487,38 +507,21 @@ fn foo() { enum FooInner { } }
487 0, 507 0,
488 ), 508 ),
489 full_range: 0..17, 509 full_range: 0..17,
490 focus_range: Some( 510 focus_range: 5..13,
491 5..13,
492 ),
493 name: "FooInner", 511 name: "FooInner",
494 kind: Some( 512 kind: Enum,
495 Enum, 513 description: "enum FooInner",
496 ),
497 container_name: None,
498 description: Some(
499 "enum FooInner",
500 ),
501 docs: None,
502 }, 514 },
503 NavigationTarget { 515 NavigationTarget {
504 file_id: FileId( 516 file_id: FileId(
505 0, 517 0,
506 ), 518 ),
507 full_range: 29..46, 519 full_range: 29..46,
508 focus_range: Some( 520 focus_range: 34..42,
509 34..42,
510 ),
511 name: "FooInner", 521 name: "FooInner",
512 kind: Some( 522 kind: Enum,
513 Enum, 523 container_name: "foo",
514 ), 524 description: "enum FooInner",
515 container_name: Some(
516 "foo",
517 ),
518 description: Some(
519 "enum FooInner",
520 ),
521 docs: None,
522 }, 525 },
523 ] 526 ]
524 "#]] 527 "#]]