mike-lischke / vscode-antlr4

ANTLR4 language support for Visual Studio Code
http://www.soft-gems.net
MIT License
429 stars 60 forks source link

Bug: alignColons formatting setting affects semicolon on first line #134

Closed xpe closed 11 months ago

xpe commented 3 years ago

The alignColons setting, as I understand it, should only impact colons (:). However, I've noticed that it changes the formatting of semicolons (;) on the first line in both my parser grammar and lexer grammar.

For example, here is the result of formatting:

lexer grammar FooLexer
    ;

Just in case there might be some kind of interactions between settings, here are my settings:

    "antlr4.format": {
        "alignTrailingComments": true,
        "allowShortBlocksOnASingleLine": true,
        "breakBeforeBraces": false,
        "columnLimit": 78,
        "continuationIndentWidth": 4,
        "indentWidth": 4,
        "keepEmptyLinesAtTheStartOfBlocks": false,
        "maxEmptyLinesToKeep": 1,
        "reflowComments": false,
        "spaceBeforeAssignmentOperators": true,
        "tabWidth": 4,
        "useTab": false,
        "alignColons": "hanging",
        "singleLineOverrulesHangingColon": true,
        "allowShortRulesOnASingleLine": true,
        "alignSemicolons": "hanging",
        "breakBeforeParens": false,
        "ruleInternalsOnSingleLine": false,
        "minEmptyLines": 1,
        "groupedAlignments": true,
        "alignFirstTokens": true,
        "alignLexerCommands": false,
        "alignActions": false,
        "alignLabels": true,
        "alignTrailers": false
    },
mike-lischke commented 3 years ago

You have set "alignSemicolons" to hanging as well. This is probably why you got this result.

xpe commented 3 years ago

You have set "alignSemicolons" to hanging as well. This is probably why you got this result.

Do you agree with these statements:

xpe commented 3 years ago

My goal is setup the extension to do ANTLR formatting along the lines of common examples provided in TDAR and many examples in the ANTLR4 grammars repo. This means:

I don't think this is currently possible given the current setting options, which is why I filed this as a bug.

mike-lischke commented 3 years ago

Do you agree with these statements:

* `alignSemicolons` should _only_ apply to rule definitions.

* `alignSemicolons` should _not_ apply to the first line of a grammar file (e.g. `grammar`, `lexer grammar`, or `parser grammar`).

I haven't thought about other occurences than rules, so I cannot answer with yes currently. However, I have not seen output where the semicolon from the introducer line is placed on the next line and I have tests with all 3 semicolon settings. But maybe I just missed that.

mike-lischke commented 3 years ago

My goal is setup the extension to do ANTLR formatting along the lines of common examples provided in TDAR and many examples in the ANTLR4 grammars repo. This means:

* in rules, align `:`, `|`, and `;`

* use semicolons normally in non-rules (such as `lexer grammar FooGrammar;`)

I agree. The setting should not affect non-rules.

I don't think this is currently possible given the current setting options, which is why I filed this as a bug.

If that's the case then it should be fixed. Interesting here is that I never got a bug report for this issue, which either means people don't care about it or they never use hanging semicolons. I certainly do not.