Skip to content

Commit

Permalink
feat(intellij): add server restart action
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Teles committed Sep 10, 2023
1 parent 001840b commit 9234688
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 5 deletions.
7 changes: 7 additions & 0 deletions editors/intellij/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Keep a Changelog guide -> https://keepachangelog.com -->

# intellij-rome Changelog

## [Unreleased]
### Added
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
15 changes: 15 additions & 0 deletions editors/intellij/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# intellij-biome

<!-- Plugin description -->
https://biomejs.dev plugin for JetBrains IDEs.

## features
- Linting
- Quickfix
- Formatting
<!-- Plugin description end -->

---
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
Original file line number Diff line number Diff line change
Expand Up @@ -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>()

biomeServerService.restartBiomeServer()
biomeServerService.notifyRestart()
}
}
}
Original file line number Diff line number Diff line change
@@ -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<out VFileEvent>) {
super.after(events)
events.forEach {
if(it.file?.name?.contains("biome.json") == true) {
val biomeServerService = project.service<BiomeServerService>()

biomeServerService.restartBiomeServer()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions editors/intellij/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
instance="com.github.biomejs.intellijbiome.settings.BiomeSettingsConfigurable"/>
<formattingService implementation="com.github.biomejs.intellijbiome.formatter.BiomeFormatterProvider"/>
</extensions>
<projectListeners>
<listener class="com.github.biomejs.intellijbiome.listeners.BiomeConfigListener"
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/>
</projectListeners>
<actions>
<group
id="com.github.biomejs.intellijbiome.actions-group"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ biome.formatting.failure=Formatting error
biome.language.server.not.found=Biome language server is not found, make sure you have @biomejs/biome installed.
biome.loading=Biome is loading...
biome.language.server.is.running=Biome server is running
biome.language.server.is.stopped=Biome server is stopped
biome.language.server.is.stopped=Biome server is stopped
biome.language.server.restarted=Biome server restarted

0 comments on commit 9234688

Please sign in to comment.