Inside F#

Brian's thoughts on F# and .NET

Archive for December, 2010

Source code for F# XmlDoc extension

Posted by Brian on December 4, 2010

I’ve just published the code for another VSIX extension; this one auto creates xml documentation boilerplate when you type triple-slash.  For example, if you have the code:

type SomeType() =
 
     member this.Foo(x:int, s:string) = 
         printfn "%d: %s" x s

and you type “///” anywhere on the blank line before “Foo”, then you get

type SomeType() =
     /// <summary>
     /// 
     /// </summary>
     /// <param name="x"></param>
     /// <param name="s"></param>
     member this.Foo(x:int, s:string) = 
         printfn "%d: %s" x s

with your cursor sitting conveniently between the summary tags.  And if instead you type “///” above the type declaration, you get

/// <summary>
/// 
/// </summary>
type SomeType() =
 
     member this.Foo(x:int, s:string) = 
         printfn "%d: %s" x s

Get the idea?  Just type “///” on a blank line right before a member, type, or module-scoped let (before any attributes, if there are any), and you get a blank xmldoc template (if there wasn’t already an xmldoc there).

I don’t plan to put this one on the gallery, as I’m not too interested in maintaining it.  You can grab the the source from github, set the VSIX project as the startup project, and build it yourself.  (If someone is interested in refining/publishing it, you can contact me directly.) 

The source code is simple, and structured just like my previous extension.  There are two projects. “MyFSParser” is (again) just the parser code ripped from the F# compiler, with about 130 new lines of code at the end of MyParsing.fs that computes information about every xml-doc-able entity in a file.  “FSXmlDocVSIX” is the editor extension that, in a mere 120 lines of code in Program.fs, intercepts keypresses and does some special logic when you press ‘/’ to see if you just typed “///” on a blank line above an xml-doc-able, and if so, dumps extra stuff into your editor buffer.  It’s really simple; if you ever wanted to look at a straightforward extension to the Visual Studio editor, this is a good code sample.

Posted in Uncategorized | 4 Comments »