dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.06k stars 4.04k forks source link

Consider having constructors automatically inherit documentation from the containing type #73579

Open sharwell opened 5 months ago

sharwell commented 5 months ago

Background and Motivation

AB#2063157 https://developercommunity.visualstudio.com/t/Documentation-Comments-in-F-library-not/10661462

/// <summary>
/// Represents a list item.
/// </summary>
class ListItem
{
}

class Usage
{
  void Method()
  {
    var listItem = new ListItem();
    //             ^^^ ^^^^^^^^^
  }
}

In this example, there is no documentation presented when covering over the tokens marked with ^. This occurs because the constructor for ListItem does not have any documentation comments, even though the containing type does.

Proposed Solution

Treat constructors with missing documentation comments as automatically inheriting documentation from their containing type.

Alternative Designs

Risks

Could lead to duplication of complicated type documentation across every constructor for that type during documentation generation.

th3oth3rjak3 commented 5 months ago

For additional context for troubleshooters, the original implementation in F# looks like below.

/// <summary>
/// Represents a list item.
/// </summary>
type ListItem = {
    /// The unique ID of the item.
    Id: int
    /// The name of the item.
    Name: string
    /// True when the item is completed, otherwise false.
    IsComplete: bool
}