use of org.eclipse.lsp4j.services.LanguageServer in project xtext-core by eclipse.
the class SocketServerLauncher method main.
public static void main(final String[] args) {
try {
ServerModule _serverModule = new ServerModule();
final Injector injector = Guice.createInjector(_serverModule);
final LanguageServer languageServer = injector.<LanguageServer>getInstance(LanguageServer.class);
final ServerSocketChannel serverSocket = ServerSocketChannel.open();
InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 5007);
serverSocket.bind(_inetSocketAddress);
final SocketChannel socketChannel = serverSocket.accept();
InputStream _newInputStream = Channels.newInputStream(socketChannel);
OutputStream _newOutputStream = Channels.newOutputStream(socketChannel);
PrintWriter _printWriter = new PrintWriter(System.out);
final Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(languageServer, _newInputStream, _newOutputStream, true, _printWriter);
launcher.startListening().get();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.services.LanguageServer in project sts4 by spring-projects.
the class LaunguageServerApp method run.
/**
* Listen for requests from the parent node process.
* Send replies asynchronously.
* When the request stream is closed, wait for 5s for all outstanding responses to compute, then return.
* @throws ExecutionException
* @throws InterruptedException
*/
protected void run(Connection connection) throws InterruptedException, ExecutionException {
LanguageServer server = createServer();
ExecutorService executor = createServerThreads();
Function<MessageConsumer, MessageConsumer> wrapper = (MessageConsumer consumer) -> {
return (msg) -> {
try {
consumer.consume(msg);
} catch (UnsupportedOperationException e) {
// log a warning and ignore. We are getting some messages from vsCode the server doesn't know about
Log.warn("Unsupported message was ignored!", e);
}
};
};
Launcher<STS4LanguageClient> launcher = Launcher.createLauncher(server, STS4LanguageClient.class, connection.in, connection.out, executor, wrapper);
if (server instanceof LanguageClientAware) {
LanguageClient client = launcher.getRemoteProxy();
((LanguageClientAware) server).connect(client);
}
launcher.startListening().get();
}
use of org.eclipse.lsp4j.services.LanguageServer in project sonarlint-core by SonarSource.
the class ServerMainTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
System.out.println("Max memory: " + Runtime.getRuntime().maxMemory());
System.setProperty(SonarLintTelemetry.DISABLE_PROPERTY_KEY, "true");
serverSocket = new ServerSocket(0);
int port = serverSocket.getLocalPort();
client = new FakeLanguageClient();
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<LanguageServer> callable = () -> {
Socket socket = serverSocket.accept();
Launcher<LanguageServer> launcher = LSPLauncher.createClientLauncher(client, socket.getInputStream(), socket.getOutputStream());
launcher.startListening();
return launcher.getRemoteProxy();
};
Future<LanguageServer> future = executor.submit(callable);
executor.shutdown();
String js = new File("target/plugins/javascript.jar").getAbsoluteFile().toURI().toURL().toString();
String php = new File("target/plugins/php.jar").getAbsoluteFile().toURI().toURL().toString();
String py = new File("target/plugins/python.jar").getAbsoluteFile().toURI().toURL().toString();
String ts = new File("target/plugins/typescript.jar").getAbsoluteFile().toURI().toURL().toString();
Path fakeTypeScriptProjectPath = globalTemp.newFolder().toPath();
Path packagejson = fakeTypeScriptProjectPath.resolve("package.json");
FileUtils.write(packagejson.toFile(), "{" + "\"devDependencies\": {\n" + " \"typescript\": \"2.6.1\"\n" + " }" + "}", StandardCharsets.UTF_8);
ProcessBuilder pb = new ProcessBuilder("npm" + (SystemUtils.IS_OS_WINDOWS ? ".cmd" : ""), "install").directory(fakeTypeScriptProjectPath.toFile()).inheritIO();
Process process = pb.start();
if (process.waitFor() != 0) {
fail("Unable to run npm install");
}
try {
ServerMain.main("" + port, js, php, py, ts);
} catch (Exception e) {
e.printStackTrace();
future.get(1, TimeUnit.SECONDS);
if (!future.isDone()) {
future.cancel(true);
}
throw e;
}
lsProxy = future.get();
InitializeParams initializeParams = new InitializeParams();
initializeParams.setInitializationOptions(ImmutableMap.builder().put(TEST_FILE_PATTERN, "{**/test/**,**/*test*,**/*Test*}").put(TYPESCRIPT_LOCATION, fakeTypeScriptProjectPath.resolve("node_modules").toString()).put(DISABLE_TELEMETRY, true).put("telemetryStorage", "not/exists").put("productName", "SLCORE tests").put("productVersion", "0.1").build());
lsProxy.initialize(initializeParams).get();
}
use of org.eclipse.lsp4j.services.LanguageServer in project sts4 by spring-projects.
the class LaunguageServerApp method startAsServer.
/**
* starts up the language server and let it listen for connections from the outside
* instead of connecting itself to an existing port or channel.
*
* This is meant for development only, to reduce turnaround times while working
* on the language server from within an IDE, so that you can start the language
* server right away in debug mode and let the vscode extension connect to that
* instance instead of vice versa.
*
* Source of inspiration:
* https://github.com/itemis/xtext-languageserver-example/blob/master/org.xtext.example.mydsl.ide/src/org/xtext/example/mydsl/ide/RunServer.java
*/
public void startAsServer() throws IOException, InterruptedException {
Log.info("Starting LS as standlone server");
Function<MessageConsumer, MessageConsumer> wrapper = consumer -> {
MessageConsumer result = consumer;
return result;
};
SimpleLanguageServer languageServer = createServer();
Launcher<STS4LanguageClient> launcher = createSocketLauncher(languageServer, STS4LanguageClient.class, new InetSocketAddress("localhost", SERVER_STANDALONE_PORT), createServerThreads(), wrapper);
languageServer.connect(launcher.getRemoteProxy());
Future<?> future = launcher.startListening();
while (!future.isDone()) {
Thread.sleep(10_000l);
}
}
Aggregations