Skip to content

better handle indentation when rendering source code #19293

Closed
@andrewrk

Description

@andrewrk

Extracted from #19249.

Example

pub fn count(self: Self) usize {
            return self.entries.len;
        }

Instead it should render like this:

pub fn count(self: Self) usize {
    return self.entries.len;
}

This happens because it is rendering only the function declaration directly from the file, which in fact is indented two levels. The rendering function needs to detect this and chop off the indentation levels.

Some Examples

Case 1

Input:

    fn add(a: u32, b: u32) u32 {
        return a + b;
    }

Expected Output:

fn add(a: u32, b: u32) u32 {
    return a + b;
}

Case 2

Input:

    const a = 1; fn add(a: u32, b: u32) u32 {
        return a + b;
    }

Expected Output:

fn add(a: u32, b: u32) u32 {
    return a + b;
}

Case 3

Input:

    fn add(a: u32, b: u32) u32 {
return a + b;
    }

Expected Output:

fn add(a: u32, b: u32) u32 {
return a + b;
}

Case 4

Input:

    const a = 1; fn add(a: u32, b: u32) u32 {
return a + b;
    }

Expected Output:

fn add(a: u32, b: u32) u32 {
return a + b;
}

Note that those last two cases are planned to become syntax errors:

Metadata

Metadata

Assignees

No one assigned

    Labels

    autodocThe web application for interactive documentation and generation of its assets.bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions