//! FIXME: write short doc here
+use std::fmt;
+
use either::Either;
use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
use ide_db::{
///
/// Typically, a `NavigationTarget` corresponds to some element in the source
/// code, like a function or a struct, but this is not strictly required.
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+#[derive(Clone, PartialEq, Eq, Hash)]
pub struct NavigationTarget {
pub file_id: FileId,
/// Range which encompasses the whole element.
pub docs: Option<Documentation>,
}
+impl fmt::Debug for NavigationTarget {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut f = f.debug_struct("NavigationTarget");
+ macro_rules! opt {
+ ($($name:ident)*) => {$(
+ if let Some(it) = &self.$name {
+ f.field(stringify!($name), it);
+ }
+ )*}
+ }
+ f.field("file_id", &self.file_id).field("full_range", &self.full_range);
+ opt!(focus_range);
+ f.field("name", &self.name);
+ opt!(kind container_name description docs);
+ f.finish()
+ }
+}
+
pub(crate) trait ToNav {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget;
}
0,
),
full_range: 0..17,
- focus_range: Some(
- 5..13,
- ),
+ focus_range: 5..13,
name: "FooInner",
- kind: Some(
- Enum,
- ),
- container_name: None,
- description: Some(
- "enum FooInner",
- ),
- docs: None,
+ kind: Enum,
+ description: "enum FooInner",
},
NavigationTarget {
file_id: FileId(
0,
),
full_range: 29..46,
- focus_range: Some(
- 34..42,
- ),
+ focus_range: 34..42,
name: "FooInner",
- kind: Some(
- Enum,
- ),
- container_name: Some(
- "foo",
- ),
- description: Some(
- "enum FooInner",
- ),
- docs: None,
+ kind: Enum,
+ container_name: "foo",
+ description: "enum FooInner",
},
]
"#]]
0,
),
full_range: 0..24,
- focus_range: Some(
- 11..19,
- ),
+ focus_range: 11..19,
name: "foo_test",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 0..46,
- focus_range: Some(
- 4..9,
- ),
+ focus_range: 4..9,
name: "tests",
- kind: Some(
- Module,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Module,
},
kind: TestMod {
path: "tests",
0,
),
full_range: 0..19,
- focus_range: Some(
- 7..8,
- ),
+ focus_range: 7..8,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 17..37,
- focus_range: Some(
- 24..25,
- ),
+ focus_range: 24..25,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
HoverGotoTypeData {
0,
),
full_range: 0..16,
- focus_range: Some(
- 7..10,
- ),
+ focus_range: 7..10,
name: "Arg",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct Arg",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct Arg",
},
},
],
0,
),
full_range: 17..37,
- focus_range: Some(
- 24..25,
- ),
+ focus_range: 24..25,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
HoverGotoTypeData {
0,
),
full_range: 0..16,
- focus_range: Some(
- 7..10,
- ),
+ focus_range: 7..10,
name: "Arg",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct Arg",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct Arg",
},
},
],
0,
),
full_range: 0..14,
- focus_range: Some(
- 7..8,
- ),
+ focus_range: 7..8,
name: "A",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct A",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct A",
},
},
HoverGotoTypeData {
0,
),
full_range: 15..29,
- focus_range: Some(
- 22..23,
- ),
+ focus_range: 22..23,
name: "B",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct B",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct B",
},
},
HoverGotoTypeData {
0,
),
full_range: 42..60,
- focus_range: Some(
- 53..54,
- ),
+ focus_range: 53..54,
name: "C",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "pub struct C",
- ),
- docs: None,
+ kind: Struct,
+ description: "pub struct C",
},
},
],
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
],
0,
),
full_range: 0..15,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 16..25,
- focus_range: Some(
- 23..24,
- ),
+ focus_range: 23..24,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 13..25,
- focus_range: Some(
- 19..22,
- ),
+ focus_range: 19..22,
name: "Bar",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Bar",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Bar",
},
},
],
0,
),
full_range: 0..15,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 16..31,
- focus_range: Some(
- 22..25,
- ),
+ focus_range: 22..25,
name: "Bar",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Bar",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Bar",
},
},
HoverGotoTypeData {
0,
),
full_range: 32..44,
- focus_range: Some(
- 39..41,
- ),
+ focus_range: 39..41,
name: "S1",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S1",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S1",
},
},
HoverGotoTypeData {
0,
),
full_range: 45..57,
- focus_range: Some(
- 52..54,
- ),
+ focus_range: 52..54,
name: "S2",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S2",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S2",
},
},
],
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
],
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 13..28,
- focus_range: Some(
- 19..22,
- ),
+ focus_range: 19..22,
name: "Bar",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Bar",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Bar",
},
},
HoverGotoTypeData {
0,
),
full_range: 29..39,
- focus_range: Some(
- 36..37,
- ),
+ focus_range: 36..37,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 101..163,
- focus_range: Some(
- 140..146,
- ),
+ focus_range: 140..146,
name: "Future",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "pub trait Future",
- ),
- docs: None,
+ kind: Trait,
+ description: "pub trait Future",
},
},
HoverGotoTypeData {
0,
),
full_range: 0..9,
- focus_range: Some(
- 7..8,
- ),
+ focus_range: 7..8,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 0..15,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 16..27,
- focus_range: Some(
- 23..24,
- ),
+ focus_range: 23..24,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 42..55,
- focus_range: Some(
- 49..50,
- ),
+ focus_range: 49..50,
name: "B",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct B",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct B",
},
},
HoverGotoTypeData {
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
],
0,
),
full_range: 0..12,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
],
0,
),
full_range: 0..15,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
HoverGotoTypeData {
0,
),
full_range: 16..27,
- focus_range: Some(
- 23..24,
- ),
+ focus_range: 23..24,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 0..21,
- focus_range: Some(
- 6..15,
- ),
+ focus_range: 6..15,
name: "ImplTrait",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait ImplTrait",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait ImplTrait",
},
},
HoverGotoTypeData {
0,
),
full_range: 43..57,
- focus_range: Some(
- 50..51,
- ),
+ focus_range: 50..51,
name: "B",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct B",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct B",
},
},
HoverGotoTypeData {
0,
),
full_range: 22..42,
- focus_range: Some(
- 28..36,
- ),
+ focus_range: 28..36,
name: "DynTrait",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait DynTrait",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait DynTrait",
},
},
HoverGotoTypeData {
0,
),
full_range: 58..69,
- focus_range: Some(
- 65..66,
- ),
+ focus_range: 65..66,
name: "S",
- kind: Some(
- Struct,
- ),
- container_name: None,
- description: Some(
- "struct S",
- ),
- docs: None,
+ kind: Struct,
+ description: "struct S",
},
},
],
0,
),
full_range: 0..62,
- focus_range: Some(
- 6..9,
- ),
+ focus_range: 6..9,
name: "Foo",
- kind: Some(
- Trait,
- ),
- container_name: None,
- description: Some(
- "trait Foo",
- ),
- docs: None,
+ kind: Trait,
+ description: "trait Foo",
},
},
],
0,
),
full_range: 1..13,
- focus_range: Some(
- 4..8,
- ),
+ focus_range: 4..8,
name: "main",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Bin,
cfg: None,
0,
),
full_range: 15..39,
- focus_range: Some(
- 26..34,
- ),
+ focus_range: 26..34,
name: "test_foo",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 41..75,
- focus_range: Some(
- 62..70,
- ),
+ focus_range: 62..70,
name: "test_foo",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 77..99,
- focus_range: Some(
- 89..94,
- ),
+ focus_range: 89..94,
name: "bench",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Bench {
test_id: Path(
0,
),
full_range: 1..13,
- focus_range: Some(
- 4..8,
- ),
+ focus_range: 4..8,
name: "main",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Bin,
cfg: None,
0,
),
full_range: 15..74,
- focus_range: None,
name: "should_have_runnable",
- kind: None,
- container_name: None,
- description: None,
- docs: None,
},
kind: DocTest {
test_id: Path(
0,
),
full_range: 76..148,
- focus_range: None,
name: "should_have_runnable_1",
- kind: None,
- container_name: None,
- description: None,
- docs: None,
},
kind: DocTest {
test_id: Path(
0,
),
full_range: 150..254,
- focus_range: None,
name: "should_have_runnable_2",
- kind: None,
- container_name: None,
- description: None,
- docs: None,
},
kind: DocTest {
test_id: Path(
0,
),
full_range: 756..821,
- focus_range: None,
name: "StructWithRunnable",
- kind: None,
- container_name: None,
- description: None,
- docs: None,
},
kind: DocTest {
test_id: Path(
0,
),
full_range: 1..13,
- focus_range: Some(
- 4..8,
- ),
+ focus_range: 4..8,
name: "main",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Bin,
cfg: None,
0,
),
full_range: 44..98,
- focus_range: None,
name: "foo",
- kind: None,
- container_name: None,
- description: None,
- docs: None,
},
kind: DocTest {
test_id: Path(
0,
),
full_range: 1..51,
- focus_range: Some(
- 5..13,
- ),
+ focus_range: 5..13,
name: "test_mod",
- kind: Some(
- Module,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Module,
},
kind: TestMod {
path: "test_mod",
0,
),
full_range: 20..49,
- focus_range: Some(
- 35..44,
- ),
+ focus_range: 35..44,
name: "test_foo1",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 22..323,
- focus_range: Some(
- 26..40,
- ),
+ focus_range: 26..40,
name: "nested_tests_0",
- kind: Some(
- Module,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Module,
},
kind: TestMod {
path: "root_tests::nested_tests_0",
0,
),
full_range: 51..192,
- focus_range: Some(
- 55..69,
- ),
+ focus_range: 55..69,
name: "nested_tests_1",
- kind: Some(
- Module,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Module,
},
kind: TestMod {
path: "root_tests::nested_tests_0::nested_tests_1",
0,
),
full_range: 84..126,
- focus_range: Some(
- 107..121,
- ),
+ focus_range: 107..121,
name: "nested_test_11",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 140..182,
- focus_range: Some(
- 163..177,
- ),
+ focus_range: 163..177,
name: "nested_test_12",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 202..286,
- focus_range: Some(
- 206..220,
- ),
+ focus_range: 206..220,
name: "nested_tests_2",
- kind: Some(
- Module,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Module,
},
kind: TestMod {
path: "root_tests::nested_tests_0::nested_tests_2",
0,
),
full_range: 235..276,
- focus_range: Some(
- 258..271,
- ),
+ focus_range: 258..271,
name: "nested_test_2",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 1..50,
- focus_range: Some(
- 36..45,
- ),
+ focus_range: 36..45,
name: "test_foo1",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(
0,
),
full_range: 1..72,
- focus_range: Some(
- 58..67,
- ),
+ focus_range: 58..67,
name: "test_foo1",
- kind: Some(
- Function,
- ),
- container_name: None,
- description: None,
- docs: None,
+ kind: Function,
},
kind: Test {
test_id: Path(