首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Roslyn Diagnostic + Visual Studio着色

Roslyn Diagnostic + Visual Studio着色
EN

Stack Overflow用户
提问于 2014-12-02 06:44:49
回答 1查看 172关注 0票数 0

有没有人知道我可以在哪里找到一个基于Roslyn诊断的标记着色的“简单”示例。是的,我可以将它们设置为信息、警告、错误或隐藏。所以假设我想使用Hidden,这样它就不会出现在错误列表/窗口中,但是可以访问,这样我以后就可以使用它了。

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

这就是我一直在尝试的。

代码语言:javascript
复制
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

代码语言:javascript
复制
    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。

EN

回答 1

Stack Overflow用户

发布于 2014-12-02 22:36:25

这只能通过IDiagnosticService完成(这是Roslyn对错误标签和不必要的代码进行分类的方式)。

这个接口是内部的,所以你不太走运(除非你想使用很多反射)。

你可以在CodePlex上提交一个问题,并要求他们公开IDiagnosticService

您还可以要求他们公开AbstractDiagnosticsTagProducer<TTag>;它将实现您想要的功能,允许您插入一个过滤器和一个标签创建器。

有关更多信息,请查看反编译器中的该类。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27238761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档