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

Improper indentation after "else" #104

Open
davaya opened this issue Sep 4, 2021 · 2 comments
Open

Improper indentation after "else" #104

davaya opened this issue Sep 4, 2021 · 2 comments
Assignees
Labels
bug something isn't working formatter code formatter issues

Comments

@davaya
Copy link

davaya commented Sep 4, 2021

Description

Statements after single-line else statement are indented one level more than expected.

Unformatted input snippet

encoding := "utf-16"
if (encoding = "utf-16")
encodingSize := 2, charType := "UShort"
else encodingSize := 1, charType := "Char"
MsgBox, Bytes per char: %encodingSize%

Expected formatted output snippet

encoding := "utf-16"
if (encoding = "utf-16")
    encodingSize := 2, charType := "UShort"
else encodingSize := 1, charType := "Char"
MsgBox, Bytes per char: %encodingSize%

or preferably:

encoding := "utf-16"
if (encoding = "utf-16")
    encodingSize := 2, charType := "UShort"
else
    encodingSize := 1, charType := "Char"
MsgBox, Bytes per char: %encodingSize%

Actual formatted output snippet

encoding := "utf-16"
if (encoding = "utf-16")
    encodingSize := 2, charType := "UShort"
else encodingSize := 1, charType := "Char"
    MsgBox, Bytes per char: %encodingSize%

Yes, the original unformatted input sucks. But one purpose of formatting is to help understand badly-written code. The debugger parses it correctly, always executing the last line regardless of its indentation. Using AHK's own AST for formatting
would avoid inconsistencies between appearance and performance.

@davaya davaya added bug something isn't working formatter code formatter issues labels Sep 4, 2021
@mark-wiemer
Copy link
Member

Yes, I do plan to research AHK's actual AST and effectively recreate it for exactly this reason. Thanks for the bug report, formatting / AST-related issues are the ones I'm most excited to work on.

@mark-wiemer mark-wiemer added this to the Backlog milestone Jun 3, 2022
@mark-wiemer mark-wiemer removed this from the Backlog milestone Oct 15, 2022
Repository owner moved this from To do to Done in [Archived] AutoHotkey for VS Code Dec 3, 2022
@mark-wiemer mark-wiemer reopened this Dec 3, 2022
@mark-wiemer mark-wiemer moved this to Todo in AHK++ Aug 18, 2024
@mark-wiemer
Copy link
Member

Can still reproduce in 6.2.3, keeping in backlog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working formatter code formatter issues
Projects
Status: Todo
Development

No branches or pull requests

2 participants