This commit is contained in:
2026-01-29 09:08:29 +08:00
commit fff3c1cc31
15 changed files with 721 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package me.zhouxi.slint
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.util.SystemInfo
import java.nio.file.Path
object SlintRuntime {
val Id = PluginId.getId("me.zhouxi.slint")
val Path: Path = PluginManagerCore.getPlugin(Id)!!.pluginPath
private val BinaryName = if (SystemInfo.isWindows) {
"slint-lsp-windows.exe"
} else if (SystemInfo.isLinux) {
"slint-lsp-linux"
} else if (SystemInfo.isMac) {
"slint-lsp-macos"
} else {
throw RuntimeException("Unsupported OS")
}
val LspExecutable: Path = Path.resolve("lsp").resolve(BinaryName)
}

View File

@@ -0,0 +1,16 @@
package me.zhouxi.slint.icons
import com.intellij.ui.IconManager
import javax.swing.Icon
object SlintIcons {
private fun load(path: String, cacheKey: Int, flags: Int): Icon {
return IconManager.getInstance()
.loadRasterizedIcon(path, SlintIcons::class.java.classLoader, cacheKey, flags)
}
val Primary: Icon = load("icons/slint-logo-small-light.png", 199921742, 2)
}

View File

@@ -0,0 +1,42 @@
package me.zhouxi.slint.lsp
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.LspServer
import com.intellij.platform.lsp.api.LspServerSupportProvider
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.platform.lsp.api.lsWidget.LspServerWidgetItem
import me.zhouxi.slint.SlintRuntime
import me.zhouxi.slint.icons.SlintIcons
class SlintLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(
project: Project,
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter
) {
if (file.extension == "slint") {
serverStarter.ensureServerStarted(FooLspServerDescriptor(project))
}
}
override fun createLspServerWidgetItem(
lspServer: LspServer,
currentFile: VirtualFile?
) =
LspServerWidgetItem(
lspServer, currentFile,
SlintIcons.Primary,
)
private class FooLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Slint") {
override fun isSupportedFile(file: VirtualFile) = file.extension == "slint"
override fun createCommandLine(): GeneralCommandLine {
val line = GeneralCommandLine(SlintRuntime.LspExecutable.toAbsolutePath().toString())
return line
}
}
}

View File

@@ -0,0 +1,19 @@
<idea-plugin>
<id>me.zhouxi.slint</id>
<name>Slint</name>
<vendor url="https://github.com/me0106">me0106</vendor>
<description><![CDATA[
IntelliJ integration of Slint, based on LSP
]]></description>
<depends>com.intellij.modules.lsp</depends>
<!-- Extensions defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<platform.lsp.serverSupportProvider implementation="me.zhouxi.slint.lsp.SlintLspServerSupportProvider"/>
</extensions>
</idea-plugin>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB