Export a custom editor at runtime FormDefinition

In the Visual Studio extension that I built, I need to highlight method calls in the Visual Studio editor. For instance:

enter image description here

I would like to use HSV colors to split the color spectrum according to the number of unique calls.

I can achieve the highlight if I export each color as my own FormatDefinition editor:

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "red-background")]
[Name("red-background")]
[UserVisible(true)]
[Order(After = Priority.High)]
public sealed class RedBackground : ClassificationFormatDefinition
{
    public RedBackground()
    {
        DisplayName = "red-background";
        BackgroundColor = Colors.Red;
    }
}

However, for this I need to manually adjust all the colors that I would like to use ahead of time. Is there a way to export EditorFormatDefinitionsat runtime?

Some registries, such as IContentTypeRegistryService and IClassificationTypeRegistryService, allow you to create new types and classifications of content at run time. Is there a similar API for EditorFormatDefinitions.

, MEF ?

+4
1

IClassificationFormatMapService IClassificationFormatMap. TextFormattingRunProperties , IClassificationFormatMap.

//No reason to use identifier, just a default starting point that works for me.
var identiferClassificationType = registryService.GetClassificationType("identifier");
var classificationType = registryService.CreateClassificationType(name, SpecializedCollections.SingletonEnumerable(identiferClassificationType));
var classificationFormatMap = ClassificationFormatMapService.GetClassificationFormatMap(category: "text");
var identifierProperties = classificationFormatMap
    .GetExplicitTextProperties(identiferClassificationType);

//Now modify the properties
var color = System.Windows.Media.Colors.Yellow;
var newProperties = identifierProperties.SetForeground(color);
classificationFormatMap.AddExplicitTextProperties(classificationType, newProperties);

//Now you can use or return classificationType...

- .

+4

All Articles