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

Fix: Indent after oneCommandCode on comment, block comment, empty line. Formatting inside block comment. #164

Merged

Conversation

kyklish
Copy link
Contributor

@kyklish kyklish commented Jul 17, 2022

Closes #59.
Closes #185.

Changes proposed in this pull request:

  • more universal search of begin /* and end */ block comment pattern
  • extract save indented line code to buildIndentedLine(...) function
  • don't reset oneCommandCode if current line is empty, single line comment or block comment
  • save indent values on block comment enter and restore them on block comment exit
  • add directives for formatter ;@AHK++FormatBlockCommentOn and ;@AHK++FormatBlockCommentOff to format code inside block comments
  • add directives to snippets

In:

foo () {
;@AHK++FormatBlockCommentOn
/*
typedef struct TEST {
DWORD cbSize;          0
} CMINVOKECOMMANDINFOEX;
*/
/*
MsgBox, This line is commented out (disabled).
MsgBox, Common mistake: */ this does not end the comment.
MsgBox, This line is commented out. 
*/
/*
bar() {
Loop, 4 {
MsgBox % A_Index
}
if (true) {
SoundBeep
} else {
MsgBox
}
}
if (true)
ToolTip
MsgBox
*/
;@AHK++FormatBlockCommentOff
MsgBox
/*
    All text in this block comment must save original indent
bar() {
        Loop, 4 {
                MsgBox % A_Index
        }
}
*/
}

Out:

foo () {
    ;@AHK++FormatBlockCommentOn
    /*
    typedef struct TEST {
        DWORD cbSize;          0
    } CMINVOKECOMMANDINFOEX;
    */
    /*
    MsgBox, This line is commented out (disabled).
    MsgBox, Common mistake: */ this does not end the comment.
    MsgBox, This line is commented out. 
    */
    /*
    bar() {
        Loop, 4 {
            MsgBox % A_Index
        }
        if (true) {
            SoundBeep
        } else {
            MsgBox
        }
    }
    if (true)
        ToolTip
    MsgBox
    */
    ;@AHK++FormatBlockCommentOff
    MsgBox
    /*
        All text in this block comment must save original indent
    bar() {
            Loop, 4 {
                    MsgBox % A_Index
            }
    }
    */
}

Notifying @mark-wiemer

@kyklish kyklish force-pushed the fix-formatter-bug-onecommand-complex branch from 3ed893f to ddd1445 Compare July 17, 2022 13:24
Copy link
Member

@mark-wiemer mark-wiemer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much, this is great code! It'd be awesome if we could update the tests in this PR as well, please let me know if you have any questions.

src/providers/formattingProvider.ts Outdated Show resolved Hide resolved
src/common/codeUtil.ts Outdated Show resolved Hide resolved
src/providers/formattingProvider.ts Outdated Show resolved Hide resolved
@mark-wiemer mark-wiemer self-assigned this Jul 18, 2022
@kyklish kyklish marked this pull request as draft July 18, 2022 15:52
…xpression)"

This reverts commit e4ae591.

Fixed in another Pull Request
@kyklish kyklish changed the title Fix #59 formatter bug Fix #59 #185 formatter bug Jul 21, 2022
@kyklish kyklish marked this pull request as ready for review July 21, 2022 17:38
@kyklish kyklish requested a review from mark-wiemer July 21, 2022 17:38
@kyklish
Copy link
Contributor Author

kyklish commented Jul 21, 2022

Who must press Resolve conversation on requested changes, when I commit requested changes?

@kyklish kyklish marked this pull request as draft July 25, 2022 17:45
@kyklish kyklish changed the title Fix #59 #185 formatter bug Fix: Indent after oneCommandCode on comment, block comment, empty line. Formatting inside block comment. Jul 25, 2022
@kyklish
Copy link
Contributor Author

kyklish commented Jul 26, 2022

TODO
Will extract block comment formatting to separate PR and add formatter directive:
; @AHK++-FormatBlockComment [add it to snippets]

Feature directives for enable/disable trim spaces between words:
; @AHK++-TrimOn
; @AHK++-TrimOff

@kyklish kyklish marked this pull request as ready for review July 31, 2022 15:36
src/providers/formattingProvider.ts Show resolved Hide resolved
src/providers/formattingProvider.ts Outdated Show resolved Hide resolved
src/providers/formattingProvider.utils.ts Outdated Show resolved Hide resolved
src/test/suite/format/samples/ahk-explorer.out.ahk Outdated Show resolved Hide resolved
src/test/suite/format/samples/ahk-explorer.out.ahk Outdated Show resolved Hide resolved
kyklish and others added 5 commits August 14, 2022 10:24
Co-authored-by: Mark Wiemer <7833360+mark-wiemer@users.noreply.github.com>
…ommand-complex

# Conflicts:
#	src/common/codeUtil.ts
#	src/test/suite/format/format.test.ts
src/providers/formattingProvider.utils.ts Outdated Show resolved Hide resolved
src/test/suite/format/samples/ahk-explorer.out.ahk Outdated Show resolved Hide resolved
@kyklish
Copy link
Contributor Author

kyklish commented Aug 15, 2022

Done.

@mark-wiemer mark-wiemer merged commit 6a53178 into mark-wiemer-org:main Aug 20, 2022
@kyklish kyklish deleted the fix-formatter-bug-onecommand-complex branch August 20, 2022 15:59
@mark-wiemer mark-wiemer mentioned this pull request Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants