aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/hover.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r--crates/ide/src/hover.rs47
1 files changed, 22 insertions, 25 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 8cb4a51d8..317b6f011 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -1,6 +1,6 @@
1use hir::{ 1use hir::{
2 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module, 2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 ModuleDef, ModuleSource, Semantics, 3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
4}; 4};
5use ide_db::base_db::SourceDatabase; 5use ide_db::base_db::SourceDatabase;
6use ide_db::{ 6use ide_db::{
@@ -17,7 +17,7 @@ use crate::{
17 doc_links::{remove_links, rewrite_links}, 17 doc_links::{remove_links, rewrite_links},
18 markdown_remove::remove_markdown, 18 markdown_remove::remove_markdown,
19 markup::Markup, 19 markup::Markup,
20 runnables::{runnable, runnable_fn}, 20 runnables::{runnable_fn, runnable_mod},
21 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, 21 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
22}; 22};
23 23
@@ -175,12 +175,7 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
175 Definition::SelfType(it) => it.target_ty(db).as_adt(), 175 Definition::SelfType(it) => it.target_ty(db).as_adt(),
176 _ => None, 176 _ => None,
177 }?; 177 }?;
178 match adt { 178 adt.try_to_nav(db).map(to_action)
179 Adt::Struct(it) => it.try_to_nav(db),
180 Adt::Union(it) => it.try_to_nav(db),
181 Adt::Enum(it) => it.try_to_nav(db),
182 }
183 .map(to_action)
184} 179}
185 180
186fn runnable_action( 181fn runnable_action(
@@ -192,7 +187,7 @@ fn runnable_action(
192 Definition::ModuleDef(it) => match it { 187 Definition::ModuleDef(it) => match it {
193 ModuleDef::Module(it) => match it.definition_source(sema.db).value { 188 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
194 ModuleSource::Module(it) => { 189 ModuleSource::Module(it) => {
195 runnable(&sema, it.syntax().clone()).map(|it| HoverAction::Runnable(it)) 190 runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it))
196 } 191 }
197 _ => None, 192 _ => None,
198 }, 193 },
@@ -220,12 +215,12 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
220 } 215 }
221 }; 216 };
222 217
223 if let Definition::TypeParam(it) = def { 218 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
224 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into())); 219 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
225 } else { 220 } else {
226 let ty = match def { 221 let ty = match def {
227 Definition::Local(it) => it.ty(db), 222 Definition::Local(it) => it.ty(db),
228 Definition::ConstParam(it) => it.ty(db), 223 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
229 _ => return None, 224 _ => return None,
230 }; 225 };
231 226
@@ -357,9 +352,11 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
357 }) 352 })
358 } 353 }
359 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), 354 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
360 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), 355 Definition::GenericParam(it) => match it {
361 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), 356 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
362 Definition::ConstParam(it) => from_def_source(db, it, None), 357 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
358 GenericParam::ConstParam(it) => from_def_source(db, it, None),
359 },
363 }; 360 };
364 361
365 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> 362 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
@@ -1951,16 +1948,16 @@ struct S {
1951/// Test cases: 1948/// Test cases:
1952/// case 1. bare URL: https://www.example.com/ 1949/// case 1. bare URL: https://www.example.com/
1953/// case 2. inline URL with title: [example](https://www.example.com/) 1950/// case 2. inline URL with title: [example](https://www.example.com/)
1954/// case 3. code refrence: [`Result`] 1951/// case 3. code reference: [`Result`]
1955/// case 4. code refrence but miss footnote: [`String`] 1952/// case 4. code reference but miss footnote: [`String`]
1956/// case 5. autolink: <http://www.example.com/> 1953/// case 5. autolink: <http://www.example.com/>
1957/// case 6. email address: <[email protected]> 1954/// case 6. email address: <[email protected]>
1958/// case 7. refrence: [example][example] 1955/// case 7. reference: [example][example]
1959/// case 8. collapsed link: [example][] 1956/// case 8. collapsed link: [example][]
1960/// case 9. shortcut link: [example] 1957/// case 9. shortcut link: [example]
1961/// case 10. inline without URL: [example]() 1958/// case 10. inline without URL: [example]()
1962/// case 11. refrence: [foo][foo] 1959/// case 11. reference: [foo][foo]
1963/// case 12. refrence: [foo][bar] 1960/// case 12. reference: [foo][bar]
1964/// case 13. collapsed link: [foo][] 1961/// case 13. collapsed link: [foo][]
1965/// case 14. shortcut link: [foo] 1962/// case 14. shortcut link: [foo]
1966/// case 15. inline without URL: [foo]() 1963/// case 15. inline without URL: [foo]()
@@ -1987,16 +1984,16 @@ pub fn fo$0o() {}
1987 Test cases: 1984 Test cases:
1988 case 1. bare URL: https://www.example.com/ 1985 case 1. bare URL: https://www.example.com/
1989 case 2. inline URL with title: [example](https://www.example.com/) 1986 case 2. inline URL with title: [example](https://www.example.com/)
1990 case 3. code refrence: `Result` 1987 case 3. code reference: `Result`
1991 case 4. code refrence but miss footnote: `String` 1988 case 4. code reference but miss footnote: `String`
1992 case 5. autolink: http://www.example.com/ 1989 case 5. autolink: http://www.example.com/
1993 case 6. email address: [email protected] 1990 case 6. email address: [email protected]
1994 case 7. refrence: example 1991 case 7. reference: example
1995 case 8. collapsed link: example 1992 case 8. collapsed link: example
1996 case 9. shortcut link: example 1993 case 9. shortcut link: example
1997 case 10. inline without URL: example 1994 case 10. inline without URL: example
1998 case 11. refrence: foo 1995 case 11. reference: foo
1999 case 12. refrence: foo 1996 case 12. reference: foo
2000 case 13. collapsed link: foo 1997 case 13. collapsed link: foo
2001 case 14. shortcut link: foo 1998 case 14. shortcut link: foo
2002 case 15. inline without URL: foo 1999 case 15. inline without URL: foo