From 4029e4410245eeb2e1f58adefad1d4cc24898579 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 22 Jan 2020 16:44:05 +0200 Subject: Omit default parameters for reference types --- crates/ra_hir_ty/src/display.rs | 2 +- crates/ra_hir_ty/src/lib.rs | 7 ++++++- crates/ra_ide/src/inlay_hints.rs | 14 +++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 37def7c03..d1ff85f0f 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs @@ -9,7 +9,7 @@ pub struct HirFormatter<'a, 'b, DB> { fmt: &'a mut fmt::Formatter<'b>, buf: String, curr_size: usize, - max_size: Option, + pub(crate) max_size: Option, omit_verbose_types: bool, } diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index d63f862dc..908e4862d 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -855,7 +855,12 @@ impl HirDisplay for ApplicationTy { } TypeCtor::Ref(m) => { let t = self.parameters.as_single(); - write!(f, "&{}{}", m.as_keyword_for_ref(), t.display(f.db))?; + let ty_display = if f.omit_verbose_types() { + t.display_truncated(f.db, f.max_size) + } else { + t.display(f.db) + }; + write!(f, "&{}{}", m.as_keyword_for_ref(), ty_display)?; } TypeCtor::Never => write!(f, "!")?, TypeCtor::Tuple { .. } => { diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 236557541..393ca9447 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -245,6 +245,7 @@ struct Test { fn main() { let zz = Test { t: 23, k: 33 }; + let zz_ref = &zz; }"#, ); @@ -255,6 +256,11 @@ fn main() { kind: TypeHint, label: "Test", }, + InlayHint { + range: [105; 111), + kind: TypeHint, + label: "&Test", + }, ] "### ); @@ -374,6 +380,7 @@ fn main() { let multiply = |a, b, c, d| a * b * c * d; let _: i32 = multiply(1, 2, 3, 4); + let multiply_ref = &multiply; let return_42 = || 42; }"#, @@ -417,7 +424,12 @@ fn main() { label: "i32", }, InlayHint { - range: [201; 210), + range: [200; 212), + kind: TypeHint, + label: "&|…| -> i32", + }, + InlayHint { + range: [235; 244), kind: TypeHint, label: "|| -> i32", }, -- cgit v1.2.3