Code Editor Markers in Visual Lint
Tuesday 27th April, 2010
For some time now we have wanted to enhance Visual Lint to make use of the code editor customisation capabilities of Visual Studio. With Visual Lint 2.5 now out, the Visual Lint development branch is now focused on the next version of Visual Lint (due out next Spring), and that is giving us the opportuity to start looking at more ambitious new features.
One obvious thing to do is to add code editor markers for analysis issues. In their simplest form, these take the form of icons displayed in the margin of the code editor - the most familiar uses being for breakpoints and bookmarks.
Fortunately, recent versions of Visual Studio provide interfaces to allow you to do this - albeit ones which are complex and rather poorly documented.*
* These are the VSIP interfaces (the lowest and most complex level of Visual Studio Extensibility, and the ones used to integrate language services such as Visual C++ and Visual C# into the IDE) rather than the higher level automation interfaces normally used by Visual Studio add-ins.
The basic idea is simple - place a marker in the code editor wherever an analysis issue is detected. In practice, it is somewhat more complex than that, as you then need to decide how the user will interact with the new marker and detect and handle line deltas (due to editing etc.) as they arise.
However, as a starting point, we have now implemented basic markers (using the same icons as the Analysis Status and Results Displays) in the Visual Lint development branch:

Hovering over a marker will of course yield a tooltip which describes its meaning:

There are some interesting subtleties involved with doing this. For example, many lint issues report their line number as the line at which the effort of the issue makes itself felt, rather than where the code fragment that causes it is. In such cases, a corresponding "Reference/Location cited in prior message" issue will locate the offending bit of code.
In marker terms, this means that the marker which actually locates the problem may be a generic location marker, and therefore not as helpful as it could be. Our approach to this is to attempt to highlight the code fragment which actually caused to the issue, as you can see in the following screenshot:

Ultimately, we want to make these interactive by adding a context menu which will allow the user to suppress (or even fix!) a specific issue directly from the code editor. That said, we feel that this is a good starting point for the development of a set of potentially very complex functionality.
