-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Language Server support for the ros (component level) DSLs
- Loading branch information
Showing
9 changed files
with
492 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../de.fraunhofer.ipa.ros.xtext.ide/src/de/fraunhofer/ipa/ros/ide/launch/ServerLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.fraunhofer.ipa.ros.ide.launch; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.SocketAddress; | ||
import java.nio.channels.AsynchronousServerSocketChannel; | ||
import java.nio.channels.AsynchronousSocketChannel; | ||
import java.nio.channels.Channels; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.lsp4j.jsonrpc.Launcher; | ||
import org.eclipse.lsp4j.jsonrpc.MessageConsumer; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.xtext.ide.server.LanguageServerImpl; | ||
import org.eclipse.xtext.ide.server.ServerModule; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
public class ServerLauncher { | ||
public static void main(String[] args) throws InterruptedException, IOException { | ||
Injector injector = Guice.createInjector(new ServerModule()); | ||
LanguageServerImpl languageServer = injector.getInstance(LanguageServerImpl.class); | ||
Function<MessageConsumer, MessageConsumer> wrapper = consumer -> { | ||
MessageConsumer result = consumer; | ||
return result; | ||
}; | ||
Launcher<LanguageClient> launcher = createSocketLauncher(languageServer, LanguageClient.class, | ||
new InetSocketAddress("localhost", 5008), Executors.newCachedThreadPool(), wrapper); | ||
languageServer.connect(launcher.getRemoteProxy()); | ||
Future<?> future = launcher.startListening(); | ||
while (!future.isDone()) { | ||
Thread.sleep(10_000l); | ||
} | ||
} | ||
|
||
static <T> Launcher<T> createSocketLauncher(Object localService, Class<T> remoteInterface, | ||
SocketAddress socketAddress, ExecutorService executorService, | ||
Function<MessageConsumer, MessageConsumer> wrapper) throws IOException { | ||
AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open().bind(socketAddress); | ||
AsynchronousSocketChannel socketChannel; | ||
try { | ||
socketChannel = serverSocket.accept().get(); | ||
return Launcher.createIoLauncher(localService, remoteInterface, Channels.newInputStream(socketChannel), | ||
Channels.newOutputStream(socketChannel), executorService, wrapper); | ||
} catch (InterruptedException | ExecutionException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...e.fraunhofer.ipa.ros1.xtext.ide/src/de/fraunhofer/ipa/ros1/ide/launch/ServerLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.fraunhofer.ipa.ros1.ide.launch; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.SocketAddress; | ||
import java.nio.channels.AsynchronousServerSocketChannel; | ||
import java.nio.channels.AsynchronousSocketChannel; | ||
import java.nio.channels.Channels; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.lsp4j.jsonrpc.Launcher; | ||
import org.eclipse.lsp4j.jsonrpc.MessageConsumer; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.xtext.ide.server.LanguageServerImpl; | ||
import org.eclipse.xtext.ide.server.ServerModule; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
public class ServerLauncher { | ||
public static void main(String[] args) throws InterruptedException, IOException { | ||
Injector injector = Guice.createInjector(new ServerModule()); | ||
LanguageServerImpl languageServer = injector.getInstance(LanguageServerImpl.class); | ||
Function<MessageConsumer, MessageConsumer> wrapper = consumer -> { | ||
MessageConsumer result = consumer; | ||
return result; | ||
}; | ||
Launcher<LanguageClient> launcher = createSocketLauncher(languageServer, LanguageClient.class, | ||
new InetSocketAddress("localhost", 5008), Executors.newCachedThreadPool(), wrapper); | ||
languageServer.connect(launcher.getRemoteProxy()); | ||
Future<?> future = launcher.startListening(); | ||
while (!future.isDone()) { | ||
Thread.sleep(10_000l); | ||
} | ||
} | ||
|
||
static <T> Launcher<T> createSocketLauncher(Object localService, Class<T> remoteInterface, | ||
SocketAddress socketAddress, ExecutorService executorService, | ||
Function<MessageConsumer, MessageConsumer> wrapper) throws IOException { | ||
AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open().bind(socketAddress); | ||
AsynchronousSocketChannel socketChannel; | ||
try { | ||
socketChannel = serverSocket.accept().get(); | ||
return Launcher.createIoLauncher(localService, remoteInterface, Channels.newInputStream(socketChannel), | ||
Channels.newOutputStream(socketChannel), executorService, wrapper); | ||
} catch (InterruptedException | ExecutionException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.