Im working on a plugin for IntelliJ, is there a way to programatically enable/disable actions on save?
Tools β Actions on Save:
-Reformat Code
-Optimize Imports
-Run Code Cleanup
What we want to achieve is when our plugin is installed, based on some criteria enable or disable those settings
Sorry for the delay.
Yes, itβs possible to programatically enable/disable Actions on Save. But Iβd kindly suggest not to do this in a plugin. Itβs extremely unpleasant user experience when project configuration silently changes just because some plugin decided that it knows better how the IDE should be configured. Users may lose their custom configuration, get unexpected changes in configuration files, get unexpected IDE behaviour without any clue why that happened, have no idea how to revert the changes, etc.
Have a look at com.intellij.codeInsight.actions.onSave.FormatOnSaveOptionsBase.DefaultsProvider. By implementing this extension you can specify which file types should have Format on Save and/or Optimize Imports on Save enabled.
1 Like