Skip to content

fix: use 4 spaces for indentation in macro expansion #16690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions crates/ide-assists/src/handlers/inline_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,24 +415,15 @@ fn inline(
let expr: &ast::Expr = expr;

let mut insert_let_stmt = || {
let param_ty = match param_ty {
None => None,
Some(param_ty) => {
if sema.hir_file_for(param_ty.syntax()).is_macro() {
if let Some(param_ty) =
ast::Type::cast(insert_ws_into(param_ty.syntax().clone()))
{
Some(param_ty)
} else {
Some(param_ty.clone_for_update())
}
} else {
Some(param_ty.clone_for_update())
}
let param_ty = param_ty.clone().map(|param_ty| {
if sema.hir_file_for(param_ty.syntax()).is_macro() {
ast::Type::cast(insert_ws_into(param_ty.syntax().clone())).unwrap_or(param_ty)
} else {
param_ty
}
};
let ty: Option<syntax::ast::Type> =
sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
});

let ty = sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);

let is_self = param
.name(sema.db)
Expand Down Expand Up @@ -1356,8 +1347,8 @@ macro_rules! define_foo {
define_foo!();
fn bar() -> u32 {
{
let x = 0;
x
let x = 0;
x
}
}
"#,
Expand Down Expand Up @@ -1670,7 +1661,7 @@ fn main() {
let a: A = A{};
let b = {
let a = a;
a as A
a as A
};
}
"#,
Expand Down Expand Up @@ -1789,7 +1780,7 @@ fn _hash2(self_: &u64, state: &mut u64) {
{
let inner_self_: &u64 = &self_;
let state: &mut u64 = state;
_write_u64(state, *inner_self_)
_write_u64(state, *inner_self_)
};
}
"#,
Expand Down
10 changes: 5 additions & 5 deletions crates/ide-assists/src/handlers/inline_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ macro_rules! foo {
}
fn main() {
cfg_if!{
if #[cfg(test)]{
1;
}else {
1;
}
if #[cfg(test)]{
1;
}else {
1;
}
};
}
"#,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
let after = Position::after;

let do_indent = |pos: fn(_) -> Position, token: &SyntaxToken, indent| {
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(2 * indent)))
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(4 * indent)))
};
let do_ws = |pos: fn(_) -> Position, token: &SyntaxToken| {
(pos(token.clone()), make::tokens::single_space())
Expand All @@ -41,7 +41,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
if indent > 0 {
mods.push((
Position::after(node.clone()),
make::tokens::whitespace(&" ".repeat(2 * indent)),
make::tokens::whitespace(&" ".repeat(4 * indent)),
));
}
if node.parent().is_some() {
Expand Down Expand Up @@ -91,10 +91,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
LIFETIME_IDENT if is_next(is_text, true) => {
mods.push(do_ws(after, tok));
}
MUT_KW if is_next(|it| it == SELF_KW, false) => {
mods.push(do_ws(after, tok));
}
AS_KW | DYN_KW | IMPL_KW | CONST_KW => {
AS_KW | DYN_KW | IMPL_KW | CONST_KW | MUT_KW => {
mods.push(do_ws(after, tok));
}
T![;] if is_next(|it| it != R_CURLY, true) => {
Expand Down
58 changes: 29 additions & 29 deletions crates/ide/src/expand_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ f$0oo!();
expect![[r#"
foo!
fn some_thing() -> u32 {
let a = 0;
a+10
let a = 0;
a+10
}"#]],
);
}
Expand Down Expand Up @@ -342,13 +342,13 @@ fn main() {
expect![[r#"
match_ast!
{
if let Some(it) = ast::TraitDef::cast(container.clone()){}
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
else {
{
continue
if let Some(it) = ast::TraitDef::cast(container.clone()){}
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
else {
{
continue
}
}
}
}"#]],
);
}
Expand Down Expand Up @@ -397,12 +397,12 @@ fn main() {
expect![[r#"
foo!
{
macro_rules! bar {
() => {
42
macro_rules! bar {
() => {
42
}
}
}
42
42
}"#]],
);
}
Expand Down Expand Up @@ -482,16 +482,16 @@ struct Foo {}
expect![[r#"
Clone
impl < >$crate::clone::Clone for Foo< >where {
fn clone(&self) -> Self {
match self {
Foo{}
=> Foo{}
,
fn clone(&self) -> Self {
match self {
Foo{}
=> Foo{}
,

}
}
}
}

}"#]],
}"#]],
);
}

Expand Down Expand Up @@ -534,16 +534,16 @@ struct Foo {}
expect![[r#"
Clone
impl < >$crate::clone::Clone for Foo< >where {
fn clone(&self) -> Self {
match self {
Foo{}
=> Foo{}
,
fn clone(&self) -> Self {
match self {
Foo{}
=> Foo{}
,

}
}
}
}

}"#]],
}"#]],
);
}
}
6 changes: 3 additions & 3 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6341,8 +6341,8 @@ fn main() { $0V; }

```rust
pub const V: i8 = {
let e = 123;
f(e)
let e = 123;
f(e)
}
```
"#]],
Expand All @@ -6368,7 +6368,7 @@ fn main() { $0V; }

```rust
pub static V: i8 = {
let e = 123;
let e = 123;
}
```
"#]],
Expand Down