Skip to content

Commit

Permalink
Binary executable files of lsp-server are embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
kizeevov committed Mar 17, 2024
1 parent e0ce2cf commit a9a4d39
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

## [Unreleased]

### Attention

- The current version is not compatible with previous plugin settings

### Fixed

- Fixed ternary expressions
- Binary executable files of lsp-server are embedded

## [0.3.1] - 2023-12-16

Expand Down
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ tasks {
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
}

prepareSandbox {
from("${project.projectDir}/language-server") {
into("${intellij.pluginName.get()}/language-server/")
}
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/slint/ideaplugin/SlintBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import org.jetbrains.annotations.PropertyKey
@NonNls
const val SLINT_BUNDLE = "messages.SlintBundle"

object SlintBundle : DynamicBundle(SLINT_BUNDLE) {
@NonNls
const val SLINT_PLUGIN_ID = "dev.slint.ideaplugin"

object SlintBundle : DynamicBundle(SLINT_BUNDLE) {
@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = SLINT_BUNDLE) key: String, vararg params: Any) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.slint.ideaplugin.ide.lsp

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.ide.plugins.PluginManager
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.Lsp4jClient
Expand All @@ -9,18 +11,21 @@ import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.platform.lsp.api.customization.LspCompletionSupport
import dev.slint.ideaplugin.ide.settings.SlintBackend
import dev.slint.ideaplugin.ide.settings.SlintState
import dev.slint.ideaplugin.ide.settings.SlintSettingsState
import dev.slint.ideaplugin.ide.settings.SlintStyle
import dev.slint.ideaplugin.lang.SlintFileType
import org.eclipse.lsp4j.services.LanguageServer
import com.intellij.openapi.util.SystemInfo
import dev.slint.ideaplugin.SlintBundle
import java.nio.file.Path

@Suppress("UnstableApiUsage")
class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Slint") {

override fun isSupportedFile(file: VirtualFile) = file.fileType == SlintFileType

override fun createCommandLine(): GeneralCommandLine {
val settingState = SlintState.getInstance().lspSettings
val settingState = SlintSettingsState.getInstance().lspSettings

val parameters = mutableListOf<String>()
if (settingState.args.isNotEmpty()) {
Expand Down Expand Up @@ -49,14 +54,59 @@ class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescripto
parameters.add("--no-toolbar")
}

return GeneralCommandLine(settingState.path).apply {
val path = if (settingState.useExternalLsp) {
settingState.path
} else {
getEmbeddedLspPath().toString()
}

return GeneralCommandLine(path).apply {
addParameters(parameters)
withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
withCharset(Charsets.UTF_8)
}
}

override fun createInitializationOptions(): Any = SlintState.getInstance().lspSettings
private fun getEmbeddedLspPath(): Path? {
val pluginPath = PluginManager
.getInstance()
.findEnabledPlugin(PluginId.getId(dev.slint.ideaplugin.SLINT_PLUGIN_ID))
?.pluginPath

val programName: String

if (SystemInfo.isMac) {
programName = "Slint Live Preview.app/Contents/MacOS/slint-lsp"
} else if (SystemInfo.isLinux) {
programName = when (SystemInfo.OS_ARCH) {
"x64" -> {
"slint-lsp-x86_64-unknown-linux-gnu"
}

"arm" -> {
"slint-lsp-armv7-unknown-linux-gnueabihf"
}

"arm64" -> {
"slint-lsp-aarch64-unknown-linux-gnu"
}

else -> {
return null
}
}
} else if (SystemInfo.isWindows) {
programName = "slint-lsp-x86_64-pc-windows-msvc.exe"
} else {
return null
}

return pluginPath
?.resolve("language-server/bin")
?.resolve(programName)
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package dev.slint.ideaplugin.ide.settings

import java.util.*

data class SlintLspSettings (
data class SlintLspSettings (
var path: String = "slint-lsp",
var args: String = "",
var style: SlintStyle = SlintStyle.DEFAULT,
var backend: SlintBackend = SlintBackend.DEFAULT,
var noToolbar: Boolean = false,
var includePaths: MutableList<String> = mutableListOf(),
var useExternalLsp: Boolean = false
)

enum class SlintStyle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.slint.ideaplugin.ide.settings

import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.dsl.builder.*

class SlintSettingsComponent(lspSettings: SlintLspSettings) {
Expand All @@ -9,9 +10,16 @@ class SlintSettingsComponent(lspSettings: SlintLspSettings) {
init {
panel = panel {
group("Lsp Settings") {
lateinit var useExternalLspCheckBox: Cell<JBCheckBox>

row {
useExternalLspCheckBox = checkBox("Use external lsp")
.bindSelected(lspSettings::useExternalLsp)
}
row("Lsp path:") {
textFieldWithBrowseButton()
.bindText(lspSettings::path)
.enabledIf(useExternalLspCheckBox.selected)
.align(AlignX.FILL)
}
row("Args:") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SlintSettingsConfigurable(internal val project: Project) : Configurable, S
override fun getId(): String = "slint.settings"

override fun createComponent(): JComponent? {
val settings = SlintState.getInstance().lspSettings
val settings = SlintSettingsState.getInstance().lspSettings
settingsComponent = SlintSettingsComponent(settings)
return settingsComponent?.getPanel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil

@Service(Service.Level.PROJECT)
@State(name = "SlintState", storages = [Storage("slint.xml")])
class SlintState : PersistentStateComponent<SlintStateData> {
@State(
name = "SlintState",
storages = [Storage("slint.xml")]
)
class SlintSettingsState : PersistentStateComponent<SlintSettingsState> {
var lspSettings: SlintLspSettings = SlintLspSettings()

companion object {
fun getInstance(): SlintState {
return ApplicationManager.getApplication().getService(SlintState::class.java)
fun getInstance(): SlintSettingsState {
return ApplicationManager.getApplication().getService(SlintSettingsState::class.java)
}
}

override fun getState(): SlintStateData {
return SlintStateData(this.lspSettings)
override fun getState(): SlintSettingsState {
return this
}

override fun loadState(state: SlintStateData) {
this.lspSettings = state.appSettings
override fun loadState(state: SlintSettingsState) {
XmlSerializerUtil.copyBean(state, this);
}


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidget.WidgetPresentation
import com.intellij.openapi.wm.impl.status.EditorBasedWidget
import com.intellij.platform.lsp.api.LspServerManager
//import com.intellij.platform.lsp.impl.LspServerImpl
import dev.slint.ideaplugin.SlintBundle
import dev.slint.ideaplugin.SlintIcons
import dev.slint.ideaplugin.ide.lsp.SlintLspServerSupportProvider
import dev.slint.ideaplugin.lang.SlintFileType
Expand Down

0 comments on commit a9a4d39

Please sign in to comment.