-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d967ae
commit aaa3495
Showing
26 changed files
with
310 additions
and
152 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
89 changes: 89 additions & 0 deletions
89
engine/language-server/src/main/java/org/enso/languageserver/boot/LanguageServerRunner.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,89 @@ | ||
package org.enso.languageserver.boot; | ||
|
||
import java.util.UUID; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.enso.runner.common.LanguageServerApi; | ||
import org.enso.runner.common.ProfilingConfig; | ||
import org.enso.runner.common.WrongOption; | ||
import org.openide.util.lookup.ServiceProvider; | ||
import org.slf4j.event.Level; | ||
import scala.concurrent.ExecutionContext; | ||
|
||
@ServiceProvider(service = LanguageServerApi.class) | ||
public final class LanguageServerRunner extends LanguageServerApi { | ||
public LanguageServerRunner() {} | ||
|
||
/** | ||
* Handles `--server` CLI option | ||
* | ||
* @param line a CLI line | ||
* @param prof profiling config | ||
* @param logLevel log level to set for the engine runtime | ||
*/ | ||
protected final void runLanguageServer(CommandLine line, ProfilingConfig prof, Level logLevel) | ||
throws WrongOption { | ||
var config = parseServerOptions(line, prof); | ||
LanguageServerApp.run(config, logLevel, line.hasOption(LanguageServerApi.DAEMONIZE_OPTION)); | ||
} | ||
|
||
private static LanguageServerConfig parseServerOptions( | ||
CommandLine line, ProfilingConfig profilingConfig) throws WrongOption { | ||
UUID rootId; | ||
try { | ||
var id = line.getOptionValue(LanguageServerApi.ROOT_ID_OPTION); | ||
if (id == null) { | ||
throw new WrongOption("Root id must be provided"); | ||
} | ||
rootId = UUID.fromString(id); | ||
} catch (IllegalArgumentException e) { | ||
throw new WrongOption("Root must be UUID"); | ||
} | ||
var rootPath = line.getOptionValue(LanguageServerApi.ROOT_PATH_OPTION); | ||
if (rootPath == null) { | ||
throw new WrongOption("Root path must be provided"); | ||
} | ||
var interfac = line.getOptionValue(LanguageServerApi.INTERFACE_OPTION, "127.0.0.1"); | ||
int rpcPort; | ||
try { | ||
rpcPort = Integer.parseInt(line.getOptionValue(LanguageServerApi.RPC_PORT_OPTION, "8080")); | ||
} catch (NumberFormatException e) { | ||
throw new WrongOption("Port must be integer"); | ||
} | ||
int dataPort; | ||
try { | ||
dataPort = Integer.parseInt(line.getOptionValue(LanguageServerApi.DATA_PORT_OPTION, "8081")); | ||
} catch (NumberFormatException e) { | ||
throw new WrongOption("Port must be integer"); | ||
} | ||
Integer secureRpcPort; | ||
try { | ||
var port = line.getOptionValue(LanguageServerApi.SECURE_RPC_PORT_OPTION); | ||
secureRpcPort = port == null ? null : Integer.valueOf(port); | ||
} catch (NumberFormatException e) { | ||
throw new WrongOption("Port must be integer"); | ||
} | ||
Integer secureDataPort; | ||
try { | ||
var port = line.getOptionValue(LanguageServerApi.SECURE_DATA_PORT_OPTION); | ||
secureDataPort = port == null ? null : Integer.valueOf(port); | ||
} catch (NumberFormatException e) { | ||
throw new WrongOption("Port must be integer"); | ||
} | ||
var graalVMUpdater = line.hasOption(LanguageServerApi.SKIP_GRAALVM_UPDATER); | ||
|
||
var config = | ||
new LanguageServerConfig( | ||
interfac, | ||
rpcPort, | ||
scala.Option.apply(secureRpcPort), | ||
dataPort, | ||
scala.Option.apply(secureDataPort), | ||
rootId, | ||
rootPath, | ||
profilingConfig, | ||
new StartupConfig(graalVMUpdater), | ||
"language-server", | ||
ExecutionContext.global()); | ||
return config; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/org/enso/runner/LanguageServerApp.scala → ...nguageserver/boot/LanguageServerApp.scala
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
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
3 changes: 2 additions & 1 deletion
3
engine/language-server/src/main/scala/org/enso/languageserver/data/Config.scala
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
30 changes: 30 additions & 0 deletions
30
...language-server/src/test/java/org/enso/languageserver/LanguageServerDependenciesTest.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,30 @@ | ||
package org.enso.languageserver; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.junit.Test; | ||
|
||
public class LanguageServerDependenciesTest { | ||
|
||
public LanguageServerDependenciesTest() {} | ||
|
||
@Test | ||
public void unableToLoadClassFromEngineRunnerProject() { | ||
try { | ||
var c = Class.forName("org.enso.runner.Main"); | ||
fail("Shouldn't be able to load class from engine-runner project " + c); | ||
} catch (ClassNotFoundException ex) { | ||
// OK | ||
} | ||
} | ||
|
||
@Test | ||
public void ableToLoadClassFromEngineRunnerCommonProject() throws ClassNotFoundException { | ||
var c = Class.forName("org.enso.runner.common.LanguageServerApi"); | ||
assertNotNull( | ||
"Should be able to load class from engine-runner-common project (obviously as we have" | ||
+ " compile time dependency)", | ||
c); | ||
} | ||
} |
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
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
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
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
29 changes: 29 additions & 0 deletions
29
engine/runner-common/src/main/java/org/enso/runner/common/LanguageServerApi.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,29 @@ | ||
package org.enso.runner.common; | ||
|
||
import java.util.ServiceLoader; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.slf4j.event.Level; | ||
|
||
public abstract class LanguageServerApi { | ||
public static final String DAEMONIZE_OPTION = "daemon"; | ||
public static final String ROOT_ID_OPTION = "root-id"; | ||
public static final String ROOT_PATH_OPTION = "path"; | ||
public static final String INTERFACE_OPTION = "interface"; | ||
public static final String RPC_PORT_OPTION = "rpc-port"; | ||
public static final String DATA_PORT_OPTION = "data-port"; | ||
public static final String SECURE_RPC_PORT_OPTION = "secure-rpc-port"; | ||
public static final String SECURE_DATA_PORT_OPTION = "secure-data-port"; | ||
public static final String SKIP_GRAALVM_UPDATER = "skip-graalvm-updater"; | ||
|
||
public static void launchLanguageServer(CommandLine line, ProfilingConfig config, Level logLevel) | ||
throws WrongOption { | ||
var it = | ||
ServiceLoader.load(LanguageServerApi.class, LanguageServerApi.class.getClassLoader()) | ||
.iterator(); | ||
var impl = it.next(); | ||
impl.runLanguageServer(line, config, logLevel); | ||
} | ||
|
||
protected abstract void runLanguageServer( | ||
CommandLine line, ProfilingConfig config, Level logLevel) throws WrongOption; | ||
} |
Oops, something went wrong.