diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 9b92959556..cbdd4ecc2a 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -1,5 +1,7 @@ //! FIXME: write short doc here +use std::fmt; + use either::Either; use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; use ide_db::{ @@ -42,7 +44,7 @@ pub enum SymbolKind { /// /// 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. @@ -68,6 +70,24 @@ pub struct NavigationTarget { pub docs: Option, } +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; } @@ -487,38 +507,21 @@ fn foo() { enum FooInner { } } 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", }, ] "#]] diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 413b1526ac..b06fa5f155 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -2187,16 +2187,9 @@ fn foo_<|>test() {} 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( @@ -2232,16 +2225,9 @@ mod tests<|> { 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", @@ -2273,18 +2259,10 @@ fn main() { let s<|>t = S{ f1:0 }; } 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", }, }, ], @@ -2314,18 +2292,10 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } 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 { @@ -2335,18 +2305,10 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } 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", }, }, ], @@ -2376,18 +2338,10 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } 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 { @@ -2397,18 +2351,10 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } 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", }, }, ], @@ -2441,18 +2387,10 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 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 { @@ -2462,18 +2400,10 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 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 { @@ -2483,18 +2413,10 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 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", }, }, ], @@ -2524,18 +2446,10 @@ fn main() { let s<|>t = 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", }, }, ], @@ -2566,18 +2480,10 @@ fn main() { let s<|>t = 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 { @@ -2587,18 +2493,10 @@ fn main() { let s<|>t = foo(); } 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", }, }, ], @@ -2629,18 +2527,10 @@ fn main() { let s<|>t = 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 { @@ -2650,18 +2540,10 @@ fn main() { let s<|>t = foo(); } 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", }, }, ], @@ -2695,18 +2577,10 @@ fn main() { let s<|>t = 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 { @@ -2716,18 +2590,10 @@ fn main() { let s<|>t = foo(); } 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 { @@ -2737,18 +2603,10 @@ fn main() { let s<|>t = foo(); } 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 { @@ -2758,18 +2616,10 @@ fn main() { let s<|>t = foo(); } 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", }, }, ], @@ -2797,18 +2647,10 @@ fn foo(ar<|>g: &impl 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", }, }, ], @@ -2839,18 +2681,10 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 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 { @@ -2860,18 +2694,10 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 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 { @@ -2881,18 +2707,10 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 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", }, }, ], @@ -2928,18 +2746,10 @@ mod future { 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 { @@ -2949,18 +2759,10 @@ mod future { 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", }, }, ], @@ -2989,18 +2791,10 @@ fn foo(ar<|>g: &impl 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 { @@ -3010,18 +2804,10 @@ fn foo(ar<|>g: &impl Foo) {} 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", }, }, ], @@ -3055,18 +2841,10 @@ fn main() { let s<|>t = foo(); } 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 { @@ -3076,18 +2854,10 @@ fn main() { let s<|>t = 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", }, }, ], @@ -3115,18 +2885,10 @@ fn foo(ar<|>g: &dyn 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", }, }, ], @@ -3155,18 +2917,10 @@ fn foo(ar<|>g: &dyn 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 { @@ -3176,18 +2930,10 @@ fn foo(ar<|>g: &dyn Foo) {} 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", }, }, ], @@ -3219,18 +2965,10 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 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 { @@ -3240,18 +2978,10 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 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 { @@ -3261,18 +2991,10 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 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 { @@ -3282,18 +3004,10 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 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", }, }, ], @@ -3332,18 +3046,10 @@ fn main() { let s<|>t = test().get(); } 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", }, }, ], diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 99f11c295c..ff386be804 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -352,16 +352,9 @@ fn bench() {} 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, @@ -372,16 +365,9 @@ fn bench() {} 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( @@ -399,16 +385,9 @@ fn bench() {} 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( @@ -426,16 +405,9 @@ fn bench() {} 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( @@ -525,16 +497,9 @@ struct StructWithRunnable(String); 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, @@ -545,12 +510,7 @@ struct StructWithRunnable(String); 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( @@ -565,12 +525,7 @@ struct StructWithRunnable(String); 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( @@ -585,12 +540,7 @@ struct StructWithRunnable(String); 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( @@ -605,12 +555,7 @@ struct StructWithRunnable(String); 0, ), full_range: 756..821, - focus_range: None, name: "StructWithRunnable", - kind: None, - container_name: None, - description: None, - docs: None, }, kind: DocTest { test_id: Path( @@ -649,16 +594,9 @@ impl Data { 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, @@ -669,12 +607,7 @@ impl Data { 0, ), full_range: 44..98, - focus_range: None, name: "foo", - kind: None, - container_name: None, - description: None, - docs: None, }, kind: DocTest { test_id: Path( @@ -708,16 +641,9 @@ mod test_mod { 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", @@ -730,16 +656,9 @@ mod 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( @@ -792,16 +711,9 @@ mod root_tests { 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", @@ -814,16 +726,9 @@ mod root_tests { 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", @@ -836,16 +741,9 @@ mod root_tests { 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( @@ -863,16 +761,9 @@ mod root_tests { 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( @@ -890,16 +781,9 @@ mod root_tests { 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", @@ -912,16 +796,9 @@ mod root_tests { 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( @@ -957,16 +834,9 @@ fn test_foo1() {} 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( @@ -1009,16 +879,9 @@ fn test_foo1() {} 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(