-
This commit is contained in:
27
src/main/kotlin/me/zhouxi/slint/SlintRuntime.kt
Normal file
27
src/main/kotlin/me/zhouxi/slint/SlintRuntime.kt
Normal 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)
|
||||
}
|
||||
|
||||
|
||||
16
src/main/kotlin/me/zhouxi/slint/icons/SlintIcons.kt
Normal file
16
src/main/kotlin/me/zhouxi/slint/icons/SlintIcons.kt
Normal 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)
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/main/resources/META-INF/plugin.xml
Normal file
19
src/main/resources/META-INF/plugin.xml
Normal 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>
|
||||
BIN
src/main/resources/META-INF/pluginIcon.png
Normal file
BIN
src/main/resources/META-INF/pluginIcon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/main/resources/icons/slint-logo-small-light.png
Normal file
BIN
src/main/resources/icons/slint-logo-small-light.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user