Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace BiomeRunner with BiomeServerService #124

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ object BiomeBundle : DynamicBundle(BUNDLE) {

@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String,
vararg params: Any) =
getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String,
vararg params: Any) =
getLazyMessage(key, *params)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.intellij.psi.PsiFile
import javax.swing.Icon

class BiomeConfigIconProvider : IconProvider() {
override fun getIcon(element: PsiElement, flags: Int): Icon? {
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
Expand Down
41 changes: 0 additions & 41 deletions src/main/kotlin/com/github/biomejs/intellijbiome/BiomeRunner.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import java.nio.charset.Charset
import kotlin.io.path.Path

class GeneralProcessCommandBuilder : ProcessCommandBuilder {
private val command = GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
private val command =
GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
private var executable: String? = null
private var workingDir: String? = null
private var inputFile: VirtualFile? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.intellij.execution.ExecutionException
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.target.value.TargetValue
import com.intellij.javascript.nodejs.execution.NodeTargetRun
import com.intellij.openapi.project.Project
import com.intellij.javascript.nodejs.execution.NodeTargetRunOptions.Companion.of
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreter
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import java.nio.charset.Charset

Expand Down
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)
}
}
}
}
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)
}
}
}
}
Loading
Loading