This page is part of multi-step Custom Language Support Tutorial. All previous steps must be executed in sequence for the code to work.
The IntelliJ Platform determines file type by examining the name of a file. Each language has Language and LanguageFileType objects defining the language. Register the LanguageFileType
with the IntelliJ Platform in the plugin configuration file.
The language implemented in this tutorial is named "Simple" - note the case of the name. The SimpleLanguage
class is defined in the org.intellij.sdk.language
package of the simple_language_plugin
code sample:
public class SimpleLanguage extends Language { public static final SimpleLanguage INSTANCE = new SimpleLanguage(); private SimpleLanguage() { super("Simple"); } }
Define an IconThe icon for the Simple Language is defined by the SimpleIcons
class. Please see Working with Icons for details on how to define and use icons.
public class SimpleIcons { public static final Icon FILE = IconLoader.getIcon("/icons/jar-gray.png", SimpleIcons.class); }
Define a File TypeThe SimpleFileType
is defined by subclassing LanguageFileType
:
public final class SimpleFileType extends LanguageFileType { public static final SimpleFileType INSTANCE = new SimpleFileType(); private SimpleFileType() { super(SimpleLanguage.INSTANCE); } @NotNull @Override public String getName() { return "Simple File"; } @NotNull @Override public String getDescription() { return "Simple language file"; } @NotNull @Override public String getDefaultExtension() { return "simple"; } @Override public Icon getIcon() { return SimpleIcons.FILE; } }
Register the File TypeThe Simple Language file type is registered via the com.intellij.fileType
extension point in plugin.xml and registered with *.simple extension:
<extensions defaultExtensionNs="com.intellij"> <fileType name="Simple File" implementationClass="org.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE" language="Simple" extensions="simple"/> </extensions>
Run the ProjectRun the plugin by using the Gradle runIde
task.
Create an empty file with the extension .simple, and IntelliJ IDEA automatically associates it with our language. Note the appearance of the Simple Language file icon next to the test.simple file in the Project Tool Window, and the editor tab for the file.
19 March 2025
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4