Set default indent for custom language plugin?

I've created a CustomCodeStyleSetting and both CodeStyleSettingsProvider and LanguageCodeStyleSettingsProvider. The custom CodeStyleSettingsPanel now sets the general indent for my language:

public class MyCodeStyleSettingsPanel extends CodeStyleAbstractPanel {
  public void apply(CodeStyleSettings settings) {
      MyCodeStyleSettings mySettings = settings.getCustomSettings(MyCodeStyleSettings.class);
mySettings.XYZ = getIntValue(myXyz);
      // sync indent settings
CommonCodeStyleSettings.IndentOptions indentOptions = settings.getCommonSettings(MyLanguage.INSTANCE).getIndentOptions();
(indentOptions != null)
          indentOptions.INDENT_SIZE = indentOptions.CONTINUATION_INDENT_SIZE = mySettings.XYZ;

But how (and where) can I set the default indent for my language before the user opens the code style settings dialog for the first time?

Comment actions Permalink

For reference - I think I found the solution.

Instead of LanguageCodeStyleSettings I'm using the FileIndentOptionsProvider extension point, this also handles the indent update of the custom settings:

public class MyFileIndentOptionsProvider extends FileIndentOptionsProvider {
CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull CodeStyleSettings codeStyleSettings,
PsiFile psiFile) {
        if (psiFile instanceof MyFile) {
            CommonCodeStyleSettings.IndentOptions options = new CommonCodeStyleSettings.IndentOptions();
MyCodeStyleSettings customSettings = codeStyleSettings.getCustomSettings(MyCodeStyleSettings.class);
options.INDENT_SIZE = options.CONTINUATION_INDENT_SIZE = customSettings != null ? customSettings.XYZ : 69;
        return null;
Comment actions Permalink

I ended up using the following for my plugin, which seems to work:

langCodeStyleSettingsProvider extension point
class extended from LanguageCodeStyleSettingsProvider

public CommonCodeStyleSettings getDefaultCommonSettings() {
   CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings( getLanguage() );
CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
indentOptions.INDENT_SIZE = 4;
indentOptions.TAB_SIZE = 4;
indentOptions.USE_TAB_CHARACTER = true;

defaultSettings.LINE_COMMENT_AT_FIRST_COLUMN = false;
defaultSettings.KEEP_FIRST_COLUMN_COMMENT = false;

Comment actions Permalink

Thanks for the alternative solution!


Please sign in to leave a comment.