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

Content of see cref tag gets dropped #7978

Closed
dotMorten opened this issue Apr 6, 2022 · 3 comments · Fixed by #7979
Closed

Content of see cref tag gets dropped #7978

dotMorten opened this issue Apr 6, 2022 · 3 comments · Fixed by #7979

Comments

@dotMorten
Copy link
Contributor

dotMorten commented Apr 6, 2022

Operating System: Windows

DocFX Version Used: 2.59

Template used: N/A

Steps to Reproduce:
1.
Create two classes with the same member name.

public class Class1
{
   public string Name { get ;set; }
}
public class Class2
{
   public string Name { get ;set; }
}

Reference these two in xml doc. We'll use the content of the tag to fully qualify the member, so we can tell the two Name properties apart in the generated documentation (otherwise it'll just say Name for both of them):

/// <summary>Some class</summary>
/// <remarks>See <see cref="Class1.Name">Class1.Name</see> and <see cref="Class2.Name">Class2.Name</see>.</remarks>
public class SomeClass
{
}
  1. Generate the API yaml
  2. Notice the generated yaml dropped the content of the reference, and the xref tag is empty:
remarks: "See <xref href=\"MyLib.Class1.Name\" data-throw-if-not-resolved=\"false\"></xref> and <xref href=\"MyLib.Class2.Name\" data-throw-if-not-resolved=\"false\"></xref>.\n"

Expected Behavior:
Generate xref with the content preserved:

remarks: "See <xref href=\"MyLib.Class1.Name\" data-throw-if-not-resolved=\"false\">Class1.Name</xref> and <xref href=\"MyLib.Class2.Name\" data-throw-if-not-resolved=\"false\">Class2.Name</xref>.\n"

Actual Behavior:
Content of the cref is lost.

Note:
Putting the string text inside the xref might not be the correct way. This doc seems to indicate it should be done a different way, but there doesn't seem to be a generic way to create arbitrary text for it (ie just fullname, name etc).

@dotMorten
Copy link
Contributor Author

Here's a unit test that can be added to TripleSlashParserUnitTest.cs:
Note that the syntax "?text=..." used in the asserts might or might not be the correct syntax.

        [Trait("Related", "TripleSlashComments")]
        [Fact]
        public void SeeAltText()
        {
            string inputFolder = Path.GetRandomFileName();
            Directory.CreateDirectory(inputFolder);
            string input = @"
<member name='T:TestClass1.Partial1'>
    <summary>
        Class summary <see cref='T:System.AccessViolationException'>Exception type</see>
    </summary>
    <remarks>
    See <see cref='T:System.Int'>Integer</see>.
    </remarks>
    <returns>Returns an <see cref='T:System.AccessViolationException'>Exception</see>.</returns>

        <param name='input'>This is an <see cref='T:System.AccessViolationException'>Exception</see>.</param>
</member>";
            var context = new TripleSlashCommentParserContext
            {
                AddReferenceDelegate = null,
                PreserveRawInlineComments = false,
                Source = new SourceDetail
                {
                    Path = Path.Combine(inputFolder, "Source.cs"),
                }
            };

            var commentModel = TripleSlashCommentModel.CreateModel(input, SyntaxLanguage.CSharp, context);
            Assert.True(commentModel.InheritDoc == null, nameof(commentModel.InheritDoc));

            var summary = commentModel.Summary;
            Assert.Equal("\nClass summary <xref href=\"System.AccessViolationException?text=Exception type\" data-throw-if-not-resolved=\"false\"></xref>\n", summary);

            var returns = commentModel.Returns;
            Assert.Equal("Returns an <xref href=\"System.AccessViolationException?text=Exception\" data-throw-if-not-resolved=\"false\"></xref>.", returns);

            var paramInput = commentModel.Parameters["input"];
            Assert.Equal("This is an <xref href=\"System.AccessViolationException?text=Exception\" data-throw-if-not-resolved=\"false\"></xref>.", paramInput);

            var remarks = commentModel.Remarks;
            Assert.Equal("\nSee <xref href=\"System.Int?text=Integer\" data-throw-if-not-resolved=\"false\"></xref>.\n", remarks);
        }

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Apr 7, 2022

In Sandcastle, one would use <see cref="Class1.Name" qualifyHint="true"/> to generate Class1.Name as the content in C#, but Class1::Name in C++/CLI. I don't remember whether DocFX supports qualifyHint. Perhaps <a href="xref:Class1.Name?displayProperty=nameWithType"/> is the nearest equivalent, but if I use that in XML doc comments, then I lose the cref resolution and validation of the C# compiler.

@dotMorten
Copy link
Contributor Author

But sandcastle would also support content to see tag. It’s quite useful for more than just qualifying classes (this was just one example) but could be to solve grammar or link to more than a member name but a sentence.

superyyrrzz pushed a commit that referenced this issue Apr 8, 2022
* Adds support for custom text in cref references

#7978

* Remove extra line feed

* Remove trailing space

* Remove preserving formatting, since it'll get escaped by the html formatter
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

Successfully merging a pull request may close this issue.

2 participants