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

Support idea2024 #41

Merged
merged 1 commit into from
Apr 28, 2024
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
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()

val slintLspVersion = properties("slintLspVersion").get()

Check notice on line 22 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

idea {
module {
Expand Down Expand Up @@ -66,13 +66,12 @@
tasks {
generateLexer {
sourceFile = file("src/main/grammars/SlintLexer.flex")
targetDir = "src/gen/dev/slint/ideaplugin/lang/lexer"
targetClass = "_SlintLexer"
targetOutputDir = file("src/gen/dev/slint/ideaplugin/lang/lexer")
purgeOldFiles = true
}
generateParser {
sourceFile = file("src/main/grammars/SlintParser.bnf")
targetRoot = "src/gen"
targetRootOutputDir = file("src/gen")
pathToParser = "dev/slint/ideaplugin/lang/parser/SlintParser.java"
pathToPsiRoot = "dev/slint/ideaplugin/lang/psi"
purgeOldFiles = true
Expand Down Expand Up @@ -137,21 +136,21 @@
channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
}

task("downloadSlintLspVscodePlugin", type = Download::class) {
src("https://Slint.gallery.vsassets.io/_apis/public/gallery/publisher/Slint/extension/slint/${slintLspVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage")
dest("${project.buildDir}/tmp/slint-${slintLspVersion}-vscode-plugin.zip")
onlyIfModified(true)
}

task("extractSlintLspVscodePlugin", type = Copy::class) {
dependsOn("downloadSlintLspVscodePlugin")
from(zipTree("${project.buildDir}/tmp/slint-${slintLspVersion}-vscode-plugin.zip")) {
destinationDir = file("${project.buildDir}/tmp/slint-vscode-plugin")
}
}
// task("downloadSlintLspVscodePlugin", type = Download::class) {
// src("https://Slint.gallery.vsassets.io/_apis/public/gallery/publisher/Slint/extension/slint/${slintLspVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage")
// dest("${project.buildDir}/tmp/slint-${slintLspVersion}-vscode-plugin.zip")
// onlyIfModified(true)
// }
//
// task("extractSlintLspVscodePlugin", type = Copy::class) {
// dependsOn("downloadSlintLspVscodePlugin")
// from(zipTree("${project.buildDir}/tmp/slint-${slintLspVersion}-vscode-plugin.zip")) {
// destinationDir = file("${project.buildDir}/tmp/slint-vscode-plugin")
// }
// }

prepareSandbox {
dependsOn("extractSlintLspVscodePlugin")
// dependsOn("extractSlintLspVscodePlugin")
from("${project.buildDir}/tmp/slint-vscode-plugin/extension/bin") {
into("${intellij.pluginName.get()}/language-server/bin")
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pluginName = SlintPlugin
pluginVersion = 1.0.2
platformType = IU
# platformType = CL
platformVersion = 232-EAP-SNAPSHOT
pluginSinceBuild = 232
platformVersion = 241-EAP-SNAPSHOT
pluginSinceBuild = 241
pluginUntilBuild =
platformPlugins =
jvmVersion = 17
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
annotations = "24.0.1"

# plugins
kotlin = "1.9.10"
kotlin = "1.9.23"
changelog = "2.2.0"
intellij = "1.16.0"
grammarkit = "2022.3.1"
intellij = "1.17.2"
grammarkit = "2022.3.2.2"
download = "5.6.0"

#gradleIntelliJPlugin = "1.15.0"
Expand All @@ -21,4 +21,4 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
intellij = { id = "org.jetbrains.intellij", version.ref = "intellij" }
grammarkit = { id = "org.jetbrains.grammarkit", version.ref = "grammarkit" }
download = { id = "de.undercouch.download", version.ref = "download"}
download = { id = "de.undercouch.download", version.ref = "download"}
23 changes: 0 additions & 23 deletions src/main/kotlin/dev/slint/ideaplugin/ide/actions/LspAction.kt

This file was deleted.

19 changes: 9 additions & 10 deletions src/main/kotlin/dev/slint/ideaplugin/ide/actions/PreviewAction.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package dev.slint.ideaplugin.ide.actions

import com.intellij.icons.AllIcons
import com.intellij.notification.Notification
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE
import com.intellij.platform.lsp.api.LspServer
import dev.slint.ideaplugin.ide.lsp.requests.PreviewMessageRequest
import com.intellij.openapi.components.service
import dev.slint.ideaplugin.ide.services.SlintServerService
import dev.slint.ideaplugin.lang.SlintLanguage
import kotlin.io.path.Path

internal class PreviewAction(private val notification: Notification? = null) :
LspAction("Show All Preview", null, AllIcons.Actions.Preview) {
internal class PreviewAction : AnAction() {

override fun update(e: AnActionEvent) {
val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return
e.presentation.isEnabledAndVisible = psiFile.language.isKindOf(SlintLanguage.INSTANCE)
}

override fun actionPerformed(e: AnActionEvent, servers: List<LspServer>) {
override fun actionPerformed(e: AnActionEvent) {
val virtualFile = e.getData(VIRTUAL_FILE) ?: return
val uriFile = Path(virtualFile.path).toUri()

val request = PreviewMessageRequest(servers.first(), uriFile.toString(), "")
servers.first().requestExecutor.sendRequestSync(request)
val project = e.project ?: return
val slintServerService = project.service<SlintServerService>()

notification?.expire()
slintServerService.previewComponent(uriFile.toString(), "")
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package dev.slint.ideaplugin.ide.actions

import com.intellij.icons.AllIcons
import com.intellij.notification.Notification
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.platform.lsp.api.LspServer
import dev.slint.ideaplugin.ide.lsp.requests.PreviewMessageRequest
import com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE
import com.intellij.openapi.components.service
import dev.slint.ideaplugin.ide.services.SlintServerService
import kotlin.io.path.Path

internal class PreviewComponentAction(
private val componentName: String,
private val notification: Notification? = null,
) :
LspAction("Show Component Preview", null, AllIcons.Actions.ShowCode) {
override fun actionPerformed(e: AnActionEvent, servers: List<LspServer>) {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return

internal class PreviewComponentAction(private val componentName: String) :
AnAction("Show Component Preview", null, AllIcons.Actions.ShowCode) {

override fun actionPerformed(e: AnActionEvent) {
val virtualFile = e.getData(VIRTUAL_FILE) ?: return
val uriFile = Path(virtualFile.path).toUri()

val request = PreviewMessageRequest(servers.first(), uriFile.toString(), componentName)
servers.first().requestExecutor.sendRequestSync(request)
val project = e.project ?: return
val slintServerService = project.service<SlintServerService>()

notification?.expire()
slintServerService.previewComponent(uriFile.toString(), componentName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@ class SlintLspFormattingService : AsyncDocumentFormattingService() {

val uriFile = Path(file.path).toUri()

val params = DocumentFormattingParams(
TextDocumentIdentifier(uriFile.toString()),
FormattingOptions(4, true)
)

val server = project.service<SlintServerService>().getServers().firstOrNull() ?: return null
val slintServerService = project.service<SlintServerService>()
val fileEditorManager = FileEditorManager.getInstance(project)
val editor = fileEditorManager.selectedTextEditor ?: return null

return object : FormattingTask {
override fun run() {
val edits = server.lsp4jServer.textDocumentService.formatting(params).join()
edits.forEach { textEdit ->
val edits = slintServerService.formatting(uriFile.toString(), 4, true)

edits?.forEach { textEdit ->
WriteCommandAction.runWriteCommandAction(project) {
FileEditorService.applyTextChanges(textEdit, editor)
}
Expand All @@ -50,7 +46,6 @@ class SlintLspFormattingService : AsyncDocumentFormattingService() {
override fun cancel(): Boolean {
return true
}

}
}

Expand Down
107 changes: 1 addition & 106 deletions src/main/kotlin/dev/slint/ideaplugin/ide/lsp/LspLanguageClient.kt
Original file line number Diff line number Diff line change
@@ -1,116 +1,11 @@
package dev.slint.ideaplugin.ide.lsp

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.platform.lsp.api.Lsp4jClient
import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import dev.slint.ideaplugin.ide.services.FileEditorService
import org.eclipse.lsp4j.*
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
import java.util.concurrent.CompletableFuture

class LspLanguageClient(project: Project) :
Lsp4jClient(LspServerNotificationsMiddleware(project)) {
class LspLanguageClient(handler: LspServerNotificationsHandler) : Lsp4jClient(handler) {
@JsonNotification("experimental/serverStatus")
fun serverStatus(status: Any?) {
}
}


class LspServerNotificationsMiddleware(
project: Project
) : LspServerNotificationsHandler {
private val fileEditorService = project.service<FileEditorService>()

override fun applyEdit(params: ApplyWorkspaceEditParams): CompletableFuture<ApplyWorkspaceEditResponse> {
fileEditorService.applyEdit(params)
return CompletableFuture.supplyAsync {
ApplyWorkspaceEditResponse(true)
}
}

override fun configuration(params: ConfigurationParams): CompletableFuture<List<Any?>> {
return CompletableFuture.supplyAsync {
null
}
}

override fun createProgress(params: WorkDoneProgressCreateParams): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun logMessage(params: MessageParams) {}

override fun logTrace(params: LogTraceParams) {}

override fun notifyProgress(params: ProgressParams) {}

override fun publishDiagnostics(params: PublishDiagnosticsParams) {}

override fun refreshCodeLenses(): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun refreshDiagnostics(): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun refreshInlayHints(): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun refreshInlineValues(): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun refreshSemanticTokens(): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun registerCapability(params: RegistrationParams): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun showDocument(params: ShowDocumentParams): CompletableFuture<ShowDocumentResult> {
fileEditorService.showDocument(params)
return CompletableFuture.supplyAsync {
ShowDocumentResult(true)
}
}

override fun showMessage(params: MessageParams) {}

override fun showMessageRequest(params: ShowMessageRequestParams): CompletableFuture<MessageActionItem> {
return CompletableFuture.supplyAsync {
null
}
}

override fun telemetryEvent(`object`: Any) {}

override fun unregisterCapability(params: UnregistrationParams): CompletableFuture<Void> {
return CompletableFuture.supplyAsync {
null
}
}

override fun workspaceFolders(): CompletableFuture<List<WorkspaceFolder>> {
return CompletableFuture.supplyAsync {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescripto

override fun createInitializationOptions(): Any = SlintSettingsState.getInstance().lspSettings

override fun createLsp4jClient(handler: LspServerNotificationsHandler): Lsp4jClient = LspLanguageClient(project)
override fun createLsp4jClient(handler: LspServerNotificationsHandler): Lsp4jClient = LspLanguageClient(handler)

override fun startServerProcess(): OSProcessHandler =
ServerProcessHandler.addListeners(super.startServerProcess(), project)
Expand Down

This file was deleted.

Loading
Loading