From e73ee9dfa28e2c093cc79e0e8d729945c43f3c81 Mon Sep 17 00:00:00 2001 From: flw Date: Sat, 26 Sep 2020 13:02:09 +0800 Subject: Add hover config `linksInHover` to suppress links --- crates/ide/src/hover.rs | 113 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 9 deletions(-) (limited to 'crates/ide/src/hover.rs') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 37171cbef..bb9f12cd3 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -14,7 +14,7 @@ use test_utils::mark; use crate::{ display::{macro_label, ShortLabel, ToNav, TryToNav}, - link_rewrite::rewrite_links, + link_rewrite::{remove_links, rewrite_links}, markup::Markup, runnables::runnable, FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, @@ -26,17 +26,29 @@ pub struct HoverConfig { pub run: bool, pub debug: bool, pub goto_type_def: bool, + pub links_in_hover: bool, } impl Default for HoverConfig { fn default() -> Self { - Self { implementations: true, run: true, debug: true, goto_type_def: true } + Self { + implementations: true, + run: true, + debug: true, + goto_type_def: true, + links_in_hover: true, + } } } impl HoverConfig { - pub const NO_ACTIONS: Self = - Self { implementations: false, run: false, debug: false, goto_type_def: false }; + pub const NO_ACTIONS: Self = Self { + implementations: false, + run: false, + debug: false, + goto_type_def: false, + links_in_hover: true, + }; pub fn any(&self) -> bool { self.implementations || self.runnable() || self.goto_type_def @@ -75,7 +87,11 @@ pub struct HoverResult { // // Shows additional information, like type of an expression or documentation for definition when "focusing" code. // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut. -pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option> { +pub(crate) fn hover( + db: &RootDatabase, + position: FilePosition, + links_in_hover: bool, +) -> Option> { let sema = Semantics::new(db); let file = sema.parse(position.file_id).syntax().clone(); let token = pick_best(file.token_at_offset(position.offset))?; @@ -93,7 +109,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option +/// case 6. email address: +/// case 7. refrence: [example][example] +/// case 8. collapsed link: [example][] +/// case 9. shortcut link: [example] +/// case 10. inline without URL: [example]() +/// case 11. refrence: [foo][foo] +/// case 12. refrence: [foo][bar] +/// case 13. collapsed link: [foo][] +/// case 14. shortcut link: [foo] +/// case 15. inline without URL: [foo]() +/// case 16. just escaped text: \[foo] +/// case 17. inline link: [Foo](foo::Foo) +/// +/// [`Result`]: ../../std/result/enum.Result.html +/// [^example]: https://www.example.com/ +pub fn fo<|>o() {} +"#, + expect![[r#" + *foo* + + ```rust + test + ``` + + ```rust + pub fn foo() + ``` + + --- + + Test cases: + case 1. bare URL: https://www.example.com/ + case 2. inline URL with title: [example](https://www.example.com/) + case 3. code refrence: `Result` + case 4. code refrence but miss footnote: `String` + case 5. autolink: http://www.example.com/ + case 6. email address: test@example.com + case 7. refrence: example + case 8. collapsed link: example + case 9. shortcut link: example + case 10. inline without URL: example + case 11. refrence: foo + case 12. refrence: foo + case 13. collapsed link: foo + case 14. shortcut link: foo + case 15. inline without URL: foo + case 16. just escaped text: \[foo] + case 17. inline link: Foo + + [^example]: https://www.example.com/ + "#]], + ); + } + #[test] fn test_hover_macro_generated_struct_fn_doc_comment() { mark::check!(hover_macro_generated_struct_fn_doc_comment); -- cgit v1.2.3