Skip to content

Commit f85f02d

Browse files
committed
improve handling of nested xml
1 parent 3c70be2 commit f85f02d

File tree

4 files changed

+93
-23
lines changed

4 files changed

+93
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.1.1] - 2023-12-25
4+
5+
### Fixed
6+
7+
* Improve handling of nested xml.
8+
39
## [0.1.0] - 2023-12-24
410

511
### Added

src/Fsih.Tests/Tests.fs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,37 @@ let ``full info is as expected for Seq.splitInto`` () =
8585

8686
| Some _ -> Assert.False(true, sprintf "unexpected help")
8787
| None -> Assert.False(true, sprintf "no docs for Seq.splitInto")
88+
89+
[<Fact>]
90+
let ``returns is as expected for HashIdentity.FromFunctions`` () =
91+
let doc = tryGetDocumentation <@ HashIdentity.FromFunctions @>
92+
93+
match doc with
94+
| Some { Returns = Some returns } ->
95+
Assert.Equal(
96+
"An object implementing System.Collections.Generic.IEqualityComparer using the given functions.",
97+
returns
98+
)
99+
| Some _ -> Assert.False(true, sprintf "unexpected help")
100+
| None -> Assert.False(true, sprintf "no docs for Seq.splitInto")
101+
102+
[<Fact>]
103+
let ``remarks is as expected for List.reduce`` () =
104+
let doc = tryGetDocumentation <@ List.reduce @>
105+
106+
match doc with
107+
| Some { Remarks = Some remarks } -> Assert.Equal("Raises System.ArgumentException if list is empty", remarks)
108+
| Some _ -> Assert.False(true, sprintf "unexpected help")
109+
| None -> Assert.False(true, sprintf "no docs for Seq.splitInto")
110+
111+
[<Fact>]
112+
let ``summary is as expected for Array.sortDescending`` () =
113+
let doc = tryGetDocumentation <@ Array.sortDescending @>
114+
115+
match doc with
116+
| Some { Summary = summary } ->
117+
Assert.Equal(
118+
"Sorts the elements of an array, in descending order, returning a new array. Elements are compared using Microsoft.FSharp.Core.Operators.compare.",
119+
summary
120+
)
121+
| None -> Assert.False(true, sprintf "no docs for Seq.splitInto")

src/Fsih/Parser.fs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ type Help =
5858

5959
let cleanupXmlContent (s: string) = s.Replace("\n ", "\n").Trim() // some stray whitespace from the XML
6060

61+
// remove any leading `X:` and trailing `N
62+
let trimDotNet (s: string) =
63+
let s = if s.Length > 2 && s[1] = ':' then s.Substring(2) else s
64+
let idx = s.IndexOf('`')
65+
let s = if idx > 0 then s.Substring(0, idx) else s
66+
s
67+
6168
let xmlDocCache = Collections.Generic.Dictionary<string, XmlDocument>()
6269

6370
let getXmlDocument xmlPath =
71+
#if DEBUG
72+
printfn $"xml file: %s{xmlPath}"
73+
#endif
6474
match xmlDocCache.TryGetValue(xmlPath) with
6575
| true, value -> value
6676
| _ ->
@@ -70,6 +80,22 @@ let getXmlDocument xmlPath =
7080
xmlDocCache.Add(xmlPath, xmlDocument)
7181
xmlDocument
7282

83+
let getTexts (node: Xml.XmlNode) =
84+
seq {
85+
for child in node.ChildNodes do
86+
if child.Name = "#text" then
87+
yield child.Value
88+
89+
if child.Name = "c" then
90+
yield child.InnerText
91+
92+
if child.Name = "see" then
93+
let cref = child.Attributes.GetNamedItem("cref")
94+
95+
if not (isNull cref) then
96+
yield cref.Value |> trimDotNet
97+
}
98+
|> String.concat ""
7399

74100
let helpText (xmlPath: string) (assembly: string) (modName: string) (implName: string) (sourceName: string) =
75101
let sourceName = sourceName.Replace('.', '#') // for .ctor
@@ -103,13 +129,13 @@ let helpText (xmlPath: string) (assembly: string) (modName: string) (implName: s
103129
let summary =
104130
n.SelectSingleNode("summary")
105131
|> Option.ofObj
106-
|> Option.map _.InnerText
132+
|> Option.map getTexts
107133
|> Option.map cleanupXmlContent
108134

109135
let remarks =
110136
n.SelectSingleNode("remarks")
111137
|> Option.ofObj
112-
|> Option.map _.InnerText
138+
|> Option.map getTexts
113139
|> Option.map cleanupXmlContent
114140

115141
let parameters =
@@ -119,7 +145,9 @@ let helpText (xmlPath: string) (assembly: string) (modName: string) (implName: s
119145
|> List.ofSeq
120146

121147
let returns =
122-
n.SelectSingleNode("returns") |> Option.ofObj |> Option.map _.InnerText.Trim()
148+
n.SelectSingleNode("returns")
149+
|> Option.ofObj
150+
|> Option.map (fun n -> getTexts(n).Trim())
123151

124152
let exceptions =
125153
n.SelectNodes("exception")

src/Fsih/Program.fs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,27 @@ module Program =
9292

9393
[<EntryPoint>]
9494
let main argv =
95-
h <@ Option.isNone @>
96-
h <@ Option.defaultValue @>
97-
h <@ Seq.allPairs @>
98-
h <@ Seq.iter @>
99-
h <@ Seq.average [ 1. ] @>
100-
h <@ Seq.append @>
101-
h <@ Seq.average [ 1. ] @>
102-
h <@ printfn @>
103-
h <@ None @>
104-
h <@ System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes @>
105-
h <@ Collections.ResizeArray<int> [] @>
106-
h <@ [] @>
107-
h <@ "" @>
108-
h <@ 1 :: List.empty @>
109-
h <@ Map @>
110-
h <@ [| 1 |] @>
111-
h <@ Array.Parallel.tryFind @>
112-
h <@ Seq.head @>
113-
h <@ Seq.delay @>
114-
h <@ Seq.countBy @>
95+
// h <@ Option.isNone @>
96+
// h <@ Option.defaultValue @>
97+
// h <@ Seq.allPairs @>
98+
// h <@ Seq.iter @>
99+
// h <@ Seq.average [ 1. ] @>
100+
// h <@ Seq.append @>
101+
// h <@ Seq.average [ 1. ] @>
102+
// h <@ printfn @>
103+
// h <@ None @>
104+
// h <@ System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes @>
105+
// h <@ Collections.ResizeArray<int> [] @>
106+
// h <@ [] @>
107+
// h <@ "" @>
108+
// h <@ 1 :: List.empty @>
109+
// h <@ Map @>
110+
// h <@ [| 1 |] @>
111+
// h <@ Array.Parallel.tryFind @>
112+
// h <@ Seq.head @>
113+
// h <@ Seq.delay @>
114+
// h <@ Seq.countBy @>
115+
// h <@ Microsoft.FSharp.Collections.HashIdentity.FromFunctions @>
116+
// h <@ List.reduce @>
115117

116118
0

0 commit comments

Comments
 (0)