Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints/binding_mode.rs')
| -rw-r--r-- | crates/ide/src/inlay_hints/binding_mode.rs | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/crates/ide/src/inlay_hints/binding_mode.rs b/crates/ide/src/inlay_hints/binding_mode.rs index 5afb98cb1c..5bbb4fe4e6 100644 --- a/crates/ide/src/inlay_hints/binding_mode.rs +++ b/crates/ide/src/inlay_hints/binding_mode.rs @@ -99,17 +99,24 @@ pub(super) fn hints( } if let hints @ [_, ..] = &mut acc[acc_base..] { - let mut edit = TextEditBuilder::default(); - for h in &mut *hints { - edit.insert( - match h.position { - InlayHintPosition::Before => h.range.start(), - InlayHintPosition::After => h.range.end(), - }, - h.label.parts.iter().map(|p| &*p.text).collect(), - ); - } - let edit = edit.finish(); + let edit = config.lazy_text_edit(|| { + let mut edit = TextEditBuilder::default(); + for h in &mut *hints { + edit.insert( + match h.position { + InlayHintPosition::Before => h.range.start(), + InlayHintPosition::After => h.range.end(), + }, + h.label + .parts + .iter() + .map(|p| &*p.text) + .chain(h.pad_right.then_some(" ")) + .collect(), + ); + } + edit.finish() + }); hints.iter_mut().for_each(|h| h.text_edit = Some(edit.clone())); } @@ -118,8 +125,10 @@ pub(super) fn hints( #[cfg(test)] mod tests { + use expect_test::expect; + use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, + inlay_hints::tests::{check_edit, check_with_config, DISABLED_CONFIG}, InlayHintsConfig, }; @@ -194,4 +203,27 @@ fn foo(s @ Struct { field, .. }: &Struct) {} "#, ); } + + #[test] + fn edits() { + check_edit( + InlayHintsConfig { binding_mode_hints: true, ..DISABLED_CONFIG }, + r#" +fn main() { + match &(0,) { + (x,) | (x,) => (), + ((x,) | (x,)) => (), + } +} +"#, + expect![[r#" + fn main() { + match &(0,) { + &(&((ref x,) | (ref x,))) => (), + &((ref x,) | (ref x,)) => (), + } + } + "#]], + ); + } } |