Skip to content

Commit 9466862

Browse files
darthorimarintellij-monorepo-bot
authored andcommitted
[lsp] fix path handling on windows in KotlinLspServer starter
GitOrigin-RevId: 2071e4742248c9f44675733ea810b3ee5591128e
1 parent a4a91a8 commit 9466862

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kotlin-lsp/src/com/jetbrains/ls/kotlinLsp/KotlinLspServer.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.jetbrains.ls.kotlinLsp
44
import com.intellij.openapi.application.ClassPathUtil.addKotlinStdlib
55
import com.intellij.openapi.application.PathManager
66
import com.intellij.openapi.diagnostic.fileLogger
7+
import com.intellij.openapi.util.io.FileUtilRt
78
import com.jetbrains.analyzer.filewatcher.FileWatcher
89
import com.jetbrains.ls.api.core.LSServer
910
import com.jetbrains.ls.api.core.LSServerContext
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.idea.base.plugin.artifacts.KotlinArtifacts
3031
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutMode
3132
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutModeProvider
3233
import org.jetbrains.kotlin.idea.compiler.configuration.isRunningFromSources
34+
import java.io.File
3335
import java.lang.invoke.MethodHandles
3436
import java.net.URLDecoder
3537
import java.nio.file.Path
@@ -134,7 +136,7 @@ private fun initIdeaPaths(systemPath: Path?) {
134136

135137
private fun getInstallationPath(): Path {
136138
val path = MethodHandles.lookup().lookupClass().getProtectionDomain().codeSource.location.path
137-
val jarPath = Paths.get(URLDecoder.decode(path, "UTF-8"))
139+
val jarPath = Paths.get(FileUtilRt.toSystemDependentName(URLDecoder.decode(path, "UTF-8")).removePrefix("\\"))
138140
check(jarPath.extension == "jar") { "Path to jar is expected to end with .jar: $jarPath" }
139141
val libsDir = jarPath.parent
140142
check(libsDir.name == "lib") { "lib dir is expected to be named `lib`: $libsDir" }
@@ -165,7 +167,8 @@ private fun isRunningFromProductionLsp(): Boolean {
165167
private fun getIJPathIfRunningFromSources(): String? {
166168
val serverClass = Class.forName("com.jetbrains.ls.kotlinLsp.KotlinLspServerKt")
167169
val jar = PathManager.getJarForClass(serverClass)?.absolutePathString() ?: return null
168-
val expectedOutDir = "/out/classes/production/language-server.kotlin-lsp"
170+
val SEP = File.separator
171+
val expectedOutDir = "${SEP}out${SEP}classes${SEP}production${SEP}language-server.kotlin-lsp"
169172
if (!jar.endsWith(expectedOutDir)) return null
170173
return jar.removeSuffix(expectedOutDir)
171174
}

0 commit comments

Comments
 (0)