Skip to content

Commit aaf2f44

Browse files
committed
Fix deployed running and cleanup.
1 parent 196147c commit aaf2f44

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/LanguageServerRouter.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.IOException;
3232
import java.io.InputStream;
3333
import java.io.OutputStream;
34+
import java.lang.ProcessBuilder.Redirect;
3435
import java.net.InetAddress;
3536
import java.net.Socket;
3637
import java.net.URI;
@@ -68,10 +69,12 @@
6869
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
6970
import org.eclipse.lsp4j.WorkspaceFolder;
7071
import org.eclipse.lsp4j.jsonrpc.Launcher;
72+
import org.rascalmpl.ideservices.GsonUtils;
7173
import org.rascalmpl.uri.URIUtil;
7274
import org.rascalmpl.vscode.lsp.parametric.LanguageRegistry.LanguageParameter;
7375
import org.rascalmpl.vscode.lsp.parametric.routing.RoutingTextDocumentService;
7476
import org.rascalmpl.vscode.lsp.parametric.routing.RoutingWorkspaceService;
77+
import org.rascalmpl.vscode.lsp.util.NamedThreadPool;
7578
import org.rascalmpl.vscode.lsp.util.Router;
7679

7780
import io.usethesource.vallang.IInteger;
@@ -140,24 +143,29 @@ public static String extension(ISourceLocation doc) {
140143

141144
private @Nullable CompletableFuture<IBaseLanguageServerExtensions> startServer(LanguageParameter lang) {
142145
try {
143-
var classPath = System.getProperty("java.class.path");
144146
InputStream in;
145147
OutputStream out;
146148
Runnable onExit;
147149
if (DEPLOY_MODE) {
150+
// TODO Figure out Rascal/Rascal-LSP versions/class path
151+
logger.info("Starting LSP process for {}", lang.getName());
152+
logger.debug("{} runs with Rascal {} and Rascal-LSP {}", lang.getName(), "x.xx.xx", "y.yy.yy");
148153
// In deployment, we start a process and connect to it via input/output streams
149-
var proc = new ProcessBuilder("java"
154+
var classPath = System.getProperty("java.class.path");
155+
var proc = new ProcessBuilder(ProcessHandle.current().info().command().get()
150156
, "-Dlog4j2.configurationFactory=org.rascalmpl.vscode.lsp.log.LogJsonConfiguration"
151157
, "-Dlog4j2.level=DEBUG"
152158
, "-Drascal.fallbackResolver=org.rascalmpl.vscode.lsp.uri.FallbackResolver"
153-
, "-Drascal.lsp.deploy=" + DEPLOY_MODE
159+
, "-Drascal.lsp.deploy=true"
154160
, "-Drascal.compilerClasspath=" + classPath
155-
, "-cp" + classPath
161+
, "-Xmx2048M"
162+
, "-cp", classPath
156163
, "org.rascalmpl.vscode.lsp.parametric.ParametricLanguageServer"
157-
).start();
164+
).redirectError(Redirect.INHERIT).start();
165+
166+
logger.debug("Launched language server on process {}", proc.pid());
158167
in = proc.getInputStream();
159168
out = proc.getOutputStream();
160-
// TODO Do we need to close the process here? Or is this triggered after the process exits?
161169
onExit = () -> {};
162170
} else {
163171
// In development, we expect the server to have been launched on a pre-agreed port
@@ -168,9 +176,10 @@ public static String extension(ISourceLocation doc) {
168176
out = socket.getOutputStream();
169177
onExit = () -> {
170178
try {
179+
logger.debug("Closing socket for language {} on port", lang.getName(), port);
171180
socket.close();
172181
} catch (IOException e) {
173-
logger.error("Closing socket for language {} on port {} failed", lang.getName(), port);
182+
logger.error("Closing socket failed", lang.getName(), port);
174183
}
175184
};
176185
}
@@ -179,9 +188,12 @@ public static String extension(ISourceLocation doc) {
179188
.setLocalService(this)
180189
.setInput(in)
181190
.setOutput(out)
191+
.configureGson(GsonUtils.complexAsJsonObject()) // Only needed if we want to communicate IValues
192+
.setExecutorService(NamedThreadPool.single("parametric-lsp-router-out"))
182193
.create();
183194

184-
scheduleShutdown(serverLauncher.startListening(), lang, onExit);
195+
var runner = serverLauncher.startListening();
196+
scheduleShutdown(runner, lang, onExit);
185197
var server = serverLauncher.getRemoteProxy();
186198
var delegateServerCaps = server.initialize(delegateInitializationParams());
187199

@@ -197,6 +209,7 @@ private void scheduleShutdown(Future<Void> server, LanguageParameter lang, Runna
197209
getExecutor().execute(() -> {
198210
try {
199211
server.get();
212+
logger.info("Language server for {} terminated gracefully", lang.getName());
200213
} catch (CancellationException | ExecutionException | InterruptedException e) {
201214
logger.error("Language server for {} crashed", lang.getName(), e);
202215
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/routing/RoutingLanguageServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static void main(String[] args) {
6666
var dedicatedLanguage = new GsonBuilder().create().fromJson(args[0], LanguageParameter.class);
6767
start(DEFAULT_PORT_NUMBER, dedicatedLanguage);
6868
} else {
69-
startLanguageServer(NamedThreadPool.single("parametric-lsp-router")
69+
startLanguageServer(NamedThreadPool.single("parametric-lsp-router-in")
7070
, NamedThreadPool.cached("parametric-router")
7171
, DEFAULT_PORT_NUMBER
7272
);

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/routing/RoutingTextDocumentService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ public void initializeServerCapabilities(ClientCapabilities clientCapabilities,
174174

175175
@Override
176176
public void shutdown() {
177-
// TODO Auto-generated method stub
178-
throw new UnsupportedOperationException("Unimplemented method 'shutdown'");
177+
availableServer().shutdown();
179178
}
180179

181180
@Override

0 commit comments

Comments
 (0)