Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mandate LanguageServerApplication running #2317

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ls.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
thread="main"
visible="true">
<run
class="org.eclipse.jdt.ls.core.internal.LanguageServer">
class="org.eclipse.jdt.ls.core.internal.LanguageServerApplication">
</run>
</application>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class JavaLanguageServerPlugin extends Plugin {

private ISourceDownloader sourceDownloader;

private LanguageServer languageServer;
private LanguageServerApplication languageServer;
private ProjectsManager projectsManager;
private DigestStore digestStore;
private ContentProviderManager contentProviderManager;
Expand All @@ -140,7 +140,7 @@ public class JavaLanguageServerPlugin extends Plugin {

private ExecutorService executorService;

public static LanguageServer getLanguageServer() {
public static LanguageServerApplication getLanguageServer() {
return pluginInstance == null ? null : pluginInstance.languageServer;
}

Expand Down Expand Up @@ -457,7 +457,7 @@ public static void sendStatus(ServiceStatus serverStatus, String status) {
}
}

static void startLanguageServer(LanguageServer newLanguageServer) throws IOException {
static void startLanguageServer(LanguageServerApplication newLanguageServer) throws IOException {
if (pluginInstance != null) {
pluginInstance.languageServer = newLanguageServer;
pluginInstance.startConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

public class LanguageServer implements IApplication {
public class LanguageServerApplication implements IApplication {

private volatile boolean shutdown;
private long parentProcessId;
private final Object waitLock = new Object();
private volatile boolean shutdown;
private long parentProcessId;
private final Object waitLock = new Object();

@Override
public Object start(IApplicationContext context) throws Exception {

JavaLanguageServerPlugin.startLanguageServer(this);
synchronized(waitLock){
while (!shutdown) {
try {
context.applicationRunning();
JavaLanguageServerPlugin.logInfo("Main thread is waiting");
waitLock.wait();
} catch (InterruptedException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
JavaLanguageServerPlugin.startLanguageServer(this);
synchronized (waitLock) {
while (!shutdown) {
try {
context.applicationRunning();
JavaLanguageServerPlugin.logInfo("Main thread is waiting");
waitLock.wait();
} catch (InterruptedException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
return IApplication.EXIT_OK;
}

@Override
public void stop() {
synchronized(waitLock){
waitLock.notifyAll();
}
synchronized (waitLock) {
waitLock.notifyAll();
}
}

public void exit() {
shutdown = true;
JavaLanguageServerPlugin.logInfo("Shutdown received... waking up main thread");
synchronized(waitLock){
waitLock.notifyAll();
}
}
shutdown = true;
JavaLanguageServerPlugin.logInfo("Shutdown received... waking up main thread");
synchronized (waitLock) {
waitLock.notifyAll();
}
}

public void setParentProcessId(long pid) {
this.parentProcessId = pid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public final class ParentProcessWatcher implements Runnable, Function<MessageCon
private static final boolean isJava1x = System.getProperty("java.version").startsWith("1.");
private static final int POLL_DELAY_SECS = 10;
private volatile long lastActivityTime;
private final LanguageServer server;
private final LanguageServerApplication server;
private ScheduledFuture<?> task;
private ScheduledExecutorService service;

public ParentProcessWatcher(LanguageServer server ) {
public ParentProcessWatcher(LanguageServerApplication server) {
this.server = server;
if (ProcessHandle.current().parent().isPresent()) {
this.server.setParentProcessId(ProcessHandle.current().parent().get().pid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.jdt.ls.core.internal.JSONUtility;
import org.eclipse.jdt.ls.core.internal.JVMConfigurator;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.LanguageServerApplication;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
Expand Down Expand Up @@ -151,8 +152,9 @@ public InitializeResult initialize(InitializeParams param) {
}

Integer processId = param.getProcessId();
if (processId != null) {
JavaLanguageServerPlugin.getLanguageServer().setParentProcessId(processId.longValue());
LanguageServerApplication application = JavaLanguageServerPlugin.getLanguageServer();
if (processId != null && application != null) {
application.setParentProcessId(processId.longValue());
}

return initializationOptions;
Expand Down