0

I am working on an editor classifier extension for classic Visual Basic source files (module- and class files). The project has been created using the editor classifier project template from the Visual Studio 2012 SDK. The wizard created three code files: one for the classifier, one for the classifier-format and -provider and another one containing classification definitions. I made the following changes to the last one in order to link *.bas and *.cls files to my custom classifier...

using System.ComponentModel.Composition;

using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

internal static class MyEditorClassifierClassificationDefinition
{
    [Export(typeof(ClassificationTypeDefinition))]
    [Name("MyEditorClassifier")]
    internal static ClassificationTypeDefinition MyEditorClassifierType = null;

    [Export]
    [Name("custom")]
    [BaseDefinition("code")]
    internal static ContentTypeDefinition MyContentDefinition = null;

    [Export]
    [FileExtension(".bas")]
    [ContentType("custom")]
    internal static FileExtensionToContentTypeDefinition MyModuleFileExtensionDefinition = null;

    [Export]
    [FileExtension(".cls")]
    [ContentType("custom")]
    internal static FileExtensionToContentTypeDefinition MyClassFileExtensionDefinition = null;
}

The problem is, that Visual Studio does not invoke my classifier for files having *.bas, or *.cls extensions, instead the built-in editor for Visual Basic is used. I already tested my editor classifier using a custom file extension; in that case the classifier works as expected. I would like to know, if it's possible to change the classifier for known file extensions.

Matze
  • 5,100
  • 6
  • 46
  • 69
  • We already define .bas and .cls to map to the Basic content type, along with the standard .vb extension. What are you actually trying to do here? Why aren't you just defining your classifier on the "Basic" content type? – Jason Malinowski Jul 11 '13 at 01:31
  • I know that those file types are mapped to the Basic content type; and I also tried to use "Basic" as the base definition for my classifier, but it didn´t work either. Beside that the Basic editor does not handle .bas and .cls files correctly; those files have a header containing metadata (I would like to use a Projection to hide those headers from the editor, but that´s a dream of the future). – Matze Jul 11 '13 at 09:13

1 Answers1

1

I found an intresting solution for classifying keywors are already classifyed by a language service. It's description says it uses a Tagger to enhance code highlighting. Maybe it can help you: KeywordClassifier Older version of the linked project used a classifier mentioned in the description.

You can get the name of the loaded document, also the extension with ITextDocumentFactoryService or maybe there is a way to bind the tagger also to extensions not only to the content type of Basic (instead of code). FileExtensionAttribute may help.

Ursegor
  • 878
  • 8
  • 16