diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-01-12 13:14:00 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2025-01-12 13:14:00 +0100 |
| commit | ab9779b4907c429eac6da247ec784189df7b5f07 (patch) | |
| tree | 5e91b93fc53cac1661cc0700a1b5d1d37df60a17 /src/tools | |
| parent | f00e5ca78700f184e847dd363fe276fcedf68356 (diff) | |
| download | rust-ab9779b4907c429eac6da247ec784189df7b5f07.tar.gz rust-ab9779b4907c429eac6da247ec784189df7b5f07.zip | |
fix: Fix `ref` text edit for binding mode hints
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints/binding_mode.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/binding_mode.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/binding_mode.rs index 5afb98cb1c7..ed2bd8d2a8f 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/binding_mode.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/binding_mode.rs @@ -106,7 +106,7 @@ pub(super) fn hints( InlayHintPosition::Before => h.range.start(), InlayHintPosition::After => h.range.end(), }, - h.label.parts.iter().map(|p| &*p.text).collect(), + h.label.parts.iter().map(|p| &*p.text).chain(h.pad_right.then_some(" ")).collect(), ); } let edit = edit.finish(); @@ -118,8 +118,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 +196,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,)) => (), + } + } + "#]], + ); + } } |
