diff options
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r-- | crates/ide/src/hover.rs | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 6022bd275..d47a4cb0f 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -98,7 +98,6 @@ pub(crate) fn hover( | |||
98 | ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)), | 98 | ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)), |
99 | ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime) | 99 | ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime) |
100 | .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)), | 100 | .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)), |
101 | ast::SelfParam(self_param) => NameClass::classify_self_param(&sema, &self_param).and_then(|d| d.defined(sema.db)), | ||
102 | _ => None, | 101 | _ => None, |
103 | } | 102 | } |
104 | }; | 103 | }; |
@@ -183,12 +182,7 @@ fn runnable_action( | |||
183 | ) -> Option<HoverAction> { | 182 | ) -> Option<HoverAction> { |
184 | match def { | 183 | match def { |
185 | Definition::ModuleDef(it) => match it { | 184 | Definition::ModuleDef(it) => match it { |
186 | ModuleDef::Module(it) => match it.definition_source(sema.db).value { | 185 | ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)), |
187 | ModuleSource::Module(it) => { | ||
188 | runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)) | ||
189 | } | ||
190 | _ => None, | ||
191 | }, | ||
192 | ModuleDef::Function(func) => { | 186 | ModuleDef::Function(func) => { |
193 | let src = func.source(sema.db)?; | 187 | let src = func.source(sema.db)?; |
194 | if src.file_id != file_id.into() { | 188 | if src.file_id != file_id.into() { |
@@ -327,6 +321,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> { | |||
327 | match it.definition_source(db).value { | 321 | match it.definition_source(db).value { |
328 | ModuleSource::Module(it) => it.short_label(), | 322 | ModuleSource::Module(it) => it.short_label(), |
329 | ModuleSource::SourceFile(it) => it.short_label(), | 323 | ModuleSource::SourceFile(it) => it.short_label(), |
324 | ModuleSource::BlockExpr(it) => it.short_label(), | ||
330 | }, | 325 | }, |
331 | mod_path, | 326 | mod_path, |
332 | ), | 327 | ), |
@@ -1831,6 +1826,35 @@ pub struct B$0ar | |||
1831 | "#]], | 1826 | "#]], |
1832 | ); | 1827 | ); |
1833 | } | 1828 | } |
1829 | #[test] | ||
1830 | fn test_hover_intra_link_reference_to_trait_method() { | ||
1831 | check( | ||
1832 | r#" | ||
1833 | pub trait Foo { | ||
1834 | fn buzz() -> usize; | ||
1835 | } | ||
1836 | /// [Foo][buzz] | ||
1837 | /// | ||
1838 | /// [buzz]: Foo::buzz | ||
1839 | pub struct B$0ar | ||
1840 | "#, | ||
1841 | expect![[r#" | ||
1842 | *Bar* | ||
1843 | |||
1844 | ```rust | ||
1845 | test | ||
1846 | ``` | ||
1847 | |||
1848 | ```rust | ||
1849 | pub struct Bar | ||
1850 | ``` | ||
1851 | |||
1852 | --- | ||
1853 | |||
1854 | [Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz) | ||
1855 | "#]], | ||
1856 | ); | ||
1857 | } | ||
1834 | 1858 | ||
1835 | #[test] | 1859 | #[test] |
1836 | fn test_hover_external_url() { | 1860 | fn test_hover_external_url() { |
@@ -3223,7 +3247,7 @@ impl Foo { | |||
3223 | } | 3247 | } |
3224 | "#, | 3248 | "#, |
3225 | expect![[r#" | 3249 | expect![[r#" |
3226 | *&self* | 3250 | *self* |
3227 | 3251 | ||
3228 | ```rust | 3252 | ```rust |
3229 | &Foo | 3253 | &Foo |
@@ -3243,7 +3267,7 @@ impl Foo { | |||
3243 | } | 3267 | } |
3244 | "#, | 3268 | "#, |
3245 | expect![[r#" | 3269 | expect![[r#" |
3246 | *self: Arc<Foo>* | 3270 | *self* |
3247 | 3271 | ||
3248 | ```rust | 3272 | ```rust |
3249 | Arc<Foo> | 3273 | Arc<Foo> |