Visual Studio 扩展中的自定义可着色项



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

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

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

/ranu /rootsuffix Exp

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

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

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

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

这为我解决了问题。此修复不应要求包含 6 个默认值,也不需要任何其他分类格式定义类。

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

信用:也归功于 Ed Dore 对这个线程的评论 http://www.databaseforum.info/8/1217583.aspx 帮助我找到了我的解决方法。

事实证明,

我需要为每种自定义颜色创建一个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()方法仍然没有命中。

最新更新