2014-12-01 22 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>公開;它會做你正在尋找的東西,讓你插入一個過濾器和一個標籤創建器。
有關更多信息,請在反編譯器中查看該類。

相關問題