Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VBAndCs opened this issue Mar 19, 2020 · 12 comments
Open

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

VBAndCs opened this issue Mar 19, 2020 · 12 comments

Comments

@VBAndCs
Copy link

VBAndCs commented Mar 19, 2020

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.

@AdamSpeight2008
Copy link
Contributor

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.

@VBAndCs
Copy link
Author

VBAndCs commented Mar 19, 2020

@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 #491 (comment)

@CyrusNajmabadi
Copy link
Member

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

@paul1956
Copy link

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())
    )

@pricerc
Copy link

pricerc commented Dec 22, 2020

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.

@VBAndCs
Copy link
Author

VBAndCs commented Dec 22, 2020

I like it 👍

@paul1956
Copy link

paul1956 commented Dec 22, 2020

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

@VBAndCs
Copy link
Author

VBAndCs commented Dec 22, 2020

@CyrusNajmabadi
Pretty listing should leave leading spaces before _

@CyrusNajmabadi
Copy link
Member

@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.

@paul1956
Copy link

@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.

@CyrusNajmabadi
Copy link
Member

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

@paul1956
Copy link

paul1956 commented Dec 23, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants