forked from cdietrich/xtext-languageserver-example
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from itemis/cd_multiProjectServer
example for a multi project server
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
org.xtext.example.mydsl.ide/src/org/xtext/example/mydsl/ide/CustomServerModule.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,13 @@ | ||
package org.xtext.example.mydsl.ide; | ||
|
||
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory; | ||
import org.eclipse.xtext.ide.server.MultiProjectWorkspaceConfigFactory; | ||
|
||
import com.google.inject.AbstractModule; | ||
|
||
public final class CustomServerModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
bind(IWorkspaceConfigFactory.class).to(MultiProjectWorkspaceConfigFactory.class); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
org.xtext.example.mydsl.ide/src/org/xtext/example/mydsl/ide/MultiProjectServerLauncher.xtend
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,58 @@ | ||
package org.xtext.example.mydsl.ide | ||
|
||
import com.google.inject.Guice | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import java.io.FileOutputStream | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
import java.io.PrintStream | ||
import java.io.PrintWriter | ||
import java.sql.Timestamp | ||
import javax.inject.Inject | ||
import org.eclipse.lsp4j.jsonrpc.Launcher | ||
import org.eclipse.lsp4j.services.LanguageClient | ||
import org.eclipse.xtext.ide.server.LanguageServerImpl | ||
import org.eclipse.xtext.ide.server.ServerModule | ||
import com.google.inject.util.Modules | ||
|
||
class MultiProjectServerLauncher { | ||
|
||
private static boolean IS_DEBUG = false | ||
|
||
def static void main(String[] args) { | ||
val stdin = System.in | ||
val stdout = System.out | ||
redirectStandardStreams() | ||
val launcher = Guice.createInjector(Modules.override(new ServerModule()).with(new CustomServerModule())).getInstance(ServerLauncher) | ||
launcher.start(stdin, stdout) | ||
} | ||
|
||
@Inject LanguageServerImpl languageServer | ||
|
||
def void start(InputStream in, OutputStream out) { | ||
System.err.println("Starting Xtext Language Server.") | ||
val launcher = Launcher.createLauncher(languageServer, LanguageClient, in, out, true, new PrintWriter(System.out)) | ||
languageServer.connect(launcher.remoteProxy) | ||
val future = launcher.startListening | ||
System.err.println("started.") | ||
while (!future.done) { | ||
Thread.sleep(10_000l) | ||
} | ||
} | ||
|
||
def static redirectStandardStreams() { | ||
System.setIn(new ByteArrayInputStream(newByteArrayOfSize(0))) | ||
val id = org.eclipse.xtext.ide.server.ServerLauncher.name + "-" + new Timestamp(System.currentTimeMillis) | ||
if (IS_DEBUG) { | ||
val stdFileOut = new FileOutputStream("out-" + id + ".log") | ||
System.setOut(new PrintStream(stdFileOut)) | ||
val stdFileErr = new FileOutputStream("error-" + id + ".log") | ||
System.setErr(new PrintStream(stdFileErr)) | ||
} else { | ||
System.setOut(new PrintStream(new ByteArrayOutputStream())) | ||
System.setErr(new PrintStream(new ByteArrayOutputStream())) | ||
} | ||
} | ||
|
||
} |