diff options
author | Edwin Cheng <[email protected]> | 2020-02-26 16:12:26 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-02-26 16:12:26 +0000 |
commit | 553254973e24a2c0bdf1475fccbbc4603e8421f0 (patch) | |
tree | a97feb3e004489c7b9896ba753a891cc7c07a8e0 /crates/ra_ide/src/hover.rs | |
parent | 2dee0779e9977e4570122c42ac35c4183bb8e604 (diff) |
Skip trival token in original_range
Diffstat (limited to 'crates/ra_ide/src/hover.rs')
-rw-r--r-- | crates/ra_ide/src/hover.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 29b16e602..177038e20 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -174,6 +174,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
174 | .ancestors() | 174 | .ancestors() |
175 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?; | 175 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?; |
176 | 176 | ||
177 | // FIXME: Currently `hover::typeof` do not work inside | ||
178 | // macro expansion such that if the hover range is pointing to | ||
179 | // a string literal, the following type_of will return None. | ||
180 | // See also `test_hover_through_literal_string_in_macro` | ||
177 | let frange = sema.original_range(&node); | 181 | let frange = sema.original_range(&node); |
178 | res.extend(type_of(db, frange).map(rust_code_markup)); | 182 | res.extend(type_of(db, frange).map(rust_code_markup)); |
179 | if res.is_empty() { | 183 | if res.is_empty() { |
@@ -250,6 +254,11 @@ mod tests { | |||
250 | content[hover.range].to_string() | 254 | content[hover.range].to_string() |
251 | } | 255 | } |
252 | 256 | ||
257 | fn check_hover_no_result(fixture: &str) { | ||
258 | let (analysis, position) = analysis_and_position(fixture); | ||
259 | assert!(analysis.hover(position).unwrap().is_none()); | ||
260 | } | ||
261 | |||
253 | #[test] | 262 | #[test] |
254 | fn hover_shows_type_of_an_expression() { | 263 | fn hover_shows_type_of_an_expression() { |
255 | let (analysis, position) = single_file_with_position( | 264 | let (analysis, position) = single_file_with_position( |
@@ -775,6 +784,24 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
775 | } | 784 | } |
776 | 785 | ||
777 | #[test] | 786 | #[test] |
787 | fn test_hover_through_literal_string_in_macro() { | ||
788 | // FIXME: Currently `hover::type_of` do not work inside | ||
789 | // macro expansion | ||
790 | check_hover_no_result( | ||
791 | r#" | ||
792 | //- /lib.rs | ||
793 | macro_rules! arr { | ||
794 | ($($tt:tt)*) => { [$($tt)*)] } | ||
795 | } | ||
796 | fn foo() { | ||
797 | let mastered_for_itunes = ""; | ||
798 | let _ = arr!("Tr<|>acks", &mastered_for_itunes); | ||
799 | } | ||
800 | "#, | ||
801 | ); | ||
802 | } | ||
803 | |||
804 | #[test] | ||
778 | fn test_hover_non_ascii_space_doc() { | 805 | fn test_hover_non_ascii_space_doc() { |
779 | check_hover_result( | 806 | check_hover_result( |
780 | " | 807 | " |