Jakub Chrzanowski 4e802980f2
Webhelp migration (#347)
* [webhelp] Fixes for TXP00152, TXP00002, test build 27 Jul 22:26

* [webhelp] Fixes for Part #4 TXP00010, EXCEPT decimal numbers in section titles

* [webhelp] Fixes for Part #5 TXP00017

* [webhelp] Fixes for Part #4 TXP00010 - removed numbers from page section titles in "Custom Language Support Tutorial" and "Testing a Custom Language Plugin".

* [webhelp] Removed numbers from page section titles in rest of project *.md files.

* [new webhelp] Build #44 changes

* [new webhelp] Maintenance merge from master

* [new webhelp] Add placeholder file for webhelp import.

* [webhelp] Correct redirects for file name changes

* [webhelp] TOC not needed in webhelp

* [format] {:toc} not needed for webhelp

* add {:disable-links} to ensure demo links are not interpreted as real links.

* Put all badges on the same line to simplify composition.

* formatter.md: fix upsource link

* fix some links

* api_changes_list.md: remove note

* migrate to webhelp - initial

* fix GH edit URL

* remove sdkdocs-template setup in VCS config

* remove recently_updated.md

* restore COC/CONTRIBUTING.md

* api_changes_list.md: remove note

* useful_links.md: IPE

Co-authored-by: JohnHake <john.hake@jetbrains.com>
Co-authored-by: Yann Cébron <yann.cebron@jetbrains.com>
2021-01-14 16:07:39 +01:00

2.3 KiB

The IntelliJ Platform includes a powerful framework for implementing formatting for custom languages. A formatter enables reformatting code automatically based on code style settings. The formatter controls spaces, indents, wrap, and alignment.

Reference: Code Formatter

Define a Block

The formatting model represents the formatting structure of a file as a tree of Block objects, with associated indent, wrap, alignment and spacing settings. The goal is to cover each PSI element with such a block. Since each block builds its children's blocks, it can generate extra blocks or skip any PSI elements. Define SimpleBlock based on AbstractBlock.

{src="simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleBlock.java"}

Define a Formatting Model Builder

Define a formatter that removes extra spaces except for the single spaces around the property separator. For example, reformat "foo =     bar" to "foo = bar".

Create SimpleFormattingModelBuilder by subclassing FormattingModelBuilder.

{src="simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFormattingModelBuilder.java"}

Register the Formatter

The SimpleFormattingModelBuilder implementation is registered with the IntelliJ Platform in the plugin configuration file using the com.intellij.lang.formatter extension point.

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

Run the Project

Add some extra spaces around the = separator between language and English. Reformat the code by selecting Code | Show Reformat File Dialog and choose Run.

Formatter