microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.32k stars 28.9k forks source link

Support multiple lineComments in a language config to allow "Remove Line Comment" to work more reliably #64659

Open DanTup opened 5 years ago

DanTup commented 5 years ago

In some languages, there may be multiple single-line comment markers, like // and ///. However the language configs can only provide a single lineComment setting which is used by the Remove Line Comment command. This makes it hard to uncomment. For example, take this C# code:

/// <summary>
/// The GetZero method.
/// </summary>
/// <example> 
/// This sample shows how to call the <see cref="GetZero"/> method.
/// <code>
/// class TestClass 
/// {
///     static int Main() 
///     {
///         return GetZero();
///     }
/// }
/// </code>
/// </example>
public static int GetZero()
{
    return 0;
}

If you copy/pasted the code from the <example> section and tried to remove the comment using Remove Line Comment you end up with this:

/ class TestClass 
/ {
/     static int Main() 
/     {
/         return GetZero();
/     }
/ }

We have a similar issue in Dart - we use both // and ///. There are things like DocFX that encourage triple-slashes too.

Although Add Line Comment would only be able to use the first, it'd be nice if in the language declaration we could provide multiple lineComments so that removing could handle this case better (it can use the longest comment first when trying to remove the markers):

{
"comments": {
    "lineComment": [ "//", "///" ],
    "blockComment": [ "/*", "*/" ]
},
}

Or:

{
"comments": {
    "lineComment": "//",
    "additionalLineComments": [ "///" ],
    "blockComment": [ "/*", "*/" ]
},
}
DanTup commented 5 years ago

Although Add Line Comment would only be able to use the first

Actually, if there are multiple line markers defined, this could cycle between them - that way the user can easily comment using whichever starting marker they want too!

inoas commented 2 years ago

PHP < 8.0 requires this # and // are both valid. Gleam requires this as it has 3 per-line comment tags //, ///, ////.

inoas commented 2 years ago

Rust supports // and ///

https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments

tsvi commented 1 year ago

Specman supports // and --

jozefizso commented 1 year ago

The VBA language supports line comments only with two styles: ' and REM

tsvi commented 1 year ago

Also Specman has a weird thing where anything that's outside of a specific type of brackets is considered a comment. The following is a classic way of writing Specman:

Some lengthy comment explaining the contents of the file.

<'
Code goes here
'>