Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/postfix.rs')
-rw-r--r--crates/ide-completion/src/completions/postfix.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions/postfix.rs b/crates/ide-completion/src/completions/postfix.rs
index fbae0f858c..0cb39dd108 100644
--- a/crates/ide-completion/src/completions/postfix.rs
+++ b/crates/ide-completion/src/completions/postfix.rs
@@ -12,7 +12,7 @@ use ide_db::{
text_edit::TextEdit,
ty_filter::TryEnum,
};
-use itertools::Itertools;
+use itertools::{Either, Itertools};
use stdx::never;
use syntax::{
SmolStr,
@@ -468,6 +468,11 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, String) {
.syntax()
.children_with_tokens()
.filter(|it| Some(it) != last_child_or_token.as_ref())
+ .flat_map(|it| {
+ let has_ws = it.next_sibling_or_token().is_some_and(|it| it.kind().is_trivia());
+ let need_ws = !has_ws && it.kind().is_any_identifier();
+ itertools::chain([Either::Left(it)], need_ws.then_some(Either::Right(" ")))
+ })
.format("")
.to_smolstr()
.as_str(),
@@ -1569,6 +1574,15 @@ fn main() {
r#"fn main() { &raw const Foo::bar::SOME_CONST.$0 }"#,
r#"fn main() { (&raw const Foo::bar::SOME_CONST) }"#,
);
+
+ check_edit_with_config(
+ CompletionConfig { snippets: vec![snippet.clone()], ..TEST_CONFIG },
+ "group",
+ r#"macro_rules! id { ($($t:tt)*) => ($($t)*); }
+fn main() { id!(&raw const Foo::bar::SOME_CONST.$0) }"#,
+ r#"macro_rules! id { ($($t:tt)*) => ($($t)*); }
+fn main() { id!((&raw const Foo::bar::SOME_CONST)) }"#,
+ );
}
#[test]