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

"Lone" else lines are not properly indented #73

Open
yohannd1 opened this issue Mar 16, 2022 · 4 comments
Open

"Lone" else lines are not properly indented #73

yohannd1 opened this issue Mar 16, 2022 · 4 comments

Comments

@yohannd1
Copy link
Contributor

By "lone" else lines, I mean lines in if statements that only have whitespace and the else keyword. They're usually around when there is a multi-line if condition that isn't directly made up of blocks.

For an actual example on what is happening - I typed this code from top to bottom using automatic indentation:

const a = if (cond)
    val1
    else
    val2;

pub fn main() void {
    const b = if (cond)
        val1
        else
            val2;
}

What I expect to happen is the following:

const a = if (cond)
    val1
else
    val2;

pub fn main() void {
    const b = if (cond)
        val1
    else
        val2;
}

NOTE: I was previously working on this under the #59 PR, but got stuck and don't really know where to go anymore, so I'm leaving it up for anyone who may be able to tackle this in a better way.

@matu3ba

This comment was marked as off-topic.

@talcynon
Copy link

talcynon commented Jan 2, 2023

Is it fair to say that a lone else should always be de-indented? Is there a time when it should never be de-indented?

@talcynon
Copy link

talcynon commented Jan 2, 2023

@matu3ba I think the issue is limited to if expressions. (An if statement would always start on its own line.) For example, this is a valid Zig program:

pub fn main() u8 {
    const retval = if (true)
        0
    else
        1;
    return retval;
}

@matu3ba
Copy link

matu3ba commented Jan 2, 2023

Ah, now I do understand the problem.
I think a proper solution requires a parser to distinguish expressions from statements, since those can be arbitrarily nested.

I can tell you that nvim-treesitter indent is broken for Zig and helix has also not implemented indentation based on treesitter yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants