Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kizeevov committed Mar 22, 2024
1 parent bf10e62 commit 9fd0b40
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 31 deletions.
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.

5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ changelog {
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
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pluginName = SlintPlugin
pluginVersion = 1.0.1
platformType = IU
# platformType = CL
platformVersion = 232-EAP-SNAPSHOT
# platformVersion = 232-EAP-SNAPSHOT
platformVersion = 241-EAP-SNAPSHOT
pluginSinceBuild = 232
pluginUntilBuild =
platformPlugins =
Expand Down
6 changes: 3 additions & 3 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"

#gradleIntelliJPlugin = "1.15.0"
#qodana = "0.1.13"
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/dev/slint/ideaplugin/ide/actions/LspAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ abstract class LspAction(text: String, description: String?, icon: Icon?) : AnAc
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

val servers = project.service<SlintServerService>().getServers()
if (servers.isEmpty()) {
return
}

actionPerformed(e, servers)
// val servers = project.service<SlintServerService>().getServers()
// if (servers.isEmpty()) {
// return
// }
//
// actionPerformed(e, servers)
}

abstract fun actionPerformed(e: AnActionEvent, servers: List<LspServer>)
Expand Down
16 changes: 10 additions & 6 deletions src/main/kotlin/dev/slint/ideaplugin/ide/actions/PreviewAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ 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.openapi.components.service
import com.intellij.openapi.project.DumbAware
import com.intellij.platform.lsp.api.LspServer
import dev.slint.ideaplugin.ide.lsp.requests.PreviewMessageRequest
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
Expand Up @@ -33,24 +33,25 @@ class SlintLspFormattingService : AsyncDocumentFormattingService() {
FormattingOptions(4, true)
)

val server = project.service<SlintServerService>().getServers().firstOrNull() ?: return null
val slintServerService = project.service<SlintServerService>()
// val server = project.service<SlintServerService>().getServers().firstOrNull() ?: return null
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 ->
WriteCommandAction.runWriteCommandAction(project) {
FileEditorService.applyTextChanges(textEdit, editor)
}
}

// val edits = server.sendRequestSync { server -> server.textDocumentService.formatting(params) }
// edits?.forEach { textEdit ->
// WriteCommandAction.runWriteCommandAction(project) {
// FileEditorService.applyTextChanges(textEdit, editor)
// }
// }
}

override fun cancel(): Boolean {
return true
}

}
}

Expand Down
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 = Lsp4jClient(handler)// LspLanguageClient(project)

override fun startServerProcess(): OSProcessHandler =
ServerProcessHandler.addListeners(super.startServerProcess(), project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,20 @@ class SlintServerService(private val project: Project) {
notifyRestart()
}

fun getServers(): List<LspServer> {
fun previewComponent(path: String, component: String) {

}

fun formatting(path: String) {

}

private fun getServers(): List<LspServer> {
val servers = LspServerManager.getInstance(project)
.getServersForProvider(SlintLspServerSupportProvider::class.java)

servers.filter { it.lsp4jServer is SlintLanguageServer }

return servers.filter { it.lsp4jServer is SlintLanguageServer }
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
<separator/>
<add-to-group group-id="ProjectViewPopupMenu"/>

<action id="Slint.Preview" class="dev.slint.ideaplugin.ide.actions.PreviewAction"/>
<action id="Slint.Preview"
class="dev.slint.ideaplugin.ide.actions.PreviewAction"
text="Show All Preview"
icon="AllIcons.Actions.Preview"
/>
</group>

<action id="Slint.RestartLspAction"
Expand Down

0 comments on commit 9fd0b40

Please sign in to comment.