-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
package dev.slint.ideaplugin.ide.actions | ||
|
||
import com.intellij.json.JsonLanguage | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.psi.util.elementType | ||
import dev.slint.ideaplugin.ide.lsp.SlintLspServer | ||
import dev.slint.ideaplugin.lang.SlintLanguage | ||
import dev.slint.ideaplugin.lang.psi.SlintFileElementType | ||
import com.intellij.openapi.components.service | ||
import com.intellij.platform.lsp.api.LspServer | ||
import dev.slint.ideaplugin.ide.services.SlintServerService | ||
import javax.swing.Icon | ||
|
||
|
||
abstract class LspAction(text: String, description: String?, icon: Icon?) : AnAction(text, description, icon) { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project ?: return | ||
|
||
val servers = SlintLspServer.getInstances(project) | ||
val servers = project.service<SlintServerService>().getServers() | ||
if (servers.isEmpty()) { | ||
return | ||
} | ||
actionPerformed(e, servers) | ||
} | ||
|
||
abstract fun actionPerformed(e: AnActionEvent, servers: List<SlintLspServer>) | ||
abstract fun actionPerformed(e: AnActionEvent, servers: List<LspServer>) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,76 @@ | ||
package dev.slint.ideaplugin.ide.lsp | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.annotations.JsonAdapter | ||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.platform.lsp.api.Lsp4jClient | ||
import com.intellij.platform.lsp.api.LspServerNotificationsHandler | ||
import org.eclipse.lsp4j.MessageActionItem | ||
import org.eclipse.lsp4j.MessageParams | ||
import org.eclipse.lsp4j.PublishDiagnosticsParams | ||
import org.eclipse.lsp4j.ShowMessageRequestParams | ||
import dev.slint.ideaplugin.SlintBundle | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification | ||
import org.eclipse.lsp4j.services.LanguageClient | ||
import java.util.concurrent.CompletableFuture | ||
import java.lang.reflect.Type | ||
|
||
class LspLanguageClient(serverNotificationsHandler: LspServerNotificationsHandler) : | ||
Lsp4jClient(serverNotificationsHandler) | ||
class LspLanguageClient( | ||
serverNotificationsHandler: LspServerNotificationsHandler, | ||
private val project: Project | ||
) : Lsp4jClient(serverNotificationsHandler) | ||
{ | ||
@JsonNotification("experimental/serverStatus") | ||
fun serverStatus(params: Any) { | ||
println("status") | ||
println(params) | ||
fun serverStatus(status: ServerStatus) { | ||
when (status.health) { | ||
Health.WARNING -> { | ||
NotificationGroupManager.getInstance() | ||
.getNotificationGroup("Slint") | ||
.createNotification( | ||
SlintBundle.message("slint.language.server.status"), | ||
status.message, | ||
NotificationType.WARNING | ||
) | ||
.notify(project) | ||
} | ||
Health.ERROR -> { | ||
NotificationGroupManager.getInstance() | ||
.getNotificationGroup("Slint") | ||
.createNotification( | ||
SlintBundle.message("slint.language.server.status"), | ||
status.message, | ||
NotificationType.ERROR | ||
) | ||
.notify(project) | ||
} | ||
|
||
Health.OK -> {} | ||
} | ||
} | ||
|
||
data class ServerStatus( | ||
@JsonAdapter(EnumDeserializer::class) | ||
val health: Health, | ||
val message: String, | ||
val quiescent: Boolean, | ||
) | ||
|
||
enum class Health { | ||
OK, | ||
WARNING, | ||
ERROR; | ||
} | ||
|
||
class EnumDeserializer<T : Enum<T>>() : JsonDeserializer<T> { | ||
override fun deserialize(json: JsonElement?, typeOfT: Type?, | ||
context: JsonDeserializationContext?): T? { | ||
return json?.asString?.let { | ||
if (it.isNotEmpty()) { | ||
val enumClass = typeOfT as? Class<T> | ||
return enumClass?.enumConstants?.first { | ||
enumValue -> enumValue.name.equals(it, true) } | ||
} else { | ||
return null | ||
} | ||
} | ||
} | ||
} | ||
// override fun telemetryEvent(p0: Any?) { | ||
// TODO("Not yet implemented") | ||
// } | ||
// | ||
// override fun publishDiagnostics(p0: PublishDiagnosticsParams?) { | ||
// TODO("Not yet implemented") | ||
// } | ||
// | ||
// override fun showMessage(p0: MessageParams?) { | ||
// TODO("Not yet implemented") | ||
// } | ||
// | ||
// override fun showMessageRequest(p0: ShowMessageRequestParams?): CompletableFuture<MessageActionItem> { | ||
// TODO("Not yet implemented") | ||
// } | ||
// | ||
// override fun logMessage(p0: MessageParams?) { | ||
// TODO("Not yet implemented") | ||
// } | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.slint.ideaplugin.ide.services | ||
|
||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.platform.lsp.api.LspServer | ||
import com.intellij.platform.lsp.api.LspServerManager | ||
import dev.slint.ideaplugin.SlintBundle | ||
import dev.slint.ideaplugin.ide.lsp.SlintLanguageServer | ||
import dev.slint.ideaplugin.ide.lsp.SlintLspServerSupportProvider | ||
|
||
@Service(Service.Level.PROJECT) | ||
class SlintServerService(private val project: Project) { | ||
fun restartServer() { | ||
LspServerManager.getInstance(project) | ||
Check warning on line 16 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
Check warning on line 16 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
|
||
.stopAndRestartIfNeeded(SlintLspServerSupportProvider::class.java) | ||
Check warning on line 17 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
|
||
} | ||
|
||
fun notifyRestart() { | ||
NotificationGroupManager.getInstance() | ||
.getNotificationGroup("Slint") | ||
.createNotification( | ||
SlintBundle.message("slint.language.server.restarted"), | ||
"", | ||
NotificationType.INFORMATION | ||
) | ||
.notify(project) | ||
} | ||
|
||
fun getServers(): List<LspServer> { | ||
val servers = LspServerManager.getInstance(project) | ||
Check warning on line 32 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
Check warning on line 32 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
|
||
.getServersForProvider(SlintLspServerSupportProvider::class.java) | ||
Check warning on line 33 in src/main/kotlin/dev/slint/ideaplugin/ide/services/SlintServerService.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
|
||
|
||
return servers.filter { it.lsp4jServer is SlintLanguageServer } | ||
} | ||
} |