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.91k stars 300 forks source link

Indenter fails on line-continued, multiline Dim statements #2133

Closed comintern closed 7 years ago

comintern commented 8 years ago

This code (avert your eyes if you're faint of heart...)...

Public Sub FooBar()
    Dim foo As String, bar As String _
    , baz As String _
    , somethingElse As String

End Sub

...indents to...

Public Sub FooBar()
    Dim foo As String, bar As String _
                      , baz As String _
                       , somethingElse As String

End Sub
comintern commented 8 years ago

With Align Dims turned on:

Before:

Private Sub Test()
Dim foo As String, bar As String _
, baz As String _
, somethingElse As String
Dim x As Integer
End Sub

After:

Private Sub Test()
Dim foo            As String, bar As String _
    , baz As String _
    , somethingElse As String
    Dim x          As Integer
End Sub
retailcoder commented 7 years ago

Is that also a bug in the original SmartIndenter?

comintern commented 7 years ago

More or less. I'm actually surprised it didn't crash the SmartIndenter. It outputs this for the first case:

Public Sub Test()
    Dim foo As Boolean, bar As String _
                        , baz As String _
                          , somethingElse As String
    Dim x As Integer

    If Not foo Then
        x = 1
    End If
End Sub

And this in the second case:

Public Sub Test()
    Dim foo As Boolean, bar As String _
                        , baz As String _
                          , somethingElse As String
    Dim x      As Integer

    If Not foo Then
        x = 1
    End If
End Sub

It's a bug in the function aligner - I'll probably just add Dim block tracking and bypass it with a special case.