From 87436a08fa63b7e5d0d6010d8c76379aa5ee16fd Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Tue, 7 Sep 2021 17:49:46 +0800 Subject: [PATCH] fix `super` path wrong display --- crates/hir_ty/src/display.rs | 10 ++++++---- crates/ide/src/hover.rs | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index e394b72d5d6..1ae718a36b8 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -1141,13 +1141,15 @@ impl HirDisplay for Path { write!(f, ">")?; } (_, PathKind::Plain) => {} - (_, PathKind::Abs) => write!(f, "")?, + (_, PathKind::Abs) => {} (_, PathKind::Crate) => write!(f, "crate")?, (_, PathKind::Super(0)) => write!(f, "self")?, (_, PathKind::Super(n)) => { - write!(f, "super")?; - for _ in 0..*n { - write!(f, "::super")?; + for i in 0..*n { + if i > 0 { + write!(f, "::")?; + } + write!(f, "super")?; } } (_, PathKind::DollarCrate(_)) => write!(f, "{{extern_crate}}")?, diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index f9000ca0000..62a322f9769 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -963,7 +963,7 @@ fn main() { let foo_test = fo$0o(); } "#]], ); - // use literal `crate` in path + // Use literal `crate` in path check( r#" pub struct X; @@ -984,6 +984,28 @@ fn main() { f$0oo(); } ``` "#]], ); + + // Check `super` in path + check( + r#" +pub struct X; + +mod m { pub fn foo() -> super::X { super::X } } + +fn main() { m::f$0oo(); } + "#, + expect![[r#" + *foo* + + ```rust + test::m + ``` + + ```rust + pub fn foo() -> super::X + ``` + "#]], + ); } #[test]