diff options
author | Aaron Loucks <[email protected]> | 2020-05-31 16:33:48 +0100 |
---|---|---|
committer | Aaron Loucks <[email protected]> | 2020-06-03 11:46:07 +0100 |
commit | 5837acce532e0cd65a1c0cb8c03cc18a4c22f327 (patch) | |
tree | fa162f2dc57a53be9a6090fb3776cc9586332551 /crates/ra_ide/src/hover.rs | |
parent | 4c655c01f31ceffae4f8219f9706992e0e7f188a (diff) |
Add basic hover and completion doc tests for macro generated items
Diffstat (limited to 'crates/ra_ide/src/hover.rs')
-rw-r--r-- | crates/ra_ide/src/hover.rs | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index e25a7dacf..731fc3673 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -256,7 +256,7 @@ fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { | |||
256 | if docs.is_empty() { | 256 | if docs.is_empty() { |
257 | None | 257 | None |
258 | } else { | 258 | } else { |
259 | Some(docs) | 259 | Some(docs.trim_end_matches("\n\n").to_owned()) |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
@@ -996,4 +996,106 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
996 | &["mod my"], | 996 | &["mod my"], |
997 | ); | 997 | ); |
998 | } | 998 | } |
999 | |||
1000 | #[test] | ||
1001 | fn test_hover_struct_doc_comment() { | ||
1002 | check_hover_result( | ||
1003 | r#" | ||
1004 | //- /lib.rs | ||
1005 | /// bar docs | ||
1006 | struct Bar; | ||
1007 | |||
1008 | fn foo() { | ||
1009 | let bar = Ba<|>r; | ||
1010 | } | ||
1011 | "#, | ||
1012 | &["struct Bar\n```\n___\n\nbar docs"], | ||
1013 | ); | ||
1014 | } | ||
1015 | |||
1016 | #[test] | ||
1017 | fn test_hover_struct_doc_attr() { | ||
1018 | check_hover_result( | ||
1019 | r#" | ||
1020 | //- /lib.rs | ||
1021 | #[doc = "bar docs"] | ||
1022 | struct Bar; | ||
1023 | |||
1024 | fn foo() { | ||
1025 | let bar = Ba<|>r; | ||
1026 | } | ||
1027 | "#, | ||
1028 | &["struct Bar\n```\n___\n\nbar docs"], | ||
1029 | ); | ||
1030 | } | ||
1031 | |||
1032 | #[test] | ||
1033 | fn test_hover_struct_doc_attr_multiple_and_mixed() { | ||
1034 | check_hover_result( | ||
1035 | r#" | ||
1036 | //- /lib.rs | ||
1037 | /// bar docs 0 | ||
1038 | #[doc = "bar docs 1"] | ||
1039 | #[doc = "bar docs 2"] | ||
1040 | struct Bar; | ||
1041 | |||
1042 | fn foo() { | ||
1043 | let bar = Ba<|>r; | ||
1044 | } | ||
1045 | "#, | ||
1046 | &["struct Bar\n```\n___\n\nbar docs 0\n\nbar docs 1\n\nbar docs 2"], | ||
1047 | ); | ||
1048 | } | ||
1049 | |||
1050 | #[test] | ||
1051 | fn test_hover_macro_generated_struct_fn_doc_comment() { | ||
1052 | check_hover_result( | ||
1053 | r#" | ||
1054 | //- /lib.rs | ||
1055 | macro_rules! bar { | ||
1056 | () => { | ||
1057 | struct Bar; | ||
1058 | impl Bar { | ||
1059 | /// Do the foo | ||
1060 | fn foo(&self) {} | ||
1061 | } | ||
1062 | } | ||
1063 | } | ||
1064 | |||
1065 | bar!(); | ||
1066 | |||
1067 | fn foo() { | ||
1068 | let bar = Bar; | ||
1069 | bar.fo<|>o(); | ||
1070 | } | ||
1071 | "#, | ||
1072 | &["Bar\n```\n\n```rust\nfn foo(&self)\n```\n___\n\n Do the foo"], | ||
1073 | ); | ||
1074 | } | ||
1075 | |||
1076 | #[test] | ||
1077 | fn test_hover_macro_generated_struct_fn_doc_attr() { | ||
1078 | check_hover_result( | ||
1079 | r#" | ||
1080 | //- /lib.rs | ||
1081 | macro_rules! bar { | ||
1082 | () => { | ||
1083 | struct Bar; | ||
1084 | impl Bar { | ||
1085 | #[doc = "Do the foo"] | ||
1086 | fn foo(&self) {} | ||
1087 | } | ||
1088 | } | ||
1089 | } | ||
1090 | |||
1091 | bar!(); | ||
1092 | |||
1093 | fn foo() { | ||
1094 | let bar = Bar; | ||
1095 | bar.fo<|>o(); | ||
1096 | } | ||
1097 | "#, | ||
1098 | &["Bar\n```\n\n```rust\nfn foo(&self)\n```\n___\n\nDo the foo"], | ||
1099 | ); | ||
1100 | } | ||
999 | } | 1101 | } |