mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
[lsp] some fixes for ServerLauncher
This commit is contained in:
parent
16c9b7c56e
commit
9d3ab92088
7 changed files with 76 additions and 28 deletions
|
@ -278,7 +278,7 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
}
|
||||
|
||||
override resolveCompletionItem(CompletionItem unresolved) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
return unresolved
|
||||
}
|
||||
|
||||
override hover(TextDocumentPositionParams position) {
|
||||
|
@ -302,7 +302,7 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
}
|
||||
|
||||
override resolveCodeLens(CodeLens unresolved) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
return unresolved
|
||||
}
|
||||
|
||||
override formatting(DocumentFormattingParams params) {
|
||||
|
|
|
@ -16,16 +16,17 @@ import java.io.ByteArrayInputStream
|
|||
import java.io.FileOutputStream
|
||||
import java.io.PrintStream
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import org.apache.log4j.Logger
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
class ServerLauncher {
|
||||
|
||||
val LOG = Logger.getLogger(ServerLauncher)
|
||||
private static boolean IS_DEBUG = false
|
||||
|
||||
def static void main(String[] args) {
|
||||
IS_DEBUG = args.exists[it == 'debug']
|
||||
val launcher = Guice.createInjector(new ServerModule).getInstance(ServerLauncher)
|
||||
launcher.start()
|
||||
}
|
||||
|
@ -37,15 +38,13 @@ class ServerLauncher {
|
|||
def void start() {
|
||||
val stdin = System.in
|
||||
val stdout = System.out
|
||||
|
||||
System.setIn(new ByteArrayInputStream(newByteArrayOfSize(0)))
|
||||
System.setOut(new PrintStream(new FileOutputStream("out.log")))
|
||||
redirectStandardStreams()
|
||||
|
||||
System.err.println("Starting Xtext Language Server.")
|
||||
val messageAcceptor = new LanguageServerToJsonAdapter(languageServer) {
|
||||
override protected _doAccept(NotificationMessage message) {
|
||||
if (LOG.isDebugEnabled) {
|
||||
LOG.debug(message)
|
||||
if (IS_DEBUG) {
|
||||
println(message)
|
||||
}
|
||||
if (message.method == MessageMethods.EXIT) {
|
||||
hasExitNotification.set(true);
|
||||
|
@ -54,29 +53,32 @@ class ServerLauncher {
|
|||
}
|
||||
|
||||
override protected sendResponse(String responseId, Object resultValue) {
|
||||
if (LOG.isDebugEnabled) {
|
||||
LOG.debug("response : "+resultValue)
|
||||
if (IS_DEBUG) {
|
||||
println("response : "+resultValue)
|
||||
}
|
||||
super.sendResponse(responseId, resultValue)
|
||||
}
|
||||
|
||||
override protected sendNotification(String methodId, Object parameter) {
|
||||
if (LOG.isDebugEnabled) {
|
||||
LOG.debug("id"+methodId)
|
||||
LOG.debug("notification : "+parameter)
|
||||
if (IS_DEBUG) {
|
||||
println("id"+methodId)
|
||||
println("notification : "+parameter)
|
||||
}
|
||||
super.sendNotification(methodId, parameter)
|
||||
}
|
||||
|
||||
override protected sendResponseError(String responseId, String errorMessage, int errorCode, Object errorData) {
|
||||
if (LOG.isDebugEnabled) {
|
||||
LOG.debug("id"+responseId)
|
||||
LOG.debug("error : "+errorMessage)
|
||||
if (IS_DEBUG) {
|
||||
println("id"+responseId)
|
||||
println("error : "+errorMessage)
|
||||
}
|
||||
super.sendResponseError(responseId, errorMessage, errorCode, errorData)
|
||||
}
|
||||
|
||||
}
|
||||
messageAcceptor.protocol.addErrorListener[p1, p2|
|
||||
p2.printStackTrace(System.err)
|
||||
]
|
||||
messageAcceptor.connect(stdin, stdout)
|
||||
messageAcceptor.start
|
||||
System.err.println("started.")
|
||||
|
@ -87,4 +89,18 @@ class ServerLauncher {
|
|||
System.err.println("Exit notification received. Good Bye!")
|
||||
}
|
||||
|
||||
def redirectStandardStreams() {
|
||||
System.setIn(new ByteArrayInputStream(newByteArrayOfSize(0)))
|
||||
val id = ServerLauncher.name+"-"+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()))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="xtend-gen"/>
|
||||
|
|
|
@ -23,9 +23,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullisdefault=disabled
|
|||
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
|
@ -124,7 +124,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
|
|||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
|
|
|
@ -4,7 +4,7 @@ Bundle-Name: %pluginName
|
|||
Bundle-SymbolicName: org.eclipse.xtext.ide.tests;singleton:=true
|
||||
Bundle-Version: 2.10.0.qualifier
|
||||
Bundle-Localization: plugin
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.xtext;visibility:=reexport,
|
||||
|
|
|
@ -21,8 +21,37 @@
|
|||
<pomDependencies>consider</pomDependencies>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- Maven Assembly Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<!-- get all project dependencies -->
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<!-- MainClass in mainfest make a executable jar -->
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.eclipse.xtext.ide.server.ServerLauncher</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<!-- bind to the packaging phase -->
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.xtext</groupId>
|
||||
|
|
|
@ -12,6 +12,7 @@ import io.typefox.lsapi.json.JsonBasedLanguageServer
|
|||
import org.eclipse.xtext.ide.server.ServerLauncher
|
||||
import org.junit.Test
|
||||
import java.lang.ProcessBuilder.Redirect
|
||||
import org.junit.Assert
|
||||
|
||||
/**
|
||||
* @author efftinge - Initial contribution and API
|
||||
|
@ -19,15 +20,17 @@ import java.lang.ProcessBuilder.Redirect
|
|||
class ServerLauncherTest {
|
||||
|
||||
@Test def void testServerLaunch() {
|
||||
val process = new ProcessBuilder("java","-cp",System.getProperty("java.class.path"), "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044", ServerLauncher.name).redirectInput(Redirect.PIPE).redirectOutput(Redirect.PIPE).start
|
||||
val process = new ProcessBuilder("java","-cp",System.getProperty("java.class.path"), "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044", ServerLauncher.name
|
||||
// ,"debug"
|
||||
).redirectInput(Redirect.PIPE).redirectOutput(Redirect.PIPE).start
|
||||
|
||||
try {
|
||||
val client = new JsonBasedLanguageServer()
|
||||
client.connect(process.inputStream, process.outputStream)
|
||||
|
||||
println(client.initialize(new InitializeParamsImpl() => [
|
||||
val msg = client.initialize(new InitializeParamsImpl() => [
|
||||
rootPath = "."
|
||||
]))
|
||||
])
|
||||
Assert.assertTrue(msg != null)
|
||||
} finally {
|
||||
process.destroy
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue