Skip to content
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

better handle indentation when rendering source code #19293

Closed
Tracked by #19249
andrewrk opened this issue Mar 13, 2024 · 0 comments · Fixed by #19422
Closed
Tracked by #19249

better handle indentation when rendering source code #19293

andrewrk opened this issue Mar 13, 2024 · 0 comments · Fixed by #19422
Labels
autodoc The web application for interactive documentation and generation of its assets. bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Mar 13, 2024

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:

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. autodoc The web application for interactive documentation and generation of its assets. labels Mar 13, 2024
@andrewrk andrewrk added this to the 0.13.0 milestone Mar 13, 2024
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autodoc The web application for interactive documentation and generation of its assets. bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals.
Projects
None yet
1 participant