Skip to content

Commit

Permalink
fix: revert "format on save" (#117)
Browse files Browse the repository at this point in the history
* fix: revert "format on save"
  • Loading branch information
denbezrukov authored Jan 7, 2025
1 parent 07796bf commit f1dd11d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BiomeCheckOnSaveAction : ActionsOnSaveFileDocumentManagerListener.ActionOn
override fun isEnabledForProject(project: Project): Boolean {
val settings = BiomeSettings.getInstance(project)

return settings.applySafeFixesOnSave || settings.applyUnsafeFixesOnSave
return settings.applySafeFixesOnSave || settings.applyUnsafeFixesOnSave || settings.formatOnSave
}

override fun processDocuments(project: Project, documents: Array<Document>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class BiomeConfigurable(internal val project: Project) :
HELP_TOPIC,
CONFIGURABLE_ID
) {
lateinit var runFormatOnSaveCheckBox: JCheckBox
lateinit var enableLspFormatCheckBox: JCheckBox
lateinit var runSafeFixesOnSaveCheckBox: JCheckBox
lateinit var runUnsafeFixesOnSaveCheckBox: JCheckBox
Expand Down Expand Up @@ -140,7 +141,7 @@ class BiomeConfigurable(internal val project: Project) :
}.enabledIf(!disabledConfiguration.selected)

// *********************
// Format on save row
// LSP row
// *********************
row {
enableLspFormatCheckBox = checkBox(BiomeBundle.message("biome.enable.lsp.format.label"))
Expand All @@ -151,6 +152,26 @@ class BiomeConfigurable(internal val project: Project) :
))
.component

val helpLabel = ContextHelpLabel.create(BiomeBundle.message("biome.enable.lsp.format.help.label"))
helpLabel.border = JBUI.Borders.emptyLeft(UIUtil.DEFAULT_HGAP)
cell(helpLabel)

val link = ActionsOnSaveConfigurable.createGoToActionsOnSavePageLink()
cell(link)
}.enabledIf(!disabledConfiguration.selected)

// *********************
// Format on save row
// *********************
row {
runFormatOnSaveCheckBox = checkBox(BiomeBundle.message("biome.run.format.on.save.label"))
.bindSelected(RunOnObservableProperty(
{ settings.configurationMode != ConfigurationMode.DISABLED && settings.formatOnSave },
{ settings.formatOnSave = it },
{ !disabledConfiguration.isSelected && runFormatOnSaveCheckBox.isSelected }
))
.component

val link = ActionsOnSaveConfigurable.createGoToActionsOnSavePageLink()
cell(link)
}.enabledIf(!disabledConfiguration.selected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class BiomeSettings :
state.enableLspFormat = value
}

var formatOnSave: Boolean
get() = isEnabled() && state.formatOnSave
set(value) {
state.formatOnSave = value
}

var applySafeFixesOnSave: Boolean
get() = isEnabled() && state.applySafeFixesOnSave
set(value) {
Expand All @@ -61,7 +67,9 @@ class BiomeSettings :

fun getEnabledFeatures(): EnumSet<Feature> {
val features = EnumSet.noneOf(Feature::class.java)

if (formatOnSave) {
features.add(Feature.Format)
}
if (applySafeFixesOnSave) {
features.add(Feature.SafeFixes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BiomeSettingsState : BaseState() {
var executablePath by string()
var configPath by string()
var filePattern by string(DEFAULT_FILE_PATTERN)
var formatOnSave by property(false)
var enableLspFormat by property(false)
var applySafeFixesOnSave by property(false)
var applyUnsafeFixesOnSave by property(false)
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/messages/BiomeBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ biome.version=Resolving Biome version...
biome.run.format.for.files.label=Run biome for &files:
biome.enable.lsp.format.label=Enable LSP-based code formatting
biome.run.safe.fixes.on.save.label=Run safe fixes on &save
biome.run.format.on.save.label=Run format on &save
biome.run.unsafe.fixes.on.save.label=Run unsafe fixes on &save
biome.run.format.on.save.checkbox.on.actions.on.save.page=Run Biome check
biome.run.safe.fixes.on.save.checkbox.on.actions.on.save.page=Run Biome check with --apply
Expand All @@ -18,3 +19,13 @@ biome.run.biome.check.with.features=Running Biome check with {0}
biome.failed.to.run.biome.check.with.features=Failed to run Biome check with {0} for file {1}
biome.run.on.save.package.not.specified.warning=Biome package not specified
biome.run.on.save.version.and.files.pattern=Version {0}. Run for: {1}
biome.enable.lsp.format.help.label=<html>If LSP formatting is enabled, you can use it as a Save Action in IntelliJ:<ul> \
<li>Open <b>Preferences/Settings</b> in IntelliJ.</li> \
<li>Navigate to <b>Tools > Actions on Save</b>.</li> \
<li>Enable the option <b>Reformat Code</b>.</li> \
<li>Add the appropriate file extensions for reformatting.</li> \
</ul> \
<p>This setup allows automatic LSP-based code formatting on save.</p> \
<p>This feature also allows you to format code using the designated hotkey (<b>Alt+Shift+Command+L</b> on Mac or <b>Ctrl+Alt+L</b> on Windows/Linux).</p></html>


0 comments on commit f1dd11d

Please sign in to comment.