-
Notifications
You must be signed in to change notification settings - Fork 95
Add new language support
To add support for a new language you have to do the following steps:
- Check out the source code of this plugin
- Open IDEA and install the following IDEA plugins:
- PsiViewer
- Lombok
- Open this project in IDEA and go to the project settings
- Set up the project SDK according to this site (you can skip all steps after Select 1.8 as the default Java SDK)
- The Intellij Platform Plugin SDK should use a JDK 8
- now you have two options:
- SHORT WAY (disable support for all unnecessary languages):
-
Open File → Settings and go to Build, Execution, Deployment → Compiler → Excluded
-
Exclude all sub directories of
src/de/endrullis/idea/postfixtemplates/languages/
exceptjava
-
Open the file
plugin.xml
and go to the line<codeInsight.template.postfixTemplateProvider language="JavaScript"
and comment out all
postfixTemplateProvider
for languages other thanJava
.
-
- LONG WAY (set up the full environment):
-
Install the following IDEA plugins:
- Scala
- Dart
- Python
- PHP
- Rust
-
Close IDEA
-
Open the file
$HOME/.IntelliJIdea2018.3/config/options/jdk.table
and search for the Intellij Platform SDK you are using (e.g. "IntelliJ IDEA IU-183.4588.61") -
Locate the classpath tag and the root child tag and append the following lines inside the root tag:
<root url="jar://$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/lib/javascript-openapi.jar!/" type="simple" /> <root url="jar://$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/lib/JavaScriptLanguage.jar!/" type="simple" /> <root url="jar://$APPLICATION_HOME_DIR$/plugins/Kotlin/lib/kotlin-plugin.jar!/" type="simple" /> <root url="jar://$APPLICATION_HOME_DIR$/plugins/Groovy/lib/Groovy.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/php/lib/php-openapi.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/python/lib/python.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/intellij-rust/lib/intellij-rust-0.2.0.2112-183.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/Dart/lib/Dart.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/Scala/lib/scalaUltimate.jar!/" type="simple" /> <root url="jar://$APPLICATION_PLUGINS_DIR$/Scala/lib/scala-library.jar!/" type="simple" />
-
Start IDEA again
-
- SHORT WAY (disable support for all unnecessary languages):
- run the plugin project in IDEA once to test if the configuration works fine
- Create the necessary folders and files for the new language (in the following I use the variables
$languageId
and$language
as placeholders in path names and file names, whereas$language
denotes the real name, e.g.SQL
, and$languageId
denotes just an ID for the language (usually the lower case variant), e.g.sql
):-
create the folder
src/de/endrullis/idea/postfixtemplates/languages/$languageId
-
copy all classes from
src/de/endrullis/idea/postfixtemplates/languages/javascript
tosrc/de/endrullis/idea/postfixtemplates/languages/$languageId
by replacing each JavaScript occurrence by your language name or camel case language name (e.g.Sql
) -
add your class
${language}Lang
to the listSupportedLanguages.supportedLanguages
. -
create the folder
resources/postfixTemplates/Custom${language}StringPostfixTemplate
-
copy all files from
resources/postfixTemplates/CustomJavaScriptStringPostfixTemplate
toresources/postfixTemplates/Custom${language}StringPostfixTemplate
-
add the following lines to the
plugin.xml
:<codeInsight.template.postfixTemplateProvider language="$language" implementationClass="de.endrullis.idea.postfixtemplates.languages.$languageId.${language}PostfixTemplateProvider"/>
-
- Start the plugin and test if it works by opening any $language file and pressing Shift+Alt+P. If you are offered to create a new template file, the file type detection works.
- Go back to a $language file and try to apply the
.example
template on any expression. If it works all basic steps are done and you have an untyped postfix template support for $language. - You can now try to add a typed postfix template support. I suggest you to install the PsiViewer plugin to analyse the different expression types in IDEA.