Weird inconsistent zig fmt bug on non-ascii chars

so I was working on something with Zig and encountered a weird fmt bug which I could not replicate consistently with zig fmt unlike the lsp

for context, here is a file I made to check for it:

before save:

fn name() !void {
    const @"é" = .{ @intCast(32)}; // breaks
    const @"é" = .{ sometext}; // breaks
    const @"é" = .{@intCast(32) }; // breaks
    const @"é" = .{sometext }; // breaks
    const @"é" = .{@intCast(32)}; // fine
    const @"é" = .{sometext}; // fine

    std.debug.print("ééé  {s}", .{ @builtinthing(12) });
    std.debug.print("يمينص  {s}", .{ @builtinthing(12)} );
    std.debug.print("يمينص  {s}", .{        @intCast(12) });
    std.debug.print("س  {s}", .{ @import("dank").daj()  }  );
}

after save:

fn name() !void {
    const @"é" = .{ intCast(32)}; // breaks
    const @"é" = .{ ometext}; // breaks
    const @"é" = .{@intCast(32) ; // breaks
    const @"é" = .{sometext ; // breaks
    const @"é" = .{@intCast(32)}; // fine
    const @"é" = .{sometext}; // fine

    std.debug.print("ééé  {s}", .{ @biltinthing(12) })
    std.debug.print("يمينص  {s}", .{ @buitinthing(12)} );
    std.debug.print("يمينص  {s}", .{     ast(12) });
    std.debug.print("س  {s}", .{ import("dank").daj()  ;
}

I use Neovim with zls and directly using zig fmt works fine here. I tried using zig fmt directly to find the issue, but while experimenting I lost the where zig fmt breaks the file (it would be great if it was only broken cuse zls touched it though)

zig fmt would break the file then print an error for invalid token. but since I can’t “undo” after calling the shell command, I couldn’t get the the input which caused the error

This isn’t a ZLS issue. ZLS calls zig fmt code under the hood.

This looks like a bug to me. I would suggest looking at the issues to see if it is reported and if not, file an issue on the ziglang/zig repo.

I actually started writing a bug report, the problem is that I could not replicate it consistently with just the shell command zig fmt file.zig I could trigger it twice or so but now I don’t know what I did (because zig fmt causes the undo history to be cleared ig). but when zls calls it it is guaranteed to break