rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Indent aligns commented Compiler Directives and all lines thereafter #6127

Closed glhey closed 1 year ago

glhey commented 1 year ago

Version 2.5.2.5906 OS: Microsoft Windows NT 10.0.19045.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.16529.20154 Host Executable: MSACCESS.EXE

INDENT recognises Compiler Directives even if they're commented out, then removes indent for that last recognised compiler directive and for ALL lines that follow

To reproduce, use this snippet in any module:

    '    #If COMPILER_EARLY_BIND Then
    '        Dim xl As Excel.Application
    '        Dim wb As Excel.workbook
    '    #Else        ' late binding
             Dim xl As Object
             Dim wb As Object
    '     #End If
    ' ---------------------------------------------------------
    ' TODO: Confirm if latebind will kill all Excel processes unitentionally on closing

Unexpected result:

    '    # If COMPILER_EARLY_BIND Then
    '        Dim xl As Excel.Application
    '        Dim wb As Excel.workbook
    '
    '    # Else        ' late binding

    Dim xl As Object
    Dim wb As Object

' #End If ' --------------------------------------------------------- ' TODO: Confirm if latebind will kill all Excel processes unitentionally on closing (Greg Long) ' To mitigate, place a space between # and directive like this

    '# End if
Vogel612 commented 1 year ago

The reason for this is most likely that the indenter is not working off of the parse-tree but off the raw string representation. This means it's using heuristics to determine indentation.

So this is basically a duplicate of #5905 although the grammar feature triggering the indentation is a different one.