/\
Documenting code in VS.Net 2003

I wrote C# should be last plain-text language several mounths ago.
There I criticize Visual Studio and make proposals of how project files should be organized and viewed instead.
"My intentions are simple. I wish to show my project to other person and has him/her immediately understand purpose, reasons and relations of project's parts without going to it's details."

Some time after when wandering .Net forums I meet mention of "Collapse to definition" command and found it was here (in Studio) all the time (more than year) and I was not aware (stupid).

Collapsed view looks very well, comparably to my "wish to see" examples in previous article. So I decided to try to customize Visual Studio more to my fashion.

First I tried to do something with Solution Explorer.
Forget about commenting files. Forget about logical ordering. Alphabetic list is only option. I read a message in some forum there one VS team member agreed that there should be choice, it was dated 2002. As we can see in 2005 Beta deadline was already too close to change something.

At least I can group project items to folders but what damned! Its are actual file folders and my files now spreaded and Editor's tabs are fulled by long combined filenames! In 2005 Beta there are "Solution folders" which can group projects and aren't related to file folders. I want same feature for project items. Let name it "categorized view" of project, symmetrically to alphabetic/categorized views of properties.

To cap my frustration folders are sorted alphabetically too. I hardly restrained a tempt to name folders as "A Something1", "B Something2" and so on. Any way it was ugly and ugly. Years of programming teach me to place things in dependance/inheritance order, from base and general ones on top to more complex and specialized below. In Visual Studio anything is alphabetic - Solution Explorer, Class View, Properties view. When I first time saw Bottom-Left-Right-Top rectangle I laughted but now its not funny anymore.

Alphabetic is evil because destroy relationship!

Now back to collapsed view. There is expanded source:

There it is collapsed:

I want to see comments also so my source will look alike C-header file. So I took this macro as starting point and wrote that:

  Imports EnvDTE
  Imports System.Diagnostics

  Public Module HeaderView
  
    Public Sub CollapseToDefinitionsAndComments()
      DTE.SuppressUI = True
      Try
        DTE.ExecuteCommand("Edit.StopOutlining")
        DTE.ExecuteCommand("Edit.CollapseToDefinitions")
        Dim ts As TextSelection = DTE.ActiveDocument.Selection
        Dim saveAnchor As EditPoint = ts.AnchorPoint.CreateEditPoint
        Dim saveActive As EditPoint = ts.ActivePoint.CreateEditPoint
        ts.EndOfDocument()
        Dim tsStart As EditPoint = ts.ActivePoint.CreateEditPoint
        Dim tsFinish As EditPoint
        Dim line As String

        Do While Not tsStart.AtStartOfDocument
          ts.StartOfLine()
          ts.LineUp(True)
          tsStart = ts.TopPoint.CreateEditPoint
          line = ts.Text.Trim
          If line.StartsWith("//") Then
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            tsFinish = ts.BottomPoint.CreateEditPoint
            If ts.FindText("/// <summary>") Then
              ts.CharLeft(True, 10)
              ts.LineDown(True)
              ts.OutlineSection()
              If ts.FindText("/// </summary>") Then
                ts.SwapAnchor()
                ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True)
                ts.CharLeft(True, 1)
                ts.SwapAnchor()
                ts.MoveToPoint(tsFinish, True)
                ts.OutlineSection()
              End If
              ts.MoveToPoint(tsStart)
            End If
          End If
        Loop
        ts.TextPane.TryToShow(saveActive, vsPaneShowHow.vsPaneShowCentered)
        ts.MoveToPoint(saveAnchor)
        ts.MoveToPoint(saveActive, True)
      Catch
      End Try
      DTE.SuppressUI = False
    End Sub

  End Module

There is resulting view:

I had to add some extra spaces and empty lines to source for better look. In VS 2005 Beta "CollapseToDefinition" work slightly differently so macro should be corrected.

I think similar view should be a standard feature of Visual Studio. It is a much more convenient way to document code than set of generated HTML pages as it is recommended in MSDN.

Note 1: There are so many efforts done to help me write code in Visual Studio, include IntelliSense, Code Snippets and more. I don't need help to write code! I can successfully type my tiny LOCs per day by one finger if I want. I need help to read, understand and manage huge amount of code written instead.

Note 2: It is clear what for documentary purpose traditional comments as "text ignored by compiler" aren't sufficient. Documentary comments are part of declaration syntax and should be supported through some language mechanism alike attributes for example. It is already so in IDL "helpstring", years before JavaDoc was invented. But now I had to write things like this:

  /// <summary>
  /// Sets layout of icons and texts
  /// </summary>
  [Description("Sets layout of icons and texts")]
  public string FormatString {
    ...