-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Biome config icons and improve save actions (#119)
Implement an icon provider to display Biome-specific icons for config files. Enhance "Actions on Save" functionality with handlers for formatting, safe fixes, and unsafe fixes.
- Loading branch information
1 parent
7162e61
commit ddd0222
Showing
8 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/github/biomejs/intellijbiome/BiomeConfigIconProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.biomejs.intellijbiome | ||
|
||
import com.intellij.ide.IconProvider | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import javax.swing.Icon | ||
|
||
class BiomeConfigIconProvider : IconProvider() { | ||
override fun getIcon(element: PsiElement, flags: Int): Icon? { | ||
val file = element as? PsiFile ?: return null | ||
if (!file.isValid || file.isDirectory) return null | ||
val virtualFile = file.virtualFile ?: return null | ||
|
||
// Check if the file is a valid Biome config file | ||
if (virtualFile.name.contains(BiomePackage.configName) && | ||
BiomePackage.configValidExtensions.contains(virtualFile.extension) | ||
) { | ||
return BiomeIcons.BiomeIcon | ||
} | ||
|
||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveFormatActionInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.biomejs.intellijbiome.settings | ||
|
||
import com.github.biomejs.intellijbiome.BiomeBundle | ||
import com.github.biomejs.intellijbiome.BiomePackage | ||
import com.intellij.ide.actionsOnSave.ActionOnSaveBackedByOwnConfigurable | ||
import com.intellij.ide.actionsOnSave.ActionOnSaveComment | ||
import com.intellij.ide.actionsOnSave.ActionOnSaveContext | ||
import com.intellij.platform.ide.progress.runWithModalProgressBlocking | ||
|
||
class BiomeOnSaveFormatActionInfo(actionOnSaveContext: ActionOnSaveContext) : | ||
ActionOnSaveBackedByOwnConfigurable<BiomeConfigurable>( | ||
actionOnSaveContext, | ||
BiomeConfigurable.CONFIGURABLE_ID, | ||
BiomeConfigurable::class.java | ||
) { | ||
|
||
override fun getActionOnSaveName() = | ||
BiomeBundle.message("biome.run.format.on.save.checkbox.on.actions.on.save.page") | ||
|
||
override fun isApplicableAccordingToStoredState(): Boolean = | ||
BiomeSettings.getInstance(project).configurationMode != ConfigurationMode.DISABLED | ||
|
||
override fun isActionOnSaveEnabledAccordingToStoredState() = BiomeSettings.getInstance(project).formatOnSave | ||
|
||
override fun isApplicableAccordingToUiState(configurable: BiomeConfigurable): Boolean = | ||
!configurable.disabledConfiguration.isSelected | ||
|
||
override fun isActionOnSaveEnabledAccordingToUiState(configurable: BiomeConfigurable) = | ||
configurable.runFormatOnSaveCheckBox.isSelected | ||
|
||
override fun setActionOnSaveEnabled(configurable: BiomeConfigurable, enabled: Boolean) { | ||
configurable.runFormatOnSaveCheckBox.isSelected = enabled | ||
} | ||
|
||
override fun getActionLinks() = listOf(createGoToPageInSettingsLink(BiomeConfigurable.CONFIGURABLE_ID)) | ||
|
||
override fun getCommentAccordingToUiState(configurable: BiomeConfigurable): ActionOnSaveComment? { | ||
if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) | ||
|
||
val biomePackage = BiomePackage(project) | ||
val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { | ||
biomePackage.versionNumber() | ||
} | ||
return ActionInfo.defaultComment(version, configurable.runForFilesField.text.trim(), isActionOnSaveEnabled) | ||
} | ||
|
||
override fun getCommentAccordingToStoredState(): ActionOnSaveComment? { | ||
if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) | ||
|
||
val biomePackage = BiomePackage(project) | ||
val settings = BiomeSettings.getInstance(project) | ||
val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { | ||
biomePackage.versionNumber() | ||
} | ||
|
||
return ActionInfo.defaultComment(version, settings.filePattern, isActionOnSaveEnabled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters