Skip to content

Commit 02be1f3

Browse files
[lsp] LSP-196: Fix conflicts accessing database
- Use the workspace storage path provided by the client - Use FS locks to prevent multiple servers connecting to the same database Merge-request: IJ-MR-171453 Merged-by: Pavel Mikhailovskii <[email protected]> GitOrigin-RevId: 18a72d1d5ca4c3f0514d002d0fbbd0bc11cccc9c
1 parent 809cffe commit 02be1f3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutMode
3232
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutModeProvider
3333
import org.jetbrains.kotlin.idea.compiler.configuration.isRunningFromSources
3434
import java.awt.Toolkit
35+
import java.io.RandomAccessFile
3536
import java.lang.invoke.MethodHandles
3637
import java.net.URLDecoder
3738
import java.nio.file.Path
@@ -125,7 +126,23 @@ private fun initIdeaPaths(systemPath: Path?) {
125126
"fleet" / "native" / "target" / "download" / "filewatcher")
126127
}
127128
else {
128-
val path = systemPath?.createDirectories() ?: createTempDirectory("idea-system")
129+
val path = systemPath
130+
?.createDirectories()
131+
?.takeIf {
132+
val lockFile = (it / ".app.lock").toFile()
133+
val channel = RandomAccessFile(lockFile, "rw").channel
134+
val isLockAcquired = channel.tryLock() != null
135+
if (!isLockAcquired) {
136+
LOG.info("The specified workspace data path is already in use: $it")
137+
channel.close()
138+
}
139+
isLockAcquired
140+
}
141+
?: createTempDirectory("idea-system").also {
142+
@Suppress("SSBasedInspection")
143+
it.toFile().deleteOnExit()
144+
}
145+
129146
systemProperty("idea.home.path", "$path")
130147
systemProperty("idea.config.path", "$path/config", ifAbsent = true)
131148
systemProperty("idea.system.path", "$path/system", ifAbsent = true)

kotlin-vscode/src/lspClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ async function getRunningJavaServerLspOptions(): Promise<ServerOptions | null> {
184184

185185
const extractPath = getContext().asAbsolutePath(path.join('server', 'extracted', 'lib'));
186186

187+
const context = getContext()
187188
const args: string[] = []
188189
args.push(...defaultJvmOptions)
189190
args.push(...getUserJvmOptions())
190191
args.push(
191192
'-classpath', extractPath + path.sep + '*',
192193
'com.jetbrains.ls.kotlinLsp.KotlinLspServerKt', '--client',
193-
'--system-path', getContext().globalStorageUri.fsPath,
194+
'--system-path', (context.storageUri ?? context.globalStorageUri).fsPath,
194195
);
195196
return <ServerOptions>{
196197
command: javaCommand,

0 commit comments

Comments
 (0)