Visual studio VSIX如何订购与其他已安装扩展相关的分类器提供程序

Visual studio VSIX如何订购与其他已安装扩展相关的分类器提供程序,visual-studio,visual-studio-2013,vsix,Visual Studio,Visual Studio 2013,Vsix,我开发了一个玩具vsix扩展。它为F#源文件实现了一个分类器。 与此同时,来自FSharp Power Tools的人员升级了他们的扩展,为F#文件提供语法高亮显示 现在在VS2013中,我的分类器总是在它们之前运行,因此它们覆盖了我的颜色 有没有一种方法可以根据一个分类器对另一个分类器进行排序?我在谷歌上没有找到任何关于这个的信息 谢谢不幸的是,没有办法做到这一点。分类是标记的一种形式,在VisualStudio中标记是无序的。编辑器只是为所有标记实现运行导入,基本上默认为MEF导入进行排序

我开发了一个玩具vsix扩展。它为F#源文件实现了一个分类器。 与此同时,来自FSharp Power Tools的人员升级了他们的扩展,为F#文件提供语法高亮显示

现在在VS2013中,我的分类器总是在它们之前运行,因此它们覆盖了我的颜色

有没有一种方法可以根据一个分类器对另一个分类器进行排序?我在谷歌上没有找到任何关于这个的信息


谢谢

不幸的是,没有办法做到这一点。分类是标记的一种形式,在VisualStudio中标记是无序的。编辑器只是为所有标记实现运行导入,基本上默认为MEF导入进行排序


VisualStudio中的许多钩子都可以使用
[Order]
属性进行排序。这通常作为MSDN文档的一部分列出。它不是用于分类/标记的,我检查了实现以确保它不是一个疏忽(不是)

不幸的是,没有办法做到这一点。分类是标记的一种形式,在VisualStudio中标记是无序的。编辑器只是为所有标记实现运行导入,基本上默认为MEF导入进行排序

VisualStudio中的许多钩子都可以使用
[Order]
属性进行排序。这通常作为MSDN文档的一部分列出。它不是用于分类/标记的,我检查了实现以确保它不是一个疏忽(不是)

我已经弄明白了

在我的例子中,优先级.Low必须指定为实现ClassificationFormatDefinition的类的Order属性

实际上,此解决方案仅适用于2个分类器。 FSharp电动工具具有顺序(After=Priority.Default) 当after=Priority.Low时,将在FSharp Power Tools之后调用我的分类器

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "FSharpNumberClassifier")]
[Name("FSharpNumberClassifier")]
[UserVisible(true)] //this should be visible to the end user
[Order(After = Priority.Low)] 
internal sealed class FSharpNumberClassifierFormat : ClassificationFormatDefinition
我已经弄明白了

在我的例子中,优先级.Low必须指定为实现ClassificationFormatDefinition的类的Order属性

实际上,此解决方案仅适用于2个分类器。 FSharp电动工具具有顺序(After=Priority.Default) 当after=Priority.Low时,将在FSharp Power Tools之后调用我的分类器

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "FSharpNumberClassifier")]
[Name("FSharpNumberClassifier")]
[UserVisible(true)] //this should be visible to the end user
[Order(After = Priority.Low)] 
internal sealed class FSharpNumberClassifierFormat : ClassificationFormatDefinition

事实上,我也遇到过类似的问题。我的VSIX扩展通过正则表达式在代码中着色DSL语句。问题在于代码中的注释——它没有避免它们,而编写逻辑来分析所有与注释相关的情况并生成正确的标记是相当多的工作,实际上太多了。所以我想出了一个主意——也许我可以重新安排着色顺序,以便在注释和预处理器指令之前完成着色。然后这些颜色将覆盖我不正确的颜色

我已经在Google上搜索了Order属性,但它在我的例子中不起作用,因为据我记忆所及,我无法将分类类型放在正确的位置,它要么覆盖了注释颜色,要么被其他默认颜色覆盖。我所需要的只是增加注释和预处理器定义的优先级,使它们覆盖我的颜色。这是一个艰难的决定,但对我来说很有效

因此,我得出了以下解决方案。在一个初始化分类格式的类中(在我的例子中是tagger提供程序),我通过MEF添加了ICClassificationFormatMapService服务。另外,我已经有了ICClassificationTypeRegistryService服务来获取ICClassificationType对象

[Import]
internal IClassificationFormatMapService classificationFormatMapService = null; 

[Import]
internal IClassificationTypeRegistryService classificationRegistry = null;
有关预定义分类类型的名称,您需要Microsoft.VisualStudio.Language.StandardClassification nuget软件包。 然后您应该将using指令添加到您的文件中

using Microsoft.VisualStudio.Language.StandardClassification;
然后我使用了以下代码片段:

private static void IncreaseCommentFormatTypesPrioirity(IClassificationTypeRegistryService registry, IClassificationFormatMapService formatMapService,                                                                  
IClassificationType myType)
{
   IClassificationFormatMap formatMap = formatMapService.GetClassificationFormatMap(category: "text");
   IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.ExcludedCode, myType);
   IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.Comment, myType);
}

private static void IncreaseServiceFormatPriority(IClassificationFormatMap formatMap, IClassificationTypeRegistryService registry, string formatName, IClassificationType myType)
{
    IClassificationType predefinedClassificationType = registry.GetClassificationType(formatName);
    IClassificationType artificialClassType = registry.CreateTransientClassificationType(predefinedClassificationType);
    TextFormattingRunProperties properties = formatMap.GetExplicitTextProperties(predefinedClassificationType);

    formatMap.AddExplicitTextProperties(artificialClassType, properties, myType);
    formatMap.SwapPriorities(artificialClassType, predefinedClassificationType);
    formatMap.SwapPriorities(myType, predefinedClassificationType);
}
它对我有用。这是一个实验性的代码,缺乏关于瞬态分类类型和分类顺序的文档,所以我不能100%(甚至90%)肯定它做得很好,不会破坏VS中的某些东西


但是,毕竟您可以在运行时更改分类顺序(尽管您不能明确地说出确切的位置,但必须使用swapriorities方法来更改两种格式的位置)

事实上,我遇到了类似的问题。我的VSIX扩展通过正则表达式在代码中着色DSL语句。问题在于代码中的注释——它没有避免它们,而编写逻辑来分析所有与注释相关的情况并生成正确的标记是相当多的工作,实际上太多了。所以我想出了一个主意——也许我可以重新安排着色顺序,以便在注释和预处理器指令之前完成着色。然后这些颜色将覆盖我不正确的颜色

我已经在Google上搜索了Order属性,但它在我的例子中不起作用,因为据我记忆所及,我无法将分类类型放在正确的位置,它要么覆盖了注释颜色,要么被其他默认颜色覆盖。我所需要的只是增加注释和预处理器定义的优先级,使它们覆盖我的颜色。这是一个艰难的决定,但对我来说很有效

因此,我得出了以下解决方案。在一个初始化分类格式的类中(在我的例子中是tagger提供程序),我通过MEF添加了ICClassificationFormatMapService服务。另外,我已经有了ICClassificationTypeRegistryService服务来获取ICClassificationType对象

[Import]
internal IClassificationFormatMapService classificationFormatMapService = null; 

[Import]
internal IClassificationTypeRegistryService classificationRegistry = null;
有关预定义分类类型的名称,您需要Microsoft.VisualStudio.Language.StandardClassification nuget软件包。 然后您应该将using指令添加到您的文件中

using Microsoft.VisualStudio.Language.StandardClassification;
然后我使用了以下代码片段:

private static void IncreaseCommentFormatTypesPrioirity(IClassificationTypeRegistryService registry, IClassificationFormatMapService formatMapService,                                                                  
IClassificationType myType)
{
   IClassificationFormatMap formatMap = formatMapService.GetClassificationFormatMap(category: "text");
   IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.ExcludedCode, myType);
   IncreaseServiceFormatPriority(formatMap, registry, PredefinedClassificationTypeNames.Comment, myType);
}

private static void IncreaseServiceFormatPriority(IClassificationFormatMap formatMap, IClassificationTypeRegistryService registry, string formatName, IClassificationType myType)
{
    IClassificationType predefinedClassificationType = registry.GetClassificationType(formatName);
    IClassificationType artificialClassType = registry.CreateTransientClassificationType(predefinedClassificationType);
    TextFormattingRunProperties properties = formatMap.GetExplicitTextProperties(predefinedClassificationType);

    formatMap.AddExplicitTextProperties(artificialClassType, properties, myType);
    formatMap.SwapPriorities(artificialClassType, predefinedClassificationType);
    formatMap.SwapPriorities(myType, predefinedClassificationType);
}
它对我有用。这是一个实验性的代码,并且缺乏关于瞬态分类类型和分类顺序的文档,所以我不是100%(甚至90%)su