From 4af5b827d44fdb108c24d3cb50b29c7255e734c4 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Mon, 14 Nov 2022 17:11:39 +0100 Subject: [PATCH 1/4] Don't crash when looking up XML docs for signature with apostrophe --- src/Compiler/SyntaxTree/XmlDoc.fs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) 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 From 599a4ef42504ff248bd38908a82375a134b8f266 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Tue, 15 Nov 2022 14:12:35 +0100 Subject: [PATCH 2/4] Find tests... --- src/Compiler/SyntaxTree/XmlDoc.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Compiler/SyntaxTree/XmlDoc.fs b/src/Compiler/SyntaxTree/XmlDoc.fs index ccab935a365..d108d95ca80 100644 --- a/src/Compiler/SyntaxTree/XmlDoc.fs +++ b/src/Compiler/SyntaxTree/XmlDoc.fs @@ -327,6 +327,9 @@ type XmlDocumentationInfo private (tryGetXmlDocument: unit -> XmlDocument option else tryGetXmlDocument () |> Option.bind (fun doc -> + + failwith "Is this tested?" + let name = if xmlDocSig.Contains "'" then $"\"{xmlDocSig}\"" From e36207a98305ed256ec74d2d7f4d9229f18c349c Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Mon, 21 Nov 2022 11:13:01 +0100 Subject: [PATCH 3/4] Revert "Find tests..." This reverts commit 599a4ef42504ff248bd38908a82375a134b8f266. --- src/Compiler/SyntaxTree/XmlDoc.fs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Compiler/SyntaxTree/XmlDoc.fs b/src/Compiler/SyntaxTree/XmlDoc.fs index d108d95ca80..ccab935a365 100644 --- a/src/Compiler/SyntaxTree/XmlDoc.fs +++ b/src/Compiler/SyntaxTree/XmlDoc.fs @@ -327,9 +327,6 @@ type XmlDocumentationInfo private (tryGetXmlDocument: unit -> XmlDocument option else tryGetXmlDocument () |> Option.bind (fun doc -> - - failwith "Is this tested?" - let name = if xmlDocSig.Contains "'" then $"\"{xmlDocSig}\"" From a43df8a1f0fe1b981c4e56052e3e243d3b3361a5 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Mon, 21 Nov 2022 13:50:23 +0100 Subject: [PATCH 4/4] Test --- src/Compiler/FSharp.Compiler.Service.fsproj | 1 + .../FSharp.Compiler.ComponentTests.fsproj | 3 +- .../Miscellaneous/XmlDoc.fs | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDoc.fs 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/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