如何使用Visual Studio扩展创建绿色(或蓝色)花体装饰 [英] How to create green (or blue) squiggle adornments with a Visual Studio extension

查看:187
本文介绍了如何使用Visual Studio扩展创建绿色(或蓝色)花体装饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio扩展,显示红色错误信息.我还喜欢为花体提供其他颜色,例如黄色作为警告.

I have a Visual Studio extension that show red error squiggles. I also like to provide squiggles with other colors, for example yellow for warnings.

可以通过扩展ITagger类来创建红色花体:

Creating red squiggles can be done by extending the ITagger class, along the lines:

internal sealed class MySquigglesTagger : ITagger<IErrorTag> {
    public IEnumerable<ITagSpan<IErrorTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
        foreach (IMappingTagSpan<MyTokenTag> myTokenTag in this._aggregator.GetTags(spans))        
            SnapshotSpan tagSpan = myTokenTag.Span.GetSpans(this._sourceBuffer)[0];
            yield return new TagSpan<IErrorTag>(tagSpan, new ErrorTag("Error", "some info about the error"));
        }
    }
}

我尝试过的事情:

  1. 我的直觉(错误地)说,返回具有不同errorType的ErrorTag可能会产生不同类型的标签,但是无论您传递的是什么字符串,花形都将保持红色.例如.新的ErrorTag("Warning")发出红色花样. MSDN文档几乎不存在.请参见 ErrorTag .
  2. 标记名称空间中没有提及实现ITag的其他Tag类.我希望有一个WarningTag或InfoTag.
  3. 在MSDN论坛上提出了一个问题
  1. My intuition (incorrectly) says that returning an ErrorTag with an different errorType may yield a different type of tag, but whatever string you pass it, the squiggles remain red. Eg. new ErrorTag("Warning") gives red squiggles. The MSDN documentation is almost nonexistent. See ErrorTag.
  2. In the Tagging namespace there is no mention of a different Tag class implementing ITag. I hoped a WarningTag or InfoTag existed.
  3. Asked a question on MSDN forum here.

问题:如何创建绿色(或蓝色或黄色)花形装饰物?可悲的是,甚至奥秘或令人费解的解决方案也受到赞赏...

Question: how to create green (or blue or yellow) squiggle adornments? Sadly, even arcane or convoluted solutions are appreciated...

我的目标是VS2015和VS2017.

I'm targeting VS2015 and VS2017.

在键入此问题时,MSDN论坛上有人回答说,当前的API无法完成.在Visual Studio中制作黄色花体真的是不可能的吗?!

While typing this question someone at the MSDN forum replied that it cannot be done with the current API. Is it really impossible to make yellow squiggles in Visual Studio?!

推荐答案

The PredefinedErrorTypeNames contains the supported values for the ErrorType property of the ErrorTag.

您已经接近警告",但PredefinedErrorTypeNames.Warning的值似乎是编译器警告".

You got close with "Warning", but the value of PredefinedErrorTypeNames.Warning appears to be "compiler warning".

这篇关于如何使用Visual Studio扩展创建绿色(或蓝色)花体装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆