mirror of
https://github.com/google/gn-language-server.git
synced 2025-12-23 12:26:43 +00:00
Use prebuilts
This commit is contained in:
parent
83eb064267
commit
1026034f45
2 changed files with 70 additions and 1 deletions
|
|
@ -60,6 +60,36 @@ tasks {
|
|||
wrapper {
|
||||
gradleVersion = "8.14.3"
|
||||
}
|
||||
|
||||
val buildLanguageServer = register<Exec>("buildLanguageServer") {
|
||||
commandLine("cargo", "build", "--release")
|
||||
workingDir = file("..")
|
||||
}
|
||||
|
||||
prepareSandbox {
|
||||
val pluginName = project.name
|
||||
val prebuiltsPath = System.getenv("GN_LSP_PREBUILTS")
|
||||
|
||||
if (prebuiltsPath != null) {
|
||||
into("$pluginName/bin") {
|
||||
from(prebuiltsPath)
|
||||
}
|
||||
} else {
|
||||
dependsOn(buildLanguageServer)
|
||||
val os = System.getProperty("os.name").lowercase()
|
||||
val arch = System.getProperty("os.arch").lowercase()
|
||||
val (platform, ext) = when {
|
||||
os.contains("linux") -> "linux-x64" to ""
|
||||
os.contains("mac") && arch == "aarch64" -> "darwin-arm64" to ""
|
||||
os.contains("win") -> "win32-x64" to ".exe"
|
||||
else -> return@prepareSandbox
|
||||
}
|
||||
|
||||
into("$pluginName/bin/$platform") {
|
||||
from(file("../target/release/gn-language-server$ext"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
|
|
|||
|
|
@ -14,16 +14,55 @@
|
|||
|
||||
package com.google.gn
|
||||
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.redhat.devtools.lsp4ij.LanguageServerFactory
|
||||
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider
|
||||
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.attribute.PosixFilePermission
|
||||
|
||||
class GnLspServerFactory : LanguageServerFactory {
|
||||
override fun createConnectionProvider(project: Project): StreamConnectionProvider {
|
||||
val binary = getBundledBinaryPath()
|
||||
return object : ProcessStreamConnectionProvider(
|
||||
listOf("gn-language-server"),
|
||||
listOf(binary.toString()),
|
||||
project.basePath
|
||||
) {}
|
||||
}
|
||||
|
||||
private fun getBundledBinaryPath(): Path {
|
||||
val plugin = PluginManagerCore.getPlugin(PluginId.getId("com.google.gn"))
|
||||
?: throw RuntimeException("Plugin descriptor not found")
|
||||
|
||||
val target = when {
|
||||
SystemInfo.isLinux && SystemInfo.is64Bit -> "linux-x64"
|
||||
SystemInfo.isMac && SystemInfo.isAarch64 -> "darwin-arm64"
|
||||
SystemInfo.isWindows && SystemInfo.is64Bit -> "win32-x64"
|
||||
else -> throw RuntimeException("Unsupported platform: ${SystemInfo.OS_NAME} (${SystemInfo.OS_ARCH})")
|
||||
}
|
||||
|
||||
val binaryName = if (SystemInfo.isWindows) "gn-language-server.exe" else "gn-language-server"
|
||||
val binaryPath = plugin.pluginPath.resolve("bin/$target/$binaryName")
|
||||
|
||||
if (!Files.exists(binaryPath)) {
|
||||
throw RuntimeException("Bundled gn-language-server binary not found at: $binaryPath")
|
||||
}
|
||||
|
||||
if (!SystemInfo.isWindows) {
|
||||
ensureExecutable(binaryPath)
|
||||
}
|
||||
return binaryPath
|
||||
}
|
||||
|
||||
private fun ensureExecutable(path: Path) {
|
||||
if (SystemInfo.isWindows) return
|
||||
val permissions = Files.getPosixFilePermissions(path).toMutableSet()
|
||||
if (permissions.add(PosixFilePermission.OWNER_EXECUTE)) {
|
||||
Files.setPosixFilePermissions(path, permissions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue