ZigBrains icon indicating copy to clipboard operation
ZigBrains copied to clipboard

Zig fmt parity [Report identation/formatting errors here!]

Open tovedetered opened this issue 1 year ago • 6 comments

Expected Formatting:

pub fn logToFile(
    comptime level: std.log.Level,
    comptime scope: @TypeOf(.EnumLiteral),
    comptime format: []const u8,
    args: anytype,
) void {
    const scope_prefix = "(" ++ switch (scope) {
        std.log.default_log_scope => @tagName(scope),
        else => if (@intFromEnum(level) <= @intFromEnum(std.log.Level.err))
            @tagName(scope)
        else
            return,
    } ++ "): ";

    const prefix = "[" ++ comptime level.asText() ++ "] " ++ scope_prefix;

    // Print the message to stderr, silently ignoring any errors
    std.debug.getStderrMutex().lock();
    defer std.debug.getStderrMutex().unlock();
    const stderr = std.io.getStdErr().writer();
    nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
}

ZigBrains Formatting

pub fn logToFile(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
    const scope_prefix = "(" ++ switch (scope) {
    std.log.default_log_scope => @tagName(scope),
    else => if (@intFromEnum(level) <= @intFromEnum(std.log.Level.err))
    @tagName(scope)
    else
    return,
    } ++ "): ";
 
    const prefix = "[" ++ comptime level.asText() ++ "] " ++ scope_prefix;

    // Print the message to stderr, silently ignoring any errors
    std.debug.getStderrMutex().lock();
    defer std.debug.getStderrMutex().unlock();
    const stderr = std.io.getStdErr().writer();
    nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
}

tovedetered avatar May 20 '24 12:05 tovedetered

ZigBrains: v14.3.0-241 Zig: Master

tovedetered avatar May 20 '24 12:05 tovedetered

Fixed in 14.4.0

FalsePattern avatar May 28 '24 01:05 FalsePattern

I'll repurpose this issue as a general zig fmt indentation / formatting mismatch tracker, it's easier to have everything in one place than having to open new issues every time.


Comments marked with a :+1: in this issue means that the specific formatting issues reported in that comment have been fixed.

FalsePattern avatar May 28 '24 01:05 FalsePattern

Hi,

The formatting fix worked, but when the correct formatting is applied the coloration of the keywords is messed up. image

I do not know if this is a ZigBrains issue, or something to do with Clion. But this issue only seems to appear when the code is formatted to comply with zig fmt. ie. after a Ctrl-S -> reformat.

Closing + reopening the file and restarting the LSP does not seem to fix the issue

- Spenser

tovedetered avatar May 29 '24 22:05 tovedetered

It is indeed a zigbrains issue (weird race condition when applying the formatting and re-requesting syntax highlighting), i've also experienced it pretty consistently in my own projects

As a workaround, you can fix it by restarting the language server using the status icon circle.

I have it fixed in my local development branch, i think i'll be able to push a patch update this week, i just need to untangle it from the major feature update i'm working on.

EDIT: Fixed in 14.5.0

FalsePattern avatar May 29 '24 22:05 FalsePattern

Fixed some more indent problems in 7231d1b6a26a4872058d7d0452d94b472012f5ae:

  • Chained additions/bitwise operations/etc. split over multiple lines now indent properly
  • Inline assembly indentation is now correct
  • The closing bracket of a struct/union/enum will no longer occasionally have an extra unnecessary indent

FalsePattern avatar Jul 17 '24 21:07 FalsePattern

It seems like formatting is working properly for the time being, i will close this issue for now, it can be reopened if the language changes and formatting breaks again.

FalsePattern avatar Oct 14 '24 15:10 FalsePattern