This week in NORMA I spent refactoring the syntax highlighting, which parses the entered text to provide tokens, or words, to be highlighted in specific colors. I made some helper methods to easily be able to get a list of all of the tokens present, including being able to tell if that token is an ObjectType on the existing model. Right now you can see this information by just hovering your curser over the ObjectType in the editor. It's possible to put a "squiggly" line underneath the text, and I successfully got that working, though the consensus was that it is possible that users would not like it on by default (we currently have some users that do not like the Model Error list showing errors at all). So it is possible that this feature may be included as a "turn on" type option.


The code to get the tooltips to work is fairly straightforward. You override the GetDataTipText method in a class derived from AuthoringScope.
/// <summary>
/// Returns a string to be used for a tool tip based on the specified location.
/// </summary>
/// <param name="line">[in] The line in the source to look at for a tool tip.</param>
/// <param name="col">[in] An offset within the line to look at for a tool tip.</param>
/// <param name="span">A <see cref="T:Microsoft.VisualStudio.TextManager.Interop.TextSpan"></see>
/// that describes the area over which the cursor can hover before the tool tip is dismissed from view.</param>
/// <returns>
/// If successful, returns a string containing the text for the tool tip; otherwise, returns a null value.
/// </returns>
[CLSCompliant(false)]
public override string GetDataTipText(Int32 line, Int32 col, out TextSpan span)
{
// new up the span
span = new TextSpan();
// if the line isn't the first, just return null
if (line > 0)
{
return null;
}
// get the view of the parse request
IVsTextView view = m_ParseRequest.View;
// get the token at the given column index
FactTokenInfo token = FactTokenHelper.GetTokenAtIndex(col, view, m_LanguageService);
// populate the span information
span.iStartLine = line;
span.iStartIndex = token.StartIndex;
span.iEndIndex = token.EndIndex + 1;
// if the token does not exist on the model create a document task
// (that is the squiggly line)
if (!token.ExistsOnModel)
{
Source s = m_LanguageService.GetOrCreateSource(view);
if (s != null)
{
DocumentTask task = s.CreateErrorTaskItem(span, MARKERTYPE.MARKER_SYNTAXERROR, String.Empty);
task.CanDelete = true;
}
}
// return the string to show as the tooltip
return String.Format("{0} {1} exist on the model.", token.Value, (token.ExistsOnModel == true) ? "does" : "does not");
}
And here's a screenshot from some of last week's work.
