fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
345 stars 21 forks source link

Support multiline XML documentation comments #783

Closed Happypig375 closed 2 years ago

Happypig375 commented 5 years ago

Support multi-line XML documentation comments

I propose we support multi-line XML documentation comments

The existing way of approaching this problem in F# is using single-line XML documentation comments.

C

Single-line

/// <summary>Documentation</summary>
class C { }

Multi-line

/** <summary>Documentation</summary> */ class C { }

F

Single-line

/// Documentation
type C = A | B

Multi-line (Does not work currently, proposed to allow)

(** Documentation *) type C = A | B

Variations of usage:

(** Documentation *) type A = int * string
(** 1st line
2nd line *) type B = B of int
(**
2431258
9347356
7567527
3496303
5534504
2018472
*)
type Numbers = class end
(**
 * blah
 * bleh
 * blih
 * bloh
 * bluh
 * blyh
*)
type ``C#-style`` = struct end

Compare:

/// Documentation
type A = int * string
/// 1st line
/// 2nd line
type B = B of int
/// 2431258
/// 9347356
/// 7567527
/// 3496303
/// 5534504
/// 2018472
type Numbers = class end
/// blah
/// bleh
/// blih
/// bloh
/// bluh
/// blyh
type ``C#-style`` = struct end

Pros and Cons

The advantages of making this adjustment to F# are

  1. Even more concise documentation
  2. More usage of wasted horizontal space (for inline XML comments)
  3. Informative text can be pasted in without needing to insert /// for each line
  4. Documentation can be easily copied away
  5. Parity with C#

The disadvantages of making this adjustment to F# are

  1. Potential loss of uniformity of XML comments (/// usually is its own line)
  2. New syntax to learn

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S-M

Related suggestions: No

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

Happypig375 commented 5 years ago

Note: As a hack, the XML comment can technically be inlined by placing in end of previous line.

type A = class end /// Docs for B
type B = struct end /// Docs for I
type I = interface end
abelbraaksma commented 5 years ago

I think this would be a worthwhile addition. Though it's a matter of taste whether this is good coding practice (main argument against it, in the C# world, is that it disallows commenting out large chunks of code during development, which is probably why most tooling in C# auto inserts the single line comments), I think we should allow it.

As an aside, I think that the editor should insert the triple slash automatically upon a new line, just like with C#. This would make writing such documentation easier in the current situation.

cartermp commented 5 years ago

F# already supports multi-line XML doc comments:

/// <summary>
/// Documentation
/// </summary>
type C() = class end

It's worth calling out that the Java-ism that C# apparently supports automatically inserts a * on new lines though, so there's still clutter. Extending the OCAML-style comments in F# to also support XML doc tags seems generally fine, though I don't imagine it'll be a high priority.

abelbraaksma commented 5 years ago

F# already supports multi-line XML doc comments

I believe the OP meant that you wouldn't need to use single line comments to get multi line xml comments. But I could be wrong ;)

dsyme commented 2 years ago

Closing per reply https://github.com/fsharp/fslang-suggestions/issues/783#issuecomment-533809079

Happypig375 commented 2 years ago

Extending the OCAML-style comments in F# to also support XML doc tags seems generally fine, though I don't imagine it'll be a high priority.

dsyme commented 2 years ago

Ha yes, no idea why I wrote that. Anyway no intention to support this, there's no need to have two ways to do xml docs.