use of org.graalvm.tools.lsp.exceptions.LSPIOException in project graal by oracle.
the class LSPInstrument method launchServer.
private TruffleAdapter launchServer(PrintWriter info, PrintWriter err) {
assert options != null;
assert options.hasSetOptions();
TruffleAdapter truffleAdapter = new TruffleAdapter(environment, options.get(DeveloperMode));
Context.Builder builder = Context.newBuilder();
builder.allowAllAccess(true);
builder.engine(Engine.create());
builder.fileSystem(LSPFileSystem.newReadOnlyFileSystem(truffleAdapter));
ContextAwareExecutor executorWrapper = new ContextAwareExecutorImpl(builder);
setWaitForClose();
executorWrapper.executeWithDefaultContext(() -> {
HostAndPort hostAndPort = options.get(Lsp);
try {
Context context = builder.build();
context.enter();
Instrument instrument = context.getEngine().getInstruments().get(ID);
EnvironmentProvider envProvider = instrument.lookup(EnvironmentProvider.class);
truffleAdapter.register(envProvider.getEnvironment(), executorWrapper);
InetSocketAddress socketAddress = hostAndPort.createSocket();
int port = socketAddress.getPort();
Integer backlog = options.get(SocketBacklogSize);
InetAddress address = socketAddress.getAddress();
ServerSocket serverSocket = new ServerSocket(port, backlog, address);
List<Pair<String, SocketAddress>> delegates = createDelegateSockets(options.get(Delegates));
LanguageServerImpl.create(truffleAdapter, info, err).start(serverSocket, delegates).thenRun(() -> {
try {
executorWrapper.executeWithDefaultContext(() -> {
context.leave();
return null;
}).get();
} catch (ExecutionException | InterruptedException ex) {
}
executorWrapper.shutdown();
notifyClose();
}).exceptionally((throwable) -> {
throwable.printStackTrace(err);
notifyClose();
return null;
});
} catch (ThreadDeath td) {
throw td;
} catch (Throwable e) {
String message = String.format("[Graal LSP] Starting server on %s failed: %s", hostAndPort.getHostPort(), e.getLocalizedMessage());
new LSPIOException(message, e).printStackTrace(err);
}
return null;
});
return truffleAdapter;
}
Aggregations