@@ -68,21 +68,27 @@ let trimDotNet (s: string) =
6868// WTF, seems like we loose inner xml (example content) if we cache an XmlDocument
6969let xmlDocCache = Collections.Generic.Dictionary< string, string>()
7070
71- let getXmlDocument xmlPath =
71+ let tryGetXmlDocument xmlPath =
7272#if DEBUG
73- printfn $" xml file: %s {xmlPath}"
73+ printfn $" trying xml file: %s {xmlPath}"
7474#endif
75- match xmlDocCache.TryGetValue( xmlPath) with
76- | true , value ->
77- let xmlDocument = XmlDocument()
78- xmlDocument.LoadXml( value)
79- xmlDocument
80- | _ ->
81- let rawXml = File.ReadAllText( xmlPath)
82- let xmlDocument = XmlDocument()
83- xmlDocument.LoadXml( rawXml)
84- xmlDocCache.Add( xmlPath, rawXml)
85- xmlDocument
75+ try
76+ match xmlDocCache.TryGetValue( xmlPath) with
77+ | true , value ->
78+ let xmlDocument = XmlDocument()
79+ xmlDocument.LoadXml( value)
80+ Some xmlDocument
81+ | _ ->
82+ let rawXml = System.IO.File.ReadAllText( xmlPath)
83+ let xmlDocument = XmlDocument()
84+ xmlDocument.LoadXml( rawXml)
85+ xmlDocCache.Add( xmlPath, rawXml)
86+ Some xmlDocument
87+ with _ ->
88+ #if DEBUG
89+ printfn $" xml file not found: {xmlPath}"
90+ #endif
91+ None
8692
8793let getTexts ( node : Xml.XmlNode ) =
8894 seq {
@@ -101,93 +107,91 @@ let getTexts (node: Xml.XmlNode) =
101107 }
102108 |> String.concat " "
103109
104- let helpText ( xmlPath : string ) ( assembly : string ) ( modName : string ) ( implName : string ) ( sourceName : string ) =
110+ let tryMkHelp
111+ ( xmlDocument : XmlDocument option )
112+ ( assembly : string )
113+ ( modName : string )
114+ ( implName : string )
115+ ( sourceName : string )
116+ =
105117 let sourceName = sourceName.Replace( '.' , '#' ) // for .ctor
106118 let implName = implName.Replace( '.' , '#' ) // for .ctor
107119 let xmlName = $" {modName}.{implName}"
108- let xmlDocument = getXmlDocument xmlPath
109120
110- let node =
111- let toTry =
112- [ $""" /doc/members/member[contains(@name, ":{xmlName}`")]"""
113- $""" /doc/members/member[contains(@name, ":{xmlName}(")]"""
114- $""" /doc/members/member[contains(@name, ":{xmlName}")]""" ]
121+ let toTry =
122+ [ $""" /doc/members/member[contains(@name, ":{xmlName}`")]"""
123+ $""" /doc/members/member[contains(@name, ":{xmlName}(")]"""
124+ $""" /doc/members/member[contains(@name, ":{xmlName}")]""" ]
115125
126+ xmlDocument
127+ |> Option.bind ( fun xmlDocument ->
116128 seq {
117129 for t in toTry do
118- #if DEBUG
119- printfn " trying xpath: %s " t
120- #endif
121130 let node = xmlDocument.SelectSingleNode( t)
122131 if not ( isNull node) then Some node else None
123132 }
124- |> Seq.tryPick id
125-
126- match node with
127- | None ->
128- #if DEBUG
129- printfn $" // No node found for {xmlName}"
130- #endif
131- None
132- | Some n ->
133- let summary =
134- n.SelectSingleNode( " summary" )
135- |> Option.ofObj
136- |> Option.map getTexts
137- |> Option.map cleanupXmlContent
138-
139- let remarks =
140- n.SelectSingleNode( " remarks" )
141- |> Option.ofObj
142- |> Option.map getTexts
143- |> Option.map cleanupXmlContent
144-
145- let parameters =
146- n.SelectNodes( " param" )
147- |> Seq.cast< XmlNode>
148- |> Seq.map ( fun n -> n.Attributes.GetNamedItem( " name" ) .Value.Trim(), n.InnerText.Trim())
149- |> List.ofSeq
150-
151- let returns =
152- n.SelectSingleNode( " returns" )
153- |> Option.ofObj
154- |> Option.map ( fun n -> getTexts( n) .Trim())
155-
156- let exceptions =
157- n.SelectNodes( " exception" )
158- |> Seq.cast< XmlNode>
159- |> Seq.map ( fun n ->
160- let exType = n.Attributes.GetNamedItem( " cref" ) .Value
161- let idx = exType.IndexOf( ':' )
162- let exType = if idx >= 0 then exType.Substring( idx + 1 ) else exType
163- exType.Trim(), n.InnerText.Trim())
164- |> List.ofSeq
165-
166- let examples =
167- n.SelectNodes( " example" )
168- |> Seq.cast< XmlNode>
169- |> Seq.map ( fun n ->
170- let codeNode = n.SelectSingleNode( " code" )
171-
172- let code =
173- if isNull codeNode then
174- " "
175- else
176- n.RemoveChild( codeNode) |> ignore
177- cleanupXmlContent codeNode.InnerText
178-
179- code, cleanupXmlContent n.InnerText)
180- |> List.ofSeq
181-
182- match summary with
183- | Some s ->
184- { Summary = s
185- Remarks = remarks
186- Parameters = parameters
187- Returns = returns
188- Exceptions = exceptions
189- Examples = examples
190- FullName = $" {modName}.{sourceName}" // the long ident as users see it
191- Assembly = assembly }
192- |> Some
193- | None -> None
133+ |> Seq.tryPick id)
134+ |> function
135+ | None -> ValueNone
136+ | Some n ->
137+ let summary =
138+ n.SelectSingleNode( " summary" )
139+ |> Option.ofObj
140+ |> Option.map getTexts
141+ |> Option.map cleanupXmlContent
142+
143+ let remarks =
144+ n.SelectSingleNode( " remarks" )
145+ |> Option.ofObj
146+ |> Option.map getTexts
147+ |> Option.map cleanupXmlContent
148+
149+ let parameters =
150+ n.SelectNodes( " param" )
151+ |> Seq.cast< XmlNode>
152+ |> Seq.map ( fun n -> n.Attributes.GetNamedItem( " name" ) .Value.Trim(), n.InnerText.Trim())
153+ |> List.ofSeq
154+
155+ let returns =
156+ n.SelectSingleNode( " returns" )
157+ |> Option.ofObj
158+ |> Option.map ( fun n -> getTexts( n) .Trim())
159+
160+ let exceptions =
161+ n.SelectNodes( " exception" )
162+ |> Seq.cast< XmlNode>
163+ |> Seq.map ( fun n ->
164+ let exType = n.Attributes.GetNamedItem( " cref" ) .Value
165+ let idx = exType.IndexOf( ':' )
166+ let exType = if idx >= 0 then exType.Substring( idx + 1 ) else exType
167+ exType.Trim(), n.InnerText.Trim())
168+ |> List.ofSeq
169+
170+ let examples =
171+ n.SelectNodes( " example" )
172+ |> Seq.cast< XmlNode>
173+ |> Seq.map ( fun n ->
174+ let codeNode = n.SelectSingleNode( " code" )
175+
176+ let code =
177+ if isNull codeNode then
178+ " "
179+ else
180+ n.RemoveChild( codeNode) |> ignore
181+ cleanupXmlContent codeNode.InnerText
182+
183+ code, cleanupXmlContent n.InnerText)
184+ |> List.ofSeq
185+
186+ match summary with
187+ | Some s ->
188+ { Summary = s
189+ Remarks = remarks
190+ Parameters = parameters
191+ Returns = returns
192+ Exceptions = exceptions
193+ Examples = examples
194+ FullName = $" {modName}.{sourceName}" // the long ident as users see it
195+ Assembly = assembly }
196+ |> ValueSome
197+ | None -> ValueNone
0 commit comments