Skip to content

Commit

Permalink
fix: insert whitespace between text and pound
Browse files Browse the repository at this point in the history
`text#`, `text"..."`, and `text'...'` are reserved syntax since Rust
2021. Note that the latter two are already handled correctly.
  • Loading branch information
lowr committed Apr 5, 2023
1 parent a646439 commit 0df9fb2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 45 additions & 0 deletions crates/ide-assists/src/handlers/inline_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,49 @@ fn f() { if true{}; }
"#,
)
}

#[test]
fn whitespace_between_text_and_pound() {
check_assist(
inline_macro,
r#"
macro_rules! foo {
() => {
cfg_if! {
if #[cfg(test)] {
1;
} else {
1;
}
}
}
}
fn main() {
$0foo!();
}
"#,
r#"
macro_rules! foo {
() => {
cfg_if! {
if #[cfg(test)] {
1;
} else {
1;
}
}
}
}
fn main() {
cfg_if!{
if #[cfg(test)]{
1;
}else {
1;
}
};
}
"#,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
|f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };

match tok.kind() {
k if is_text(k) && is_next(|it| !it.is_punct() || it == UNDERSCORE, false) => {
k if is_text(k)
&& is_next(|it| !it.is_punct() || matches!(it, T![_] | T![#]), false) =>
{
mods.push(do_ws(after, tok));
}
L_CURLY if is_next(|it| it != R_CURLY, true) => {
Expand Down

0 comments on commit 0df9fb2

Please sign in to comment.