Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<InternalsVisibleTo Include="fsiArm64" />
<InternalsVisibleTo Include="VisualFSharp.Salsa" />
<InternalsVisibleTo Include="VisualFSharp.UnitTests" />
<InternalsVisibleTo Include="FSharp.Compiler.ComponentTests" />
<InternalsVisibleTo Include="FSharp.Compiler.UnitTests" />
<InternalsVisibleTo Include="FSharp.Compiler.Service.Tests" />
<InternalsVisibleTo Include="HostedCompilerServer" />
Expand Down
24 changes: 17 additions & 7 deletions src/Compiler/SyntaxTree/XmlDoc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,23 @@ type XmlDocumentationInfo private (tryGetXmlDocument: unit -> XmlDocument option
keepMax = cacheMaxSize
)

let tryGetSummaryNode xmlDocSig =
tryGetXmlDocument ()
|> Option.bind (fun doc ->
match doc.SelectSingleNode(sprintf "doc/members/member[@name='%s']" xmlDocSig) with
| null -> None
| node when node.HasChildNodes -> Some node
| _ -> None)
let tryGetSummaryNode (xmlDocSig: string) =
if xmlDocSig.Contains "'" && xmlDocSig.Contains "\"" then
// No easy way to find this signature with XPath
None
else
tryGetXmlDocument ()
|> Option.bind (fun doc ->
let name =
if xmlDocSig.Contains "'" then
$"\"{xmlDocSig}\""
else
$"'{xmlDocSig}'"

match doc.SelectSingleNode $"doc/members/member[@name={name}]" with
| null -> None
| node when node.HasChildNodes -> Some node
| _ -> None)

member _.TryGetXmlDocBySig(xmlDocSig: string) =
tryGetSummaryNode xmlDocSig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<Compile Include="Globalization\GlobalizationTestCases.fs" />
<Compile Include="OCamlCompat\OCamlCompat.fs" />
<Compile Include="Miscellaneous\ListLiterals.fs" />
<Compile Include="Miscellaneous\XmlDoc.fs" />
<Compile Include="Signatures\TestHelpers.fs" />
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />
<Compile Include="Signatures\RecordTests.fs" />
Expand All @@ -211,7 +212,7 @@
<Compile Include="FSharpChecker\CommonWorkflows.fs" />
<Compile Include="FSharpChecker\SymbolUse.fs" />
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
</None>
</ItemGroup>

Expand Down
47 changes: 47 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDoc.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

module FSharp.Compiler.ComponentTests.Miscellaneous.XmlDoc

open System.IO
open Xunit
open FSharp.Compiler.Xml
open TestFramework


let memberDoc = "<summary>Summary</summary>"

let xmlFileContents signature = $"""<?xml version="1.0" encoding="utf-8"?>
<doc>
<assembly>
<name>FSharp.Core</name>
</assembly>
<members>
<member name="T:Microsoft.FSharp.Collections.list`1">
<summary>The type of immutable singly-linked lists. </summary>
</member>
<member name="{signature}">
{memberDoc}
</member>
</members>
</doc>
"""

[<Theory>]
[<InlineData("P:Microsoft.FSharp.Collections.FSharpList`1.Length")>]
[<InlineData("P:Microsoft.FSharp.Collections.FSharpList`1.Length'")>]
let ``Can extract XML docs from a file for a signature`` signature =
let xmlFileName = tryCreateTemporaryFileName () + ".xml"

try
File.WriteAllText(xmlFileName, xmlFileContents signature)

let docInfo =
XmlDocumentationInfo.TryCreateFromFile(xmlFileName)
|> Option.defaultWith (fun () -> failwith "Couldn't create XmlDoc from file")

match docInfo.TryGetXmlDocBySig(signature) with
| None -> failwith "Got no doc"
| Some doc -> Assert.Equal(memberDoc, doc.UnprocessedLines |> String.concat "\n")

finally
File.Delete xmlFileName