Is there a way to make fsi print the documentation for a function?
I can retrieve the type by just evaluating the function as a value but I would like the know what the xml docs say if they exist.
Without the use case I have 2 suggestions. If this is just about help then use and FSX file.
If you are actually wanting to print out the docs in FSI you could use the following code to print out the docs for a member. Since the xml comments are not stored in the dll, this code checks if the xml doc exists in the location of the dll and loads that in if so.
#r "packages/Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll"
open System.IO
open System.Xml
open System.Reflection
let loadXml (path:string) =
if (File.Exists(path)) then
let xml = new XmlDocument()
xml.Load(path)
Some xml
else None
let xmlForMember (maybeXml:XmlDocument option) (mi:MemberInfo) =
let path = sprintf "M:%s.%s" mi.DeclaringType.FullName mi.Name
match maybeXml with
| None -> None
| Some xml -> xml.SelectSingleNode("//member[starts-with(@name, '" + path + "')]") |> Some
let docFrom (node:XmlNode option) =
match node with
| None -> "No docs available"
| Some n -> n.InnerXml
Usage would be something like this but you could neaten and package this up for your needs:
let t = typedefof<Newtonsoft.Json.JsonSerializer>
let assembly = t.Assembly
let dllPath = assembly.Location
printfn "Assembly location: %s" dllPath
let expectedXmlPath = Path.ChangeExtension(dllPath, ".xml")
printfn "Expected xml: %s" expectedXmlPath
let xmlDoc = expectedXmlPath |> loadXml
let mi = t.GetMember("Create").[0]
let docNode = mi |> xmlForMember xmlDoc
docNode |> docFrom |> printfn "%s"
Hope this can get you started.