-
-
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: Refactor and replace BiomeRunner with BiomeServerService (#124)
Removed BiomeRunner implementations and introduced BiomeServerService to handle formatting, safe fixes, and import sorting using LSP features. Added new actions for safe fixes and import sorting, and updated settings to include extension lists. Minor refactoring and formatting adjustments across various files.
- Loading branch information
1 parent
151efba
commit 7fd7573
Showing
29 changed files
with
554 additions
and
511 deletions.
There are no files selected for viewing
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
41 changes: 0 additions & 41 deletions
41
src/main/kotlin/com/github/biomejs/intellijbiome/BiomeRunner.kt
This file was deleted.
Oops, something went wrong.
94 changes: 0 additions & 94 deletions
94
src/main/kotlin/com/github/biomejs/intellijbiome/BiomeStdinRunner.kt
This file was deleted.
Oops, something went wrong.
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
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/github/biomejs/intellijbiome/actions/BiomeApplySafeFixesAction.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,62 @@ | ||
package com.github.biomejs.intellijbiome.actions | ||
|
||
import com.github.biomejs.intellijbiome.BiomeBundle | ||
import com.github.biomejs.intellijbiome.BiomeIcons | ||
import com.github.biomejs.intellijbiome.services.BiomeServerService | ||
import com.github.biomejs.intellijbiome.services.BiomeServerService.Feature | ||
import com.github.biomejs.intellijbiome.settings.BiomeConfigurable | ||
import com.github.biomejs.intellijbiome.settings.BiomeSettings | ||
import com.intellij.notification.NotificationAction | ||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.options.ShowSettingsUtil | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.platform.ide.progress.runWithModalProgressBlocking | ||
import kotlinx.coroutines.withTimeout | ||
|
||
class BiomeApplySafeFixesAction : AnAction(), DumbAware { | ||
init { | ||
templatePresentation.icon = BiomeIcons.BiomeIcon | ||
} | ||
|
||
override fun actionPerformed(event: AnActionEvent) { | ||
val project = event.project ?: return | ||
val editor = event.getData(CommonDataKeys.EDITOR) ?: return | ||
|
||
val notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("Biome") | ||
|
||
val settings = BiomeSettings.getInstance(project) | ||
val manager = FileDocumentManager.getInstance() | ||
val virtualFile = manager.getFile(editor.document) ?: return | ||
|
||
if (!settings.fileSupported(virtualFile)) { | ||
notificationGroup.createNotification(title = BiomeBundle.message("biome.file.not.supported.title"), | ||
content = BiomeBundle.message("biome.file.not.supported.description", virtualFile.name), | ||
type = NotificationType.WARNING) | ||
.addAction(NotificationAction.createSimple(BiomeBundle.message("biome.configure.extensions.link")) { | ||
ShowSettingsUtil.getInstance().showSettingsDialog(project, BiomeConfigurable::class.java) | ||
}).notify(project) | ||
return | ||
} | ||
|
||
runWithModalProgressBlocking(project, | ||
BiomeBundle.message("biome.run.biome.check.with.features", Feature.ApplySafeFixes.toString())) { | ||
try { | ||
withTimeout(5_000) { | ||
BiomeServerService.getInstance(project).applySafeFixes(editor.document) | ||
} | ||
notificationGroup.createNotification(title = BiomeBundle.message("biome.apply.safe.fixes.success.label"), | ||
content = BiomeBundle.message("biome.apply.safe.fixes.success.description"), | ||
type = NotificationType.INFORMATION).notify(project) | ||
} catch (e: Exception) { | ||
notificationGroup.createNotification(title = BiomeBundle.message("biome.apply.safe.fixes.failure.label"), | ||
content = BiomeBundle.message("biome.apply.safe.fixes.failure.description", e.message.toString()), | ||
type = NotificationType.ERROR).notify(project) | ||
} | ||
} | ||
} | ||
} |
43 changes: 38 additions & 5 deletions
43
src/main/kotlin/com/github/biomejs/intellijbiome/actions/BiomeCheckOnSaveAction.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 |
---|---|---|
@@ -1,18 +1,51 @@ | ||
package com.github.biomejs.intellijbiome.actions | ||
|
||
import com.github.biomejs.intellijbiome.BiomeBundle | ||
import com.github.biomejs.intellijbiome.services.BiomeServerService | ||
import com.github.biomejs.intellijbiome.settings.BiomeSettings | ||
import com.intellij.ide.actionsOnSave.impl.ActionsOnSaveFileDocumentManagerListener | ||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.platform.ide.progress.runWithModalProgressBlocking | ||
import kotlinx.coroutines.withTimeout | ||
|
||
class BiomeCheckOnSaveAction : ActionsOnSaveFileDocumentManagerListener.ActionOnSave() { | ||
override fun isEnabledForProject(project: Project): Boolean { | ||
val settings = BiomeSettings.getInstance(project) | ||
|
||
return settings.applySafeFixesOnSave || settings.applyUnsafeFixesOnSave || settings.formatOnSave | ||
return !BiomeSettings.getInstance(project).getEnabledFeatures().isEmpty() | ||
} | ||
|
||
override fun processDocuments(project: Project, documents: Array<Document>) { | ||
BiomeCheckRunner(project).run(documents) | ||
override fun processDocuments(project: Project, | ||
documents: Array<Document>) { | ||
val features = BiomeSettings.getInstance(project).getEnabledFeatures() | ||
val featuresInfo = features.joinToString(prefix = "(", postfix = ")") { it.toString().lowercase() } | ||
val notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("Biome") | ||
|
||
runWithModalProgressBlocking(project, | ||
BiomeBundle.message("biome.run.biome.check.with.features", featuresInfo)) { | ||
try { | ||
withTimeout(5_000) { | ||
documents.filter { | ||
val settings = BiomeSettings.getInstance(project) | ||
val manager = FileDocumentManager.getInstance() | ||
val virtualFile = manager.getFile(it) ?: return@filter false | ||
return@filter settings.fileSupported(virtualFile) | ||
}.forEach { | ||
BiomeServerService.getInstance(project).executeFeatures(it, features) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
notificationGroup.createNotification( | ||
title = BiomeBundle.message("biome.apply.feature.on.save.failure.label", featuresInfo), | ||
content = BiomeBundle.message( | ||
"biome.apply.feature.on.save.failure.description", | ||
featuresInfo, | ||
e.message.toString() | ||
), | ||
type = NotificationType.ERROR).notify(project) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.