2014-12-01 3 views
0

Roslyn 진단을 기반으로 한 토큰의 "간단한"예를 어디에서 찾을 수 있는지 알고 있습니다. 네, Info, Warning, Error 또는 Hidden으로 만들 수 있습니다. 그래서 숨김을 사용하여 오류 목록/창에 나타나지 않도록하고 싶지만 나중에 액세스 할 수 있도록 액세스 할 수 있습니다.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 

나는 내

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 

GetSyntaxDiagnostic 내가 컴파일러에 의해 진단 문제를 얻을 시도했지만하지 않았습니다. 왜?

예제는 C# 또는 VB.net 일 수 있습니다.

답변

1

IDiagnosticService으로만 가능합니다 (Roslyn이 오류 태그 & 불필요한 코드를 분류하는 방법입니다).

인터페이스가 내부 인터페이스이므로 많은 반사 (Reflection)을 사용하지 않는 한 운이 없어진 것입니다.

CodePlex &에 문제를 제기하여 IDiagnosticService을 공개 할 수 있습니다.

AbstractDiagnosticsTagProducer<TTag>을 공개하도록 요청할 수도 있습니다. 그것은 당신이 찾고있는 것을 정확히 할 것이며, 필터와 태그 생성자를 연결할 수 있습니다.
자세한 내용은 디 컴파일러에서 해당 클래스를 참조하십시오.

관련 문제