How to: Implement Error Markers
Error markers (or red wavy underlines) are the most difficult of the text editor customizations to implement. However, the benefits they give to users of your VSPackage can far outweigh the cost to provide them. Error markers subtly mark text that your language parser deems incorrect with a squiggly or wavy red line. This indicator helps programmers by visually displaying incorrect code.
Use text markers to implement the red wavy underlines. As a rule, language services add red wavy underlines to the text buffer as a background pass, either at idle time or in a background thread.
To implement the red wavy underline feature
Select the text under which you want place the red wavy underline.
Create a marker of the type MARKER_CODESENSE_ERROR. For more information, see How to: Add Standard Text Markers.
After that, pass in an IVsTextMarkerClient interface pointer.
This process also allows you to create tip text or a special context menu over a given marker. For more information, see How to: Add Standard Text Markers.
The following objects are required before error markers can be displayed.
A parser.
A task provider (that is, an implementation of IVsTaskProvider2) that maintains a record of changes in line information in order to identify the lines to be re-parsed.
A text view filter that captures caret change events from the view using the OnChangeCaretLine) method.
The parser, task provider, and filter provide the infrastructure necessary to make error markers possible. The following steps provide the process for displaying error markers.
In a view that is being filtered, the filter obtains a pointer to the task provider associated with that view's data.
Hinweis
You can use the same command filter for method tips, statement completion, error markers, and so on.
When the filter receives an event indicating that you have moved to another line, a task is created to check for errors.
The task handler checks if the line is dirty. If so, it parses the line for errors.
If errors are found, the task provider creates a task item instance. This instance creates the text marker that the environment uses as an error marker in the text view.
See Also
Tasks
How to: Add Standard Text Markers
How to: Create Custom Text Markers