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 일 수 있습니다.