Introducing: GhostDoc


[2004-08-22] As this old post has a pretty high Google rating, I'd like to emphasise that it does not contain up-to-date information. If you are interested in GhostDoc, I'd suggest to take a look at the GhostDoc homepage.


/// <summary>
/// GhostDoc is a VS.Net macro for automatically generating those
/// parts of a C# doc comment that can be deduced from the name
/// and/or type of a method or property.
/// </summary>


In my previous post I already mentioned my current project "GhostDoc"; now a first public release is ready. Before I start explaining a lot of things, why don't just watch the small video showing GhostDoc in action (400k).

Now here's the basic idea for GhostDoc: When writing documentation comments (e.g. for an API) I tend to use "documentation patterns", e.g. the infamous "Gets or sets a value indicating whether" for a boolean property. And my summary often consists of what I call "method/property name as a sentence plus X", with X being something that adds some value. Example: if I have e.g. a method "void CreateDocumentBuffer(int bytes)", I write "Creates the document buffer with the specified size in bytes". Of this sentence, typing the words "Creates the document buffer" is pretty brainless labor (because I already typed the method name). So wouldn't it be cool if some macro would do that for me? Well, that's what GhostDoc is about; or to be exact, what the very first version started with.

GhostDoc works the following way: When you hit a hotkey inside the c# source editor of VS.Net, GhostDoc finds out what kind of code element the cursor is currently in (e.g. a method), determines the name and (return) type and uses these to look up a matching template for the documentation comment (the templates are stored in an XML configuration file).

The current version of GhostDoc is definitely a "technical preview". It's the result of a macro that grew bigger and bigger until it had to be supported by code in a C# assembly. Now all code is in the assembly and the macro consists only of a single method call. So GhostDoc is not (yet) a VS.Net addin. It's pretty stable; stable enough for me to use it both at home and at work. The good thing is that because of the way GhostDoc works, it simply can't mess up your source code (unless VS.Net has some serious problems) and undo works nicely, too.


The installation is currently completely manual

  • Download
  • Unzip it to a directory of your choice
  • Move "Weigelt.Tools.GhostDoc.dll" and "Weigelt.Tools.GhostDoc.Texts.xml" to the  "Common7\IDE\PublicAssemblies" subdirectory inside your VS.Net 2003 installation directory.
  • Start Visual Studio and go to the Macros IDE (Tools - Macros - Macros IDE)
  • Open the MyMacros node in the project explorer
  • Add a reference to the "GhostDoc macro support" assembly (it will appear automatically in the list of the "Add Reference" dialog)
  • Right click "MyMacros" and "Add existing item", browsing for the "GhostDoc.vb" file in the directory you unzipped to.
  • Save and leave the Macros IDE.
  • Open the options dialog (Tools - Options) and define the keyboard bindings; simply type "ghost" in the "show commands containing" input field and you'll see the two commands (I use Ctrl-D for CreateComment, and Ctrl-Shift-D for RefreshConfiguration, but it's completely up to you)

Getting started

Move the cursor into a method or a property without a documentation comment, and hit e.g. Ctrl-D (if a documentation comment already exists, nothing will happen). Note that your code should use .NET naming conventions, otherwise the results can be pretty strange, sometimes even funny. GhostDoc is highly configurable, but in this version the default configuration is far from being finished. Simply take a look into the file "Weigelt.Tools.GhostDoc.Texts.xml" and you'll get an idea how things work.

Known Issues

  • As already mentioned, the generated summary can sometimes be pretty off. In many cases, a new rule in the configuration will help - if you add such a rule, please send me a copy.
  • There is virtually no user documentation. Some information can be found inside comments in the configuration file.

Plans for the future

  • More entries in the configuration file
  • A GUI for editing the configuration
  • Better installation
  • A release including source code, maybe opening a GDN workspace.
  • ...

Update 01.12.2003: I'm now working on turning GhostDoc into a Visual Studio .NET addin. So if you're put off by the ugly installation of the current version, you may want wait just a little.

1 Comment

  • Good question ;-) No, seriously, I prefer reading an actual sentence in a tooltip shown by intellisense, especially for methods with multiple overloads or with several parameters (of which the comment e.g. only mentions the one or two important ones).

    When you are dealing with properties though, even a trivial doc comment does in fact help you lot, because it tells you (again, when shown in a tooltip in the text editor) whether the property is read-only or read-write (or write-only ;-).

    Regarding the overall idea of generating and/or writing &quot;obvious stuff&quot; in a doc comment, my personal experience is that once the initial hurdle to write any comment at all is taken, additional (more valuable) information is added with less effort; maybe even quite some time later when revisiting the method.

Comments have been disabled for this content.