diff --git a/src/Compiler/FSharp.Compiler.Service.fsproj b/src/Compiler/FSharp.Compiler.Service.fsproj index eedb771f0f3..c55f834763d 100644 --- a/src/Compiler/FSharp.Compiler.Service.fsproj +++ b/src/Compiler/FSharp.Compiler.Service.fsproj @@ -71,6 +71,7 @@ + diff --git a/src/Compiler/SyntaxTree/XmlDoc.fs b/src/Compiler/SyntaxTree/XmlDoc.fs index 72c657d2911..ccab935a365 100644 --- a/src/Compiler/SyntaxTree/XmlDoc.fs +++ b/src/Compiler/SyntaxTree/XmlDoc.fs @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 85239d5a3c0..706e44266ca 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -202,6 +202,7 @@ + @@ -211,7 +212,7 @@ - %(RelativeDir)\TestSource\%(Filename)%(Extension) + %(RelativeDir)\TestSource\%(Filename)%(Extension) diff --git a/tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDoc.fs b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDoc.fs new file mode 100644 index 00000000000..1fac6e2509c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDoc.fs @@ -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" + +let xmlFileContents signature = $""" + + + FSharp.Core + + + + The type of immutable singly-linked lists. + + + {memberDoc} + + + +""" + +[] +[] +[] +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