Skip to content

Commit f8fce71

Browse files
mickaelistriargrunber
authored andcommitted
Do not exit if client and server are the same process.
For Java based clients, they may choose to run the LS application in the same process. Calling System.exit() would terminate both which may not be desired.
1 parent b73f680 commit f8fce71

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServerApplication.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class LanguageServerApplication implements IApplication {
2323

2424
@Override
2525
public Object start(IApplicationContext context) throws Exception {
26-
2726
JavaLanguageServerPlugin.startLanguageServer(this);
2827
synchronized (waitLock) {
2928
while (!shutdown) {
@@ -61,7 +60,7 @@ public void setParentProcessId(long pid) {
6160
/**
6261
* @return the parentProcessId
6362
*/
64-
long getParentProcessId() {
63+
public long getParentProcessId() {
6564
return parentProcessId;
6665
}
6766
}

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
4747
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
4848
import org.eclipse.jdt.ls.core.internal.JobHelpers;
49+
import org.eclipse.jdt.ls.core.internal.LanguageServerApplication;
4950
import org.eclipse.jdt.ls.core.internal.LanguageServerWorkingCopyOwner;
5051
import org.eclipse.jdt.ls.core.internal.ServiceStatus;
5152
import org.eclipse.jdt.ls.core.internal.codemanipulation.GenerateGetterSetterOperation.AccessorField;
@@ -448,10 +449,13 @@ public CompletableFuture<Object> shutdown() {
448449
@Override
449450
public void exit() {
450451
logInfo(">> exit");
451-
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
452-
logInfo("Forcing exit after 1 min.");
453-
System.exit(FORCED_EXIT_CODE);
454-
}, 1, TimeUnit.MINUTES);
452+
LanguageServerApplication application = JavaLanguageServerPlugin.getLanguageServer();
453+
if (application != null && application.getParentProcessId() != ProcessHandle.current().pid()) {
454+
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
455+
logInfo("Forcing exit after 1 min.");
456+
System.exit(FORCED_EXIT_CODE);
457+
}, 1, TimeUnit.MINUTES);
458+
}
455459
if (!shutdownReceived) {
456460
shutdownJob.schedule();
457461
}

0 commit comments

Comments
 (0)