From 923468811b6d9b080bf617624f7e4c86ee579c8d Mon Sep 17 00:00:00 2001 From: Victor Teles Date: Sat, 9 Sep 2023 14:39:51 -0300 Subject: [PATCH] feat(intellij): add server restart action --- editors/intellij/CHANGELOG.md | 7 ++++++ editors/intellij/README.md | 15 ++++++++++++ .../actions/RestartBiomeServerAction.kt | 14 ++++++++--- .../listeners/BiomeConfigListener.kt | 20 ++++++++++++++++ .../lsp/BiomeLspServerSupportProvider.kt | 2 +- .../services/BiomeServerService.kt | 24 +++++++++++++++++++ .../src/main/resources/META-INF/plugin.xml | 4 ++++ .../resources/messages/BiomeBundle.properties | 3 ++- 8 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 editors/intellij/CHANGELOG.md create mode 100644 editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/listeners/BiomeConfigListener.kt create mode 100644 editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/services/BiomeServerService.kt diff --git a/editors/intellij/CHANGELOG.md b/editors/intellij/CHANGELOG.md new file mode 100644 index 000000000000..5bbb9775ef1e --- /dev/null +++ b/editors/intellij/CHANGELOG.md @@ -0,0 +1,7 @@ + + +# intellij-rome Changelog + +## [Unreleased] +### Added +- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template) diff --git a/editors/intellij/README.md b/editors/intellij/README.md index f46264878588..9a32326b9196 100644 --- a/editors/intellij/README.md +++ b/editors/intellij/README.md @@ -1 +1,16 @@ # intellij-biome + + +https://biomejs.dev plugin for JetBrains IDEs. + +## features +- Linting +- Quickfix +- Formatting + + +--- +Plugin based on the [IntelliJ Platform Plugin Template][template]. + +[template]: https://github.com/JetBrains/intellij-platform-plugin-template +[docs:plugin-description]: https://plugins.jetbrains.com/docs/intellij/plugin-user-experience.html#plugin-description-and-presentation diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt index 3f2c7b178b01..cf0febc2cd99 100644 --- a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt @@ -2,9 +2,17 @@ package com.github.biomejs.intellijbiome.actions import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.components.service +import com.github.biomejs.intellijbiome.services.BiomeServerService class RestartBiomeServerAction : AnAction() { - override fun actionPerformed(p0: AnActionEvent) { - TODO("Not yet implemented") + override fun actionPerformed(actionEvent: AnActionEvent) { + val project = actionEvent.project + if (project == null || project.isDefault) return + + val biomeServerService = project.service() + + biomeServerService.restartBiomeServer() + biomeServerService.notifyRestart() } -} \ No newline at end of file +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/listeners/BiomeConfigListener.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/listeners/BiomeConfigListener.kt new file mode 100644 index 000000000000..ddd0ab3a07ba --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/listeners/BiomeConfigListener.kt @@ -0,0 +1,20 @@ +package com.github.biomejs.intellijbiome.listeners + +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.newvfs.BulkFileListener +import com.intellij.openapi.vfs.newvfs.events.VFileEvent +import com.intellij.openapi.components.service +import com.github.biomejs.intellijbiome.services.BiomeServerService + +class BiomeConfigListener(val project: Project) : BulkFileListener { + override fun after(events: MutableList) { + super.after(events) + events.forEach { + if(it.file?.name?.contains("biome.json") == true) { + val biomeServerService = project.service() + + biomeServerService.restartBiomeServer() + } + } + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt index 3b7b0db050f7..575b6eb0f778 100644 --- a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt @@ -29,7 +29,7 @@ class BiomeLspServerSupportProvider : LspServerSupportProvider { private class BiomeLspServerDescriptor(project: Project, val executable: String) : ProjectWideLspServerDescriptor(project, "Biome") { override fun isSupportedFile(file: VirtualFile) = BiomeUtils.isSupportedFileType(file.fileType) override fun createCommandLine(): GeneralCommandLine { - val params = SmartList("lsp-proxy", "--use-server") + val params = SmartList("lsp-proxy") BiomeUtils.attachConfigPath(params, project, thisLogger()) if(executable.isEmpty()) { diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/services/BiomeServerService.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/services/BiomeServerService.kt new file mode 100644 index 000000000000..fd10143b982d --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/services/BiomeServerService.kt @@ -0,0 +1,24 @@ +package com.github.biomejs.intellijbiome.services + +import com.intellij.openapi.components.Service +import com.intellij.openapi.project.Project +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.lsp.BiomeLspServerSupportProvider +import com.intellij.notification.NotificationGroupManager +import com.intellij.notification.NotificationType +import com.intellij.platform.lsp.api.LspServerManager + +@Service(Service.Level.PROJECT) +class BiomeServerService(private val project: Project) { + + fun restartBiomeServer() { + LspServerManager.getInstance(project).stopAndRestartIfNeeded(BiomeLspServerSupportProvider::class.java) + } + + fun notifyRestart(){ + NotificationGroupManager.getInstance() + .getNotificationGroup("Biome") + .createNotification(BiomeBundle.message("biome.language.server.restarted"), "", NotificationType.INFORMATION) + .notify(project) + } +} diff --git a/editors/intellij/src/main/resources/META-INF/plugin.xml b/editors/intellij/src/main/resources/META-INF/plugin.xml index 0a8a9b6120db..a53c00406baf 100644 --- a/editors/intellij/src/main/resources/META-INF/plugin.xml +++ b/editors/intellij/src/main/resources/META-INF/plugin.xml @@ -22,6 +22,10 @@ instance="com.github.biomejs.intellijbiome.settings.BiomeSettingsConfigurable"/> + + +