问题描述
我有一个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"));
}
}
}
我尝试过的事情:
- 我的直觉(错误地)说,返回具有不同errorType的ErrorTag可能会产生不同类型的标签,但是无论您传递的是什么字符串,花形都将保持红色.例如.新的ErrorTag("Warning")发出红色花样. MSDN文档几乎不存在.请参见 ErrorTag .
- 在标记名称空间中没有提及实现ITag的其他Tag类.我希望有一个WarningTag或InfoTag.
- 在MSDN论坛上提出了一个问题这里.
- 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.
- In the Tagging namespace there is no mention of a different Tag class implementing ITag. I hoped a WarningTag or InfoTag existed.
- 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?!
推荐答案
PredefinedErrorTypeNames 包含ErrorTag
的ErrorType
属性的支持值.
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扩展创建绿色(或蓝色)花体装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!