0

我正在为 Visual Studio 开发 LanguageService,并且在 Visual Studio 2013 中遇到自定义颜色问题。我最近从 Visual Studio 2010 迁移到 2013,现在每当我设置RequestStockColors为时false,我都会失去所有语法突出显示。

我的 LanguageService 实现GetColorableItemGetItemCount. 我正在使用 9 种自定义颜色。当我调试我的语言服务时,我注意到它GetColorableItem被调用了几次,但从GetItemCount未被击中。

通过 Visual Studio 进行调试时,我使用以下命令行参数:

/ranu /rootsuffix Exp

更新:我更改了前 5 种颜色的名称(与标准标记颜色重叠的颜色)以匹配标准名称(例如“关键字”、“标识符”等),这些颜色现在显示,但我的没有出现额外的颜色类型。此外,我从未看到它们中的任何一个出现在 Visual Studio 的字体和颜色配置中。我如何让它们安装在那里?

4

2 回答 2

3

我最近遇到了一个类似的问题,我的自定义 ColorableItems 没有出现在我的语法突出显示中。我可以通过清除字体和颜色缓存来解决这个问题。

我暂时在我的 vs 包的 Initialize 方法中包含以下内容:

IVsFontAndColorCacheManager mgr = this.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager;
mgr.ClearAllCaches();

这为我解决了问题。此修复不需要包括 6 个默认值或需要任何其他 ClassificationFormatDefinition 类。

注意:值得一提的是,我也从未见过 GetItemCount() 被调用,但清除缓存解决了主要问题。

学分:也归功于 Ed Dore 在此线程http://www.databaseforum.info/8/1217583.aspx上的评论,它帮助我找到了解决方法。

于 2015-03-16T00:29:34.587 回答
0

事实证明,我需要为ClassificationFormatDefinition我的每种自定义颜色创建一个实例并将它们导出为一种EditorFormatDefinition类型。一旦我这样做了,它们就会出现在字体和颜色页面中,并且还会出现在语法突出显示中。

对于默认 6 之外的每种颜色,我添加了一个类定义,如下所示:

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "<name of color>")]
[Name("<name of color>")]
[UserVisible(true)]
[Order(Before = Priority.Default)]
internal sealed class ExampleColor: ClassificationFormatDefinition
{
    public ExampleColor()
    {
        this.DisplayName = "<name of color>";
        this.ForegroundColor = System.Windows.Media.Color.FromArgb(0, 0, 128, 128);
    }
}

但是,我仍然没有看到我的GetItemCount()方法受到任何影响。

于 2015-02-03T19:46:33.103 回答