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

Formatter incorrectly indents object literals #222

Closed
incansvl opened this issue Sep 2, 2022 · 1 comment · Fixed by #260
Closed

Formatter incorrectly indents object literals #222

incansvl opened this issue Sep 2, 2022 · 1 comment · Fixed by #260
Assignees
Labels
bug something isn't working formatter code formatter issues

Comments

@incansvl
Copy link

incansvl commented Sep 2, 2022

Description

The formatter does not behave properly on multi-line object literal assignments.

Unformatted input snippet

PF= C:\Program Files
PF86= C:\Program Files (x86)

; first version
AppPaths := {
    "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
    , "bar.exe" : PF86 . "bar\bar.exe"
}

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe" : PF86 . "\foo\foo.exe"
            , "bar.exe" : PF86 . "bar\bar.exe" }

Expected formatted output snippet

; first version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe"       : PF86 . "\foo\foo.exe"
            , "bar.exe"       : PF86 . "bar\bar.exe" }

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe"       : PF86 . "\foo\foo.exe"
            , "bar.exe"       : PF86 . "bar\bar.exe" }

Note:

  1. The first version is not actually valid syntax in AHK as written. I'm not sure if it's fair to expect the formatter to fix this, but if it's not it would be helpful if the extension recognised and highlighted the error during editing
  2. lining up the colons vertically is nice, but perhaps a lot to ask

Actual formatted output snippet

; first version
AppPaths := {
    "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
    , "bar.exe" : PF86 . "bar\bar.exe"
}

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
, "bar.exe" : PF86 . "bar\bar.exe" }

Additional context

Note:

  1. The formatter ignores the first version, possibly because it is not valid syntax?
  2. However the second version is recognised and reformatted, but the result is ugly with the indenting being prgressively reduced on succesive lines
  3. This issue would seem to be related to Issue ID Formatter incorrectly indents object literals #184 (same title) but-
    a) Formatter incorrectly indents object literals #184 seems to relate to object literals defined as the return values of functions (true?)
    b) The example provided in Formatter incorrectly indents object literals #184 uses the "one true brace" style-
    function(){
        ...
    }

but this is a syntax error in AHK for object literals (which I was rather hoping the formatter woudl fix for me automatically, per my example). Object literals in AHK require the opening and closing braces to be on the same line as the immediately following/preceding expressions.

@incansvl incansvl added bug something isn't working formatter code formatter issues labels Sep 2, 2022
@kyklish
Copy link
Contributor

kyklish commented Sep 3, 2022

It's about broken formatting of continuation sections. I had it in my TODO list of feature fixes.

mark-wiemer added a commit that referenced this issue Nov 22, 2022
## 3.1.0 - 2022-11-21 🦃

Compiler:

-   New compiler options in settings: Choose base file, file icon, and "use [MPRESS](https://www.autohotkey.com/mpress/mpress_web.htm)"
-   Add "Compiler GUI" command in context menu to use the AHK GUI when compiling

Snippets:

-   Update snippets for AHK 1.1.35.00 and fix broken `InStr()` snippet ([#263](#263))

Grammar: Fix `#Requires` not being recognized ([#268](#268))

Editor: New AHK file icon (green square with white H)

Debugger: Minor debugger improvements

Formatter: Close the following bugs:

    -   Formatter incorrectly indents object literals ([#184](#184), [#222](#222))
    -   Nested one command code flow control ([#255](#255))

Miscellaneous:

-   Extension should start up faster
@mark-wiemer mark-wiemer mentioned this issue Nov 22, 2022
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
None yet
Development

Successfully merging a pull request may close this issue.

3 participants