vblang
vblang copied to clipboard
[Proposal] Allow comment lines in middle of a multi-line statement
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.
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 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
Note: this woudl likely be a very large impact to the IDE. Any proposal/work here will need to appropriately cost that in.
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())
)
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.
I like it :+1:
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
@CyrusNajmabadi Pretty listing should leave leading spaces before _
@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 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.
I consider this a higher priority as we want the core experience around these features (including formatting) to be at an acceptable level :-)
@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