Q:

Can't link known file extensions to custom editor classifier

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.

A:

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.

