From 4a0bb3d7c53c2a914649087bf206d52ed5768576 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Thu, 7 Mar 2019 10:32:39 +0200 Subject: Add support for goto definition and hover on Self This fixes #943 --- crates/ra_ide_api/src/hover.rs | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 638c24e31..f14001e84 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -557,4 +557,62 @@ mod tests { assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32")); assert_eq!(hover.info.is_exact(), true); } + + #[test] + fn test_hover_self() { + let (analysis, position) = single_file_with_position( + " + struct Thing { x: u32 }; + impl Thing { + fn new() -> Self { + Self<|> { x: 0 } + } + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing")); + assert_eq!(hover.info.is_exact(), true); + + let (analysis, position) = single_file_with_position( + " + struct Thing { x: u32 }; + impl Thing { + fn new() -> Self<|> { + Self { x: 0 } + } + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing")); + assert_eq!(hover.info.is_exact(), true); + + let (analysis, position) = single_file_with_position( + " + enum Thing { A }; + impl Thing { + pub fn new() -> Self<|> { + Thing::A + } + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); + assert_eq!(hover.info.is_exact(), true); + + let (analysis, position) = single_file_with_position( + " + enum Thing { A }; + impl Thing { + pub fn thing(a: Self<|>) { + } + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); + assert_eq!(hover.info.is_exact(), true); + } } -- cgit v1.2.3