2014-12-01 77 views
0

是否有任何知道我可以在哪里定位基于Roslyn诊断的令牌的颜色化“简单”示例。是的,我可以让他们信息,警告,错误或隐藏。所以说让我们想使用隐藏,所以它不会出现在错误列表/窗口,但是可以访问,所以我可以稍后做一些事情。Roslyn Diagnostic + Visual Studio Colorisation

现在我已经有了这些隐藏的诊断,现在我想影响IDE中文本的着色。

这是我试过的。

Private Sub CreateVisuals(ByVal line As ITextViewLine) 
    Try 
    'grab a reference to the lines in the current TextView 
    Dim textViewLines = _view?.TextViewLines 
    If textViewLines Is Nothing Then Exit Sub 
    If line Is Nothing Then Exit Sub 
    Dim lineStart As Integer = line.Start 
    Dim lineEnd As Integer = line.End 
    Dim q = textViewLines.FirstOrDefault 
    If q Is Nothing Then Exit Sub 
    Dim qq = q.Snapshot.GetOpenDocumentInCurrentContextWithChanges 
    If qq Is Nothing Then Exit Sub 
    Dim sm = qq.GetSemanticModelAsync.Result '..GetSemanticModelAsync.Result 
    ' Dim di = sm.GetSyntaxDiagnostics.ToArray 
    If sm Is Nothing Then Exit Sub 
    Dim diags = sm.GetDiagnostics.ToArray 

我已经试过GetSyntaxDiagnostic

If diags.Any() = False Then Exit Sub 
    For Each d In diags 
     ' This is the ID if the Diagnostic I want to color. 
     'If d.Id<>"SFD000" Then Continue For 
     Dim charSpan As New SnapshotSpan(_view.TextSnapshot, 
         Span.FromBounds(d.Location.SourceSpan.Start, d.Location.SourceSpan.End)) 
     Dim g As Geometry = textViewLines.GetMarkerGeometry(charSpan) 
     If g IsNot Nothing Then 
     Dim drawing As New GeometryDrawing(_brush, _pen, g) : drawing.Freeze() 
     Dim drawingImage As New DrawingImage(drawing) : drawingImage.Freeze() 
     Dim image As New Image() 
     image.Source = drawingImage 
     'Align the image with the top of the bounds of the text geometry 
     Canvas.SetLeft(image, g.Bounds.Left) 
     Canvas.SetTop(image, g.Bounds.Top) 
     _layer?.AddAdornment(AdornmentPositioningBehavior.TextRelative, 
          charSpan, Nothing, image, Nothing) 
     End If 
    Next 
    Catch ex As Exception 
    Debug.Print(ex.ToString) 
    End Try 
End Sub 

我由编译器得到的诊断问题,但不是我的。为什么?

该示例可以是C#或VB.net。

回答

1

这只能用IDiagnosticService(这是罗斯林如何分类错误标记&不必要的代码)完成的。

该界面是内部的,所以你运气不好(除非你想使用很多反射)。

您可以在CodePlex &上提出问题,要求他们公开IDiagnosticService

你也可以让他们把AbstractDiagnosticsTagProducer<TTag>公开;它会做你正在寻找的东西,让你插入一个过滤器和一个标签创建器。
有关更多信息,请在反编译器中查看该类。