IntelliJ Platform Plugin SDK Help

5. Syntax Highlighter and Color Settings Page

The first level of syntax highlighting is based on the lexer output, and is provided by SyntaxHighlighter. A plugin can also define color settings based on ColorSettingPage so the user can configure highlight colors.

Define a Syntax Highlighter

The SimpleSyntaxHighlighter class extends SyntaxHighlighterBase. As recommended in Color Scheme Management, the Simple Language highlighting text attributes are specified as a dependency on one of standard Intellij Platform keys. For the Simple Language, define only one scheme.

Define a Syntax Highlighter Factory

The factory provides a standard way for the IntelliJ Platform to instantiate the syntax highlighter for Simple Language files. Here, SimpleSyntaxHighlighterFactory subclasses SyntaxHighlighterFactory.

Register the Syntax Highlighter Factory

Register the factory with the IntelliJ Platform in the plugin configuration file using the com.intellij.lang.syntaxHighlighterFactory extension point.

<extensions defaultExtensionNs="com.intellij"> <lang.syntaxHighlighterFactory language="Simple" implementationClass="org.intellij.sdk.language.SimpleSyntaxHighlighterFactory"/> </extensions>

Run the Project with Default Colors

Open the example Simple Language properties file (test.simple) in the IDE Development Instance. The colors for Simple Language Key, Separator, and Value highlighting default to the IDE Language Defaults for Keyword, Braces, Operators, and Strings, respectively.

Syntax highlighter

Define a Color Settings Page

The color settings page adds the ability for users to customize color settings for the highlighting in Simple Language files. The SimpleColorSettingsPage implements ColorSettingsPage.

It is supported to group related attributes like operators or braces by separating the nodes with //, e.g.:

AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] { new AttributesDescriptor("Operators//Plus", MySyntaxHighlighter.PLUS), new AttributesDescriptor("Operators//Minus", MySyntaxHighlighter.MINUS), new AttributesDescriptor("Operators//Advanced//Sigma", MySyntaxHighlighter.SIGMA), new AttributesDescriptor("Operators//Advanced//Pi", MySyntaxHighlighter.PI), //... };

Register the Color Settings Page

Register the Simple Language color settings page with the IntelliJ Platform in the plugin configuration file using the com.intellij.colorSettingsPage extension point.

<extensions defaultExtensionNs="com.intellij"> <colorSettingsPage implementation="org.intellij.sdk.language.SimpleColorSettingsPage"/> </extensions>

Run the Project

Run the project by using the Gradle runIde task.

In the IDE Development Instance, open the Simple Language highlight settings page: . Each color initially inherits from a Language Defaults value.

Color Settings Page
Last modified: 29 九月 2022