Inside F#

Brian's thoughts on F# and .NET

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.

About these ads

4 Responses to “Source code for F# XmlDoc extension”

  1. Nice, thats what we need for F# more productivity tools, it still feels like its way behind the productivity I get with something like resharper.

    Whats next a refactoring plugin? go on, you know you want to…

  2. […] Brian McNamara’s Source code for F# XmlDoc extension “I’ve just published the code for another VSIX extension; this one auto creates xml documentation boilerplate when you type triple-slash” […]

  3. […] Inside F#: Source code for F# XmlDoc extension; […]

  4. alex said

    very nice, thanks for posting this extension,
    couple of things to make it compile: need to install Visual Studio 2010 SDK from here: http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=47305cf4-2bea-43c0-91cd-1b853602dcc5&displaylang=en
    and for 32-bit machines change paths in the project file to remove (x86) from Program Files.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 30 other followers

%d bloggers like this: