Skip to content

Commit 002c437

Browse files
committed
fix: update to Mago 1.29.0 (new bytes-based format_code API)
mago-formatter changed its API across the 1.x line: - 1.29.0's `Formatter::format_code` now takes/returns `Cow<'static, [u8]>` / `&'arena [u8]` instead of `Cow<'static, str>` / `&'arena str`. Convert the path and source text to owned bytes before calling, and decode the resulting bytes back via `std::str::from_utf8` before returning. - 1.29.0 declares `rust-version = "1.95.0"`, so bump rust-toolchain.toml from 1.92.0 to 1.95.0. Without a `rust-version` in our Cargo.toml, cargo's MSRV-aware resolver had nothing to filter against and was picking 1.29.0 on top of Rust 1.92 anyway — which broke CI. - Update Cargo.toml's `mago-formatter` / `mago-php-version` pin from 1.0.3 to 1.29.0. - Regenerate test specs: 1.29.0 now inlines empty function/method bodies by default (`function foo() {}` rather than the old multi-line brace form), so the corresponding `.txt` specs needed refreshing.
1 parent 19c0825 commit 002c437

9 files changed

Lines changed: 21 additions & 41 deletions

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ wasm = ["serde_json", "dprint-core/wasm"]
2727
anyhow = "1.0.51"
2828
bumpalo = "3"
2929
dprint-core = { version = "0.67.4", default-features = false }
30-
mago-formatter = "1.0.3"
31-
mago-php-version = "1.0.3"
30+
mago-formatter = "1.29.0"
31+
mago-php-version = "1.29.0"
3232
serde = { version = "1.0.210", features = ["derive"] }
3333
serde_json = { version = "1.0", optional = true }
3434

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.92.0"
2+
channel = "1.95.0"
33
components = ["clippy", "rustfmt"]

src/format_text.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ pub fn format_text(file_path: &Path, input_text: &str, config: &Configuration) -
3333
let settings = build_format_settings(config);
3434
let formatter = Formatter::new(&arena, php_version, settings);
3535

36-
let file_name = file_path.to_string_lossy().into_owned();
37-
let formatted = formatter.format_code(Cow::Owned(file_name), Cow::Owned(input_text.to_string()))?;
36+
// mago_formatter::Formatter::format_code requires Cow<'static, [u8]>,
37+
// so the runtime inputs are converted to owned Vec<u8>.
38+
let file_name = file_path.to_string_lossy().into_owned().into_bytes();
39+
let code = input_text.as_bytes().to_vec();
40+
let formatted = formatter.format_code(Cow::Owned(file_name), Cow::Owned(code))?;
41+
let formatted = std::str::from_utf8(formatted)?;
3842

3943
if formatted == input_text {
4044
Ok(None)

tests/specs/ClassMembers.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class Foo
1515

1616
public $y;
1717

18-
public function bar()
19-
{
20-
}
18+
public function bar() {}
2119
}
2220

2321
== should not sort class methods (default) ==
@@ -33,15 +31,9 @@ class Foo {
3331

3432
class Foo
3533
{
36-
public function z()
37-
{
38-
}
34+
public function z() {}
3935

40-
private function a()
41-
{
42-
}
36+
private function a() {}
4337

44-
protected function m()
45-
{
46-
}
38+
protected function m() {}
4739
}

tests/specs/ClassMembersSeparateFalse.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ class Foo
1818

1919
public $y;
2020

21-
public function bar()
22-
{
23-
}
21+
public function bar() {}
2422
}

tests/specs/ClassMembersSortTrue.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@ class Foo {
1212

1313
class Foo
1414
{
15-
public function a()
16-
{
17-
}
15+
public function a() {}
1816

19-
protected function m()
20-
{
21-
}
17+
protected function m() {}
2218

23-
private function z()
24-
{
25-
}
19+
private function z() {}
2620
}

tests/specs/EmptyBraces.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class Foo {
4141

4242
class Foo
4343
{
44-
public function bar()
45-
{
46-
}
44+
public function bar() {}
4745
}
4846

4947
== should not inline empty function braces (default) ==
@@ -53,9 +51,7 @@ function foo() {}
5351
[expect]
5452
<?php
5553

56-
function foo()
57-
{
58-
}
54+
function foo() {}
5955

6056
== should not inline empty control braces (default) ==
6157
<?php

tests/specs/Spacing.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,4 @@ function test(& $x) {}
6363
[expect]
6464
<?php
6565

66-
function test(&$x)
67-
{
68-
}
66+
function test(&$x) {}

tests/specs/SpacingReferenceSpace.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ function test(&$x) {}
66
[expect]
77
<?php
88

9-
function test(&$x)
10-
{
11-
}
9+
function test(&$x) {}

0 commit comments

Comments
 (0)