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 299 forks source link

Indentation failed on simple code #6191

Open 1504168 opened 9 months ago

1504168 commented 9 months ago

Rubberduck version information The info below can be copy-paste-completed from the first lines of Rubberduck's log or the About box:

Version 2.5.9.6289 OS: Microsoft Windows NT 10.0.19045.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.17231.20008 Host Executable: EXCEL.EXE

Description Indenting is failing on the below line of code.

Public Sub SubName()

    '@PossibleError: Type mismatch(13) if given input is not an array
    Dim X As Long
    X = X + 1

End Sub

It failed if I got rid of the @ from the comment as well. It successfully indent if I don't put any space after @PossibleError from the comment line.

Expected behavior Expected indentation:

Public Sub SubName()

    '@PossibleError: Type mismatch(13) if given input is not an array
    Dim X As Long
    X = X + 1

End Sub
retailcoder commented 9 months ago

Repro'd online; removing the : colon formats the resulting code as expected - the indenter is probably getting confused with line labels... if I recall there's some regex-matching involved, in which case the fix for this is probably just a few characters in a regex pattern. The plan for RD3 is to leverage parse trees for code formatting (we've talked about rewriting the indenter to do this, for years!), so this kind of problems pretty much solve themselves, because our parser has no problem telling a comment from a line label.

1504168 commented 8 months ago

Thank you.