Converting Roslyn diagnostics to squiggles

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 10 months ago by Steven Marshall
Version: 19.1.0683

Hi, I'm trying to highlight Roslyn diagnostics in an Actipro syntax document using a CollectionTagger, but have a couple of issues

The document offsets returned from Roslyn don't include CR/LF characters whereas it appears that the offsets required in the Actipro TextSnapshotRange should include them. So the squiggles appear in the wrong locations in the document.

The quickinfo for the squiggles also only appears when i hover over the very start of the squiggle

How can i use Roslyn to provide all the backend parsing, diagnostics, completion etc with the SyntaxEditor.

    public override IEnumerable<TagSnapshotRange<ISquiggleTag>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
      var currentDiagnostics = diagnostics;
      if (currentDiagnostics != null)
        foreach (var snapshotRange in snapshotRanges)
          var startOffset = snapshotRange.StartOffset;
          var endOffset = snapshotRange.EndOffset;

          var diagnostics = currentDiagnostics.Where((diagnostic) =>
            return (
              Document.FileName == diagnostic.Location.SourceTree.FilePath &&
              diagnostic.Location.SourceSpan.Start >= startOffset &&
              diagnostic.Location.SourceSpan.Start <= endOffset);

          foreach (var diagnostic in diagnostics)
            var start = diagnostic.Location.SourceSpan.Start;
            var end = diagnostic.Location.SourceSpan.End;
            var message = diagnostic.GetMessage();
            yield return new TagSnapshotRange<ISquiggleTag>(
              new TextSnapshotRange(snapshotRange.Snapshot, start, end),
              new SquiggleTag(ClassificationTypes.Warning, 
              new CompilerDiagnosticContentProvider(message)));

Comments (2)

Posted 9 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Steven,

Our offsets are zero-based and count one character per line end.  We also allow you to do easy conversion of line/character pairs (what we call a TextPosition) to our offsets.

Are you able to get the line/char of your source span somehow?  If so then you could use our snapshot methods to convert that position to an offset.

Also, for the other question, I'm using our latest codebase and I'm able to hover anywhere over a squiggle to see the related quick info.

Actipro Software Support

Posted 9 months ago by Steven Marshall

Thankyou - this worked perfectly, and having correct squiggle positions seems to have fixed the quick info issue too. Much appreciated

The latest build of this product (v2019.1 build 0686) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.