Getting IClassifier to work with custom content type

南楼画角 提交于 2020-01-07 05:46:08

问题


I am trying to add syntax highlighting for a custom content type based on text e.g.

static class RTextContentType
{
    public const string ContentTypeName = Constants.CONTENT_TYPE;
    [Export, Name(ContentTypeName), BaseDefinition("text")]
    internal static ContentTypeDefinition ContentTypeDefinition = null; // set via MEF
}

Then the classifier provider is declared like this,

[Export(typeof(IClassifierProvider)), ContentType(Constants.CONTENT_TYPE)]
class RTextClassifierProvider : IClassifierProvider
{
   ...
}

The problem is, that the constructor of the provider is never get called for my specified extensions. Note here, that I provide the editor factories and the file extensions are associated with the factory. I can see the factory getting initialized through debugging for all associated files.

If I change the content type to "text" the constructor gets called.

So the question is, how can one map a custom content type to a file extension ?

Second note, using FileExtensionToContentTypeDefintion

is not an option, as this does not allow a lot of features..

Thanks for the help :)


回答1:


Your implementation of IVsEditorFactory is responsible for setting the content type of the text displayed in the editor. The default implementation of this interface includes special support for FileExtensionToContentTypeDefinitionAttribute as a simple extension mechanism for users that don't require some of the more advanced features (e.g. projection buffers for multiple content types).

The DjangoEditorFactory class includes a nested class named TextBufferEventListener, which shows one example for how an editor factory might assign the content types to the buffers displayed in an editor window.



来源:https://stackoverflow.com/questions/18400139/getting-iclassifier-to-work-with-custom-content-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!