From db570ba52eef6346f7705503a4cbe32f30c3cf93 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Thu, 25 Apr 2019 18:46:09 +0200 Subject: [PATCH] Java LS should lock its workspace Signed-off-by: Snjezana Peco --- .../jdt/ls/core/internal/LanguageServer.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServer.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServer.java index 7037f56327..709f03d39d 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServer.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServer.java @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.jdt.ls.core.internal; +import java.io.File; + +import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.osgi.service.datalocation.Location; public class LanguageServer implements IApplication { @@ -22,6 +26,15 @@ public class LanguageServer implements IApplication { @Override public Object start(IApplicationContext context) throws Exception { + Location instanceLoc = Platform.getInstanceLocation(); + if (!instanceLoc.lock()) { + File workspaceFile = new File(instanceLoc.getURL().getFile()); + if (workspaceFile.exists()) { + JavaLanguageServerPlugin.logError("Could not launch the server because associated workspace is currently in use by another Java LS server."); + } + return IApplication.EXIT_OK; + } + JavaLanguageServerPlugin.startLanguageServer(this); synchronized(waitLock){ while (!shutdown) {