Skip to content

Add new language support

Stefan Endrullis edited this page Jun 18, 2019 · 20 revisions

To add support for a new language you have to do the following steps:

  • Check out the source code of this plugin and try to compile it via

    ./gradlew buildPlugin

  • Open the project in IDEA and install the following IDEA plugins:

    • PsiViewer
    • Lombok
  • TODO: next steps are outdated and need some revision

  • 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/ except java

      • Open the file plugin.xml and go to the line

        <codeInsight.template.postfixTemplateProvider language="JavaScript"

        and comment out all postfixTemplateProvider for languages other than Java.

    • 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 (path might be different for you depending on your OS and your IDEA version, see here)

      • in this file 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" />
        
      • Save the file and start IDEA again

  • Press the compile button two times (first compilation will fail)

  • Create a new run configuration (Plugin) and name it for instance Plugin

  • Run the plugin project in IDEA to test if the configuration works fine

    • Make sure that the postfix completion works (IDEA must be restarted after the web templates have been enabled for the first time)
  • 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 to src/de/endrullis/idea/postfixtemplates/languages/$languageId by replacing each JavaScript occurrence by your language name or camel case language name (e.g. Sql)

    • create the folder resources/postfixTemplates/Custom${language}StringPostfixTemplate

    • copy all files from resources/postfixTemplates/CustomJavaScriptStringPostfixTemplate to resources/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.