Proper registration of Syntax coloring components for custom language plugins.

Hi,

A friend of mine and I have been trying to develop a custom language plugin for OpenGL Shading Language (GLSL).
This plugin started out as a 7.0 plugin but we have now moved over to 8.0.

I see that a lot of stuff has been moved from the Language class to the plugin.xml file instead.
The question is; is it possible to register all classes necessary for syntax highlighting in the xml file or is some "manual" registration still required in the code?
Our current extensions in the xml file are currently:

<fileTypeFactory implementation="glslplugin.GLSLSupportLoader" />
<colorSettingsPage implementation="glslplugin.GLSLColorAndFontsPage" />
<syntaxHighlighter key="GLSL" factoryClass="glslplugin.GLSLHighlighterFactory" />


I added the <syntaxHighlighter ...> in the xml file to register the glsl syntax highlighter but using the debugger it becomes apparent the the GLSLFactory is never instantiated. The syntax highlighting is still working in the color settings page though.
Furthermore what does the key attribute refer to and which class is GLSLFactory supposed to be a subclass of? Looking at the source code for the JS plugin its SyntaxHighlighterProvider, but if it's never instantiated, what use is it?

For now we have a explicit registration of the syntax highlighter in the GLSLLanguage constructor and it seems to work.
What are the minimum set of components needed for syntax coloring and how are they registered with IDEA (preferably using the xml file)?

Thanks in advance,

best regards,

Yngve D Hammersland

5 comments
Comment actions Permalink

Hello Yngve,

The correct registration is:

<lang.syntaxHighlighterFactory key="GLSL" implementationClass="GLSLHighlighterFactory"/>

where the key matches the name of the file type (rather than language), and
GLSLHighlighterFactory extends SyntaxHighlighterFactory.

All language components can be registered in plugin.xml - there's no need
to do manual registration from code.

A friend of mine and I have been trying to develop a custom language
plugin for OpenGL Shading Language (GLSL).

This plugin started out as a 7.0 plugin but we have now moved over to
8.0.

I see that a lot of stuff has been moved from the Language class to
the plugin.xml file instead.

The question is; is it possible to register all classes necessary for
syntax highlighting in the xml file or is some "manual" registration
still required in the code?

Our current extensions in the xml file are currently:

 implementation="glslplugin.GLSLSupportLoader" />
> 
>  />
> 
>  factoryClass="glslplugin.GLSLHighlighterFactory" />]]>


I added the <syntaxHighlighter ...> in the xml file to register the
glsl syntax highlighter but using the debugger it becomes apparent the
the GLSLFactory is never instantiated. The syntax highlighting is
still working in the color settings page though.

Furthermore what does the key attribute refer to and which class is
GLSLFactory supposed to be a subclass of? Looking at the source code
for the JS plugin its SyntaxHighlighterProvider, but if it's never
instantiated, what use is it?

For now we have a explicit registration of the syntax highlighter in
the GLSLLanguage constructor and it seems to work.

What are the minimum set of components needed for syntax coloring and
how are they registered with IDEA (preferably using the xml file)?

Thanks in advance,

best regards,

Yngve D Hammersland

---
Original message URL:
http://www.jetbrains.net/devnet/message/5230287#5230287

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi

As far as i understand, "key" attribute for syntaxHighlighter extension should be equal to your language name (what you pass to Language constructor in your Language implementation).
Also, here http://svn.jetbrains.org/idea/BRANCHES/DianaFinal/bundled/groovy/src/META-INF/plugin.xml and in my plugin i use "implementationClass" attribute to point to implementation and not "factoryClass", and that works for me.

Try looking at groovy plugin sources:
http://svn.jetbrains.org/idea/BRANCHES/DianaFinal/bundled/groovy/src/META-INF/plugin.xml
http://svn.jetbrains.org/idea/BRANCHES/DianaFinal/bundled/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovySyntaxHighlighter.java
http://svn.jetbrains.org/idea/BRANCHES/DianaFinal/bundled/groovy/src/org/jetbrains/plugins/groovy/GroovyLanguage.java


best,
jay

0
Comment actions Permalink

Hi,

I tried the implementationClass attribute and pointing it directly at the GLSLSyntaxHighlighter class but still no luck.
(It still doesn't instantiate the highlighter at all)

My xml which I try to keep at a minimum is currently:

<!DOCTYPE idea-plugin PUBLIC "Plugin/DTD" "http://plugins.intellij.net/plugin.dtd" >
<idea-plugin>
    <name>GLSL Support</name>
    <id>GLSL</id>
    <description>Support for the OpenGL Shading Language</description>
    <version>1.0</version>
    <vendor>Foundation</vendor>
    <idea-version since-build="8000"/>

    <extensions defaultExtensionNs="com.intellij">
        <fileTypeFactory implementation="glslplugin.GLSLSupportLoader" />
        <colorSettingsPage implementation="glslplugin.GLSLColorAndFontsPage" />
        <syntaxHighlighter key="GLSL" implementationClass="glslplugin.GLSLHighlighter" />
    </extensions>
</idea-plugin>

The fileTypeFactory is working as I get the correct icons on the file and the color settings page is working. The grammar also works when I add it to the xml.
My GLSLLanguage class (I commented out the registration of the highlighter to try to make it work with xml only):

public class GLSLLanguage extends Language {
    public GLSLLanguage() {
        super("GLSL");
//        SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new GLSLHighlighterFactory());
    }
}

and my GLSLHighlighter class:

public class GLSLHighlighter extends SyntaxHighlighterBase {
    static final TextAttributesKey GLSL_NUMBER = ...;
    static final TextAttributesKey GLSL_TYPE_SPECIFIER = ...;
    static final TextAttributesKey GLSL_TYPE_QUALIFIERS = ...;
    static final TextAttributesKey GLSL_PARAMETER_QUALIFIERS = ...;
    static final TextAttributesKey GLSL_FLOW_KEYWORDS = ...;
    static final TextAttributesKey GLSL_COMMENT = ...;
    static final TextAttributesKey GLSL_IDENTIFIER = ...;
    static final TextAttributesKey GLSL_COMPILER_DIRECTIVE = ...;
    static final TextAttributesKey GLSL_UNKNOWN = ...;

    @NotNull
    public Lexer getHighlightingLexer() {
        return new GLSLFlexAdapter();
    }

    @NotNull
    public TextAttributesKey[] getTokenHighlights(IElementType type) {
        if (type == INTEGER_CONSTANT || type == FLOAT_CONSTANT || type == BOOL_CONSTANT) {
            return new TextAttributesKey[]{GLSL_NUMBER};
        } else if (type == COMMENT_BLOCK || type == COMMENT_LINE) {
            return new TextAttributesKey[]{GLSL_COMMENT};
        } else if (type == IDENTIFIER) {
            return new TextAttributesKey[]{GLSL_IDENTIFIER};
        } else if (type == COMPILER_DIRECTIVE) {
            return new TextAttributesKey[]{GLSL_COMPILER_DIRECTIVE};
        } else if (TYPE_SPECIFIER_NONARRAY_TOKENS.contains(type)) {
            return new TextAttributesKey[]{GLSL_TYPE_SPECIFIER};
        } else if (TYPE_QUALIFIERS.contains(type)) {
            return new TextAttributesKey[]{GLSL_TYPE_QUALIFIERS};
        } else if (PARAMETER_QUALIFIERS.contains(type)) {
            return new TextAttributesKey[]{GLSL_PARAMETER_QUALIFIERS};
        } else if(FLOW_KEYWORDS.contains(type)) {
            return new TextAttributesKey[]{GLSL_FLOW_KEYWORDS};
        } else if (type == UNKNOWN) {
            return new TextAttributesKey[]{GLSL_UNKNOWN};
        }
        return new TextAttributesKey[]{TextAttributesKey.createTextAttributesKey("GLSL.TEXT", new TextAttributes(Color.BLACK, null, null, null, Font.PLAIN))};
    }
}


Any ideas?

regards,

Yngve

0
Comment actions Permalink

Great! Thanks, now it works.

I'm qurious on one more thing though. Why doesn't the lang.syntaxHighlighterFactory have a "lang" attribute like the other extension points? I would be great to have that kind of consistency.

regards,

- Yngve D. Hammersland

0
Comment actions Permalink

Hello Yngve,

I'm qurious on one more thing though. Why doesn't the
lang.syntaxHighlighterFactory have a "lang" attribute like the other
extension points? I would be great to have that kind of consistency.


Because the syntax highlighters are registered per file type and not per
language (for example, it's possible to register a syntax highlighter for
a file type hich doesn't have an associated language - for example, IDEA
custom file types use this possibility).

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.