vblang icon indicating copy to clipboard operation
vblang copied to clipboard

[Proposal] Allow comment lines in middle of a multi-line statement

Open VBAndCs opened this issue 5 years ago • 12 comments

Today, I wrote this in a VB.NET ASP.NET Core app:

services.AddControllersWithViews(). 
    ' Enable Vazor
    AddRazorRuntimeCompilation(
        Sub(options) options.FileProviders.Add(
             New Vazor.VazorViewProvider())
    )

but I got syntax error, because the comment in the second line! The only allowed syntax today is:

services.AddControllersWithViews(). ' Enable Vazor
    AddRazorRuntimeCompilation(
        Sub(options) options.FileProviders.Add(
             New Vazor.VazorViewProvider())
    )

I propose to accept comment line/lines in middle of a multi-line statement. I think it t shouldn't be that hard.

Note: This proposals is not for VB.NET team, but for the community that will continue to evolve the language. I started today to trace VB compiler code by debugging its tests. I hope I find my way through the source so I can implement my suggestions myself.

VBAndCs avatar Mar 19 '20 17:03 VBAndCs

My thoughts about that is, maybe hard to implement my personal opinion, Has currently comments are allowed after implicit / explicit line-continuations, we have to remember what construct we were parsing before and continue afterwards. This could clash if the two line before and after can me interpreted as two legally separate statements.

AdamSpeight2008 avatar Mar 19 '20 18:03 AdamSpeight2008

@AdamSpeight2008 Implicit line continuation rules already ensure the previous line is incomplete or the next line can't be a start of a statement, so it is safe to do it. @tverweij has it done in Mercury https://github.com/dotnet/vblang/issues/491#issuecomment-601317369

VBAndCs avatar Mar 19 '20 19:03 VBAndCs

Note: this woudl likely be a very large impact to the IDE. Any proposal/work here will need to appropriately cost that in.

CyrusNajmabadi avatar Dec 21 '20 08:12 CyrusNajmabadi

You can do this now in VB16, the formatting is just not pretty.

services.AddControllersWithViews(). 
  _ ' Enable Vazor
    AddRazorRuntimeCompilation(
        Sub(options) options.FileProviders.Add(
             New Vazor.VazorViewProvider())
    )

paul1956 avatar Dec 22 '20 03:12 paul1956

You can do this now in VB16, the formatting is just not pretty.

services.AddControllersWithViews(). 
  _ ' Enable Vazor
    AddRazorRuntimeCompilation(
        Sub(options) options.FileProviders.Add(
             New Vazor.VazorViewProvider())
    )

Thanks for pointing that out, I agree it's not pretty, but it's still less ugly than the alternatives.

Call me old fashioned, but I'm not mad about 'fluent' construction of objects, but some libraries don't offer an alternative, and this could come in handy for explaining in the middle of a fluent construction.

pricerc avatar Dec 22 '20 04:12 pricerc

I like it :+1:

VBAndCs avatar Dec 22 '20 09:12 VBAndCs

The problem is the formatter always puts the _ in position 2 on an comment only line.

    services.AddControllersWithViews(). _ ' Enable Vazor
 _                                                               ' You can do this, any number of spaces are allowed after the _ and 
 _                                                               '  before the ' but its manual. GitHub doesn't understand it but the 3 comment lines up
 _ ' and new lines align back at the beginning
        AddRazorRuntimeCompilation(
            Sub(options) options.FileProviders.Add( _ ' This is also allowed
                 New Vazor.VazorViewProvider())            ' and this
        )

The formatter just doesn't understand _ ' Comment

paul1956 avatar Dec 22 '20 10:12 paul1956

@CyrusNajmabadi Pretty listing should leave leading spaces before _

VBAndCs avatar Dec 22 '20 11:12 VBAndCs

@VBAndCs prs welcome. In general, we would ask that any of these language features come with the respective ide work for them as well to be actually complete.

CyrusNajmabadi avatar Dec 22 '20 18:12 CyrusNajmabadi

@CyrusNajmabadi when I did I the formatter was being updated and was to include this but it never happened. Supporting this was too low a priority since no one was using it yet to delay other formatting improvements. Its one of the reason other VB features don't happen that were originally planned. VB support is not a gate for a release.

paul1956 avatar Dec 23 '20 00:12 paul1956

I consider this a higher priority as we want the core experience around these features (including formatting) to be at an acceptable level :-)

CyrusNajmabadi avatar Dec 23 '20 03:12 CyrusNajmabadi

@CyrusNajmabadi thanks, There is a design question on how to handle the spaces best. Below are just a few possible options. The parser will accept any of them.

                       YourCode _ ' Comment 
 _ '                   Comment
                       _ ' Comment
 _                     ' Comment
 _ '                              Comment
                                  _ ' Comment
 _                                ' Comment
 _ '                                 Comment
                                    _ ' Comment
 _                                  ' Comment

paul1956 avatar Dec 23 '20 06:12 paul1956