Visual Studio 2015中的GetClassificationSpans不返回任何内容 [英] GetClassificationSpans in Visual Studio 2015 doesn't return anything

查看:124
本文介绍了Visual Studio 2015中的GetClassificationSpans不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标记器(ITagger的子类),并且我试图调用GetClassificationSpans,以便可以使用分类来查找使用标记进行格式化的注释.这在Visual Studio 2013中有效,但是现在在Visual Studio 2015中运行它时,GetClassificationSpans始终返回一个空列表-即使我在调试器中检查了范围,也肯定传递了带有注释的范围.

有人知道2015年在调用GetClassificationSpans方面可能发生的变化吗?

顺便说一句:通过将IClassifierAggregatorService导入我的标记提供程序(ITaggerProvider的子类)并将其传递给标记程序的构造函数,我得到了分类器:

[import]
IClassifierAggregatorService aggregator;

然后,我在从提供者那里获得的聚合器上的标记器中使用以下调用:

IList<ClassificationSpan> lstClassifiers = aggregator.GetClassifier(span.Snapshot.TextBuffer).GetClassificationSpans(span);

而且,正如我所说,lstClassifiers列表始终为空.在VS2013中找到了完全相同的代码.我似乎在网上找不到任何提及VS2015可能导致此问题的更改.

谢谢

解决方案

尽管在不同的上下文中,我还是遇到了相同的问题.从我的谷歌搜索看来,他们似乎已经改变了分类器,因此它们被懒惰地初始化了……我猜GetClassificationSpans()不会强行初始化它们. MSFT仍然认为这是一个错误,因此您可能希望在VS Connect上对该问题进行/a>.

一个潜在的解决方法(如MSFT所建议的)是切换为使用TagAggregator而不是IClassifier.因此,代替:

var service = container.GetService<IClassifierAggregatorService>();
var classifier = service.GetClassifier(textView.TextBuffer);
var spans = classifier.GetClassificationSpans(new SnapshotSpan(...));

您可以改写这样的内容:

var service = container.GetService<IViewTagAggregatorFactoryService>();
var aggregator = service.CreateTagAggregator<IClassificationTag>(textView);
var tags = aggregator.GetTags(new SnapshotSpan(...)));

这将返回IMappingTagSpan<IClassificationTag>的列表,而不是ClassificationSpan的列表,因此使用它们的方式略有不同.但是基础数据似乎在大多数情况下都是相同的-即,您可以获得每个词汇元素的分类和范围.有一些细微的差异(请参阅VS Connect上的描述),但是结果对于我的应用程序来说已经足够好了.

I have a tagger (subclass of ITagger) and I'm trying to call GetClassificationSpans so I can use the classifications to find comments to format using tags. This worked in Visual Studio 2013, but now when running it in Visual Studio 2015, GetClassificationSpans always returns an empty list - even when I've examined the span in the debugger and it is definitely passing a span with a comment in it.

Does anyone know what could have changed in 2015 in regards to calling GetClassificationSpans?

BTW: I'm getting the classifier by importing the IClassifierAggregatorService in my tagger provider (subclass of ITaggerProvider) and passing it along to the constructor of the tagger:

[import]
IClassifierAggregatorService aggregator;

Then I use the following call in the tagger on the aggregator that I got from the provider:

IList<ClassificationSpan> lstClassifiers = aggregator.GetClassifier(span.Snapshot.TextBuffer).GetClassificationSpans(span);

And, as I said, the lstClassifiers list is always empty. The exact same code ran find in VS2013. I can't seem to find anything on the net that mentions any changes in VS2015 that may be causing this.

Thanks,

解决方案

I ran into the same problem, though in a different context. From my googling, it looks like they've changed the classifiers so that they're lazily initialized... and I guess GetClassificationSpans() won't forceably initialize them. MSFT still considers this a bug, so you might want to up-vote the issue on VS Connect.

A potential workaround (as suggested by MSFT) is to switch to using TagAggregator instead of IClassifier. So instead of:

var service = container.GetService<IClassifierAggregatorService>();
var classifier = service.GetClassifier(textView.TextBuffer);
var spans = classifier.GetClassificationSpans(new SnapshotSpan(...));

You can instead write something like this:

var service = container.GetService<IViewTagAggregatorFactoryService>();
var aggregator = service.CreateTagAggregator<IClassificationTag>(textView);
var tags = aggregator.GetTags(new SnapshotSpan(...)));

This returns a list of IMappingTagSpan<IClassificationTag> instead of a list of ClassificationSpan, so the way you'll work with them is slightly different. But the underlying data appears to be mostly the same---i.e., you can get a classification and span for each lexical element. There are some subtle differences (see the description on VS Connect), but the results were good enough for my application.

这篇关于Visual Studio 2015中的GetClassificationSpans不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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