下面列出了怎么用org.eclipse.lsp4j.launch.LSPLauncher的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
List<String> arguments = Arrays.asList(args);
if (arguments.contains(HELP_PARAMETER)) {
System.out.println(HELP_MESSAGE);
} else if (arguments.contains(WEBSOCKET_PARAMETER)) {
int port = extractPort(arguments);
String hostname = extractHostname(arguments);
webSocketRunner = new WebSocketRunner();
String contextPath = extractContextPath(arguments);
webSocketRunner.runWebSocketServer(hostname, port, contextPath);
} else {
server = new CamelLanguageServer();
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, System.in, System.out);
server.connect(launcher.getRemoteProxy());
launcher.startListening();
}
}
@SuppressWarnings({"try", "FutureReturnValueIgnored"})
public static void main(String[] args) throws DeploymentException, InterruptedException {
LOGGER.info(" -- >>> TeiidDdlLanguageServerRunner.main()");
List<String> arguments = Arrays.asList(args);
if (arguments.contains(WEBSOCKET_PARAMETER)) {
LOGGER.info(" -- >>> Started Teiid LS as WEB SOCKET");
int port = extractPort(arguments);
String hostname = extractHostname(arguments);
String contextPath = extractContextPath(arguments);
try (TeiidDdlWebSocketRunner runner = new TeiidDdlWebSocketRunner(hostname, port, contextPath);) {
Thread.currentThread().join();
}
} else {
LOGGER.info(" -- >>> Started Teiid LS as JAVA SERVER");
server = new TeiidDdlLanguageServer(null);
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, System.in, System.out);
server.connect(launcher.getRemoteProxy());
launcher.startListening();
LOGGER.info(" -- >>> Teiid LS Started. launch listening started");
}
}
@Before public void setup() throws IOException {
PipedInputStream inClient = new PipedInputStream();
PipedOutputStream outClient = new PipedOutputStream();
PipedInputStream inServer = new PipedInputStream();
PipedOutputStream outServer = new PipedOutputStream();
inClient.connect(outServer);
outClient.connect(inServer);
server = new AssertingEndpoint();
serverLauncher = LSPLauncher.createServerLauncher(ServiceEndpoints.toServiceObject(server, LanguageServer.class), inServer, outServer);
serverListening = serverLauncher.startListening();
client = new AssertingEndpoint();
clientLauncher = LSPLauncher.createClientLauncher(ServiceEndpoints.toServiceObject(client, LanguageClient.class), inClient, outClient);
clientListening = clientLauncher.startListening();
Logger logger = Logger.getLogger(StreamMessageProducer.class.getName());
logLevel = logger.getLevel();
logger.setLevel(Level.SEVERE);
}
private static void run(InputStream in, OutputStream out) throws Exception {
LanguageServerImpl server = new LanguageServerImpl();
Launcher<LanguageClient> serverLauncher = LSPLauncher.createServerLauncher(server, in, out);
((LanguageClientAware) server).connect(serverLauncher.getRemoteProxy());
serverLauncher.startListening();
while (true) {
try {
Thread.sleep(100000);
} catch (InterruptedException ex) {
//ignore
}
}
}
@Messages("LBL_Connecting=Connecting to language server")
public static void addBindings(FileObject root, int port, String... extensions) {
BaseProgressUtils.showProgressDialogAndRun(() -> {
try {
Socket s = new Socket(InetAddress.getLocalHost(), port);
LanguageClientImpl lc = new LanguageClientImpl();
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
Launcher<LanguageServer> launcher = LSPLauncher.createClientLauncher(lc, in, new OutputStream() {
@Override
public void write(int w) throws IOException {
out.write(w);
if (w == '\n')
out.flush();
}
});
launcher.startListening();
LanguageServer server = launcher.getRemoteProxy();
InitializeResult result = initServer(null, server, root);
LSPBindings bindings = new LSPBindings(server, result, null);
lc.setBindings(bindings);
workspace2Extension2Server.put(root, Arrays.stream(extensions).collect(Collectors.toMap(k -> k, v -> bindings)));
} catch (InterruptedException | ExecutionException | IOException ex) {
Exceptions.printStackTrace(ex);
}
}, Bundle.LBL_Connecting());
}
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new ServerModule());
LanguageServer languageServer = injector.getInstance(LanguageServer.class);
ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.bind(new InetSocketAddress("localhost", 5007));
SocketChannel socketChannel = serverSocket.accept();
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(languageServer, Channels.newInputStream(socketChannel), Channels.newOutputStream(socketChannel), true, new PrintWriter(System.out));
launcher.startListening().get();
}
/**
* rdflint entry point.
*/
public static void main(String[] args) throws ParseException, IOException {
// Parse CommandLine Parameter
Options options = new Options();
options.addOption("baseuri", true, "RDF base URI");
options.addOption("targetdir", true, "Target Directory Path");
options.addOption("outputdir", true, "Output Directory Path");
options.addOption("origindir", true, "Origin Dataset Directory Path");
options.addOption("config", true, "Configuration file Path");
options.addOption("suppress", true, "Suppress problems file Path");
options.addOption("minErrorLevel", true,
"Minimal logging level which is considered an error, e.g. INFO, WARN, ERROR");
options.addOption("i", false, "Interactive mode");
options.addOption("ls", false, "Language Server mode (experimental)");
options.addOption("h", false, "Print usage");
options.addOption("v", false, "Print version");
options.addOption("vv", false, "Verbose logging (for debugging)");
CommandLine cmd = null;
try {
CommandLineParser parser = new DefaultParser();
cmd = parser.parse(options, args);
} catch (UnrecognizedOptionException e) {
System.out.println("Unrecognized option: " + e.getOption()); // NOPMD
System.exit(1);
}
// print version
if (cmd.hasOption("v")) {
System.out.println("rdflint " + VERSION); // NOPMD
return;
}
// print usage
if (cmd.hasOption("h")) {
HelpFormatter f = new HelpFormatter();
f.printHelp("rdflint [options]", options);
return;
}
// verbose logging mode
if (cmd.hasOption("vv")) {
Logger.getLogger("com.github.imas.rdflint").setLevel(Level.TRACE);
}
// Execute Language Server Mode
if (cmd.hasOption("ls")) {
RdfLintLanguageServer server = new RdfLintLanguageServer();
Launcher<LanguageClient> launcher = LSPLauncher
.createServerLauncher(server, System.in, System.out);
LanguageClient client = launcher.getRemoteProxy();
server.connect(client);
launcher.startListening();
return;
}
// Set parameter
Map<String, String> cmdOptions = new ConcurrentHashMap<>();
for (String key :
Arrays.asList("targetdir", "config", "suppress", "outputdir", "baseuri", "origindir")) {
if (cmd.hasOption(key)) {
cmdOptions.put(key, cmd.getOptionValue(key));
}
}
// Main procedure
if (cmd.hasOption("i")) {
// Execute Interactive mode
InteractiveMode imode = new InteractiveMode();
imode.execute(cmdOptions);
} else {
// Execute linter
RdfLint lint = new RdfLint();
RdfLintParameters params = ConfigurationLoader.loadParameters(cmdOptions);
LintProblemSet problems = lint.lintRdfDataSet(params, params.getTargetDir());
if (problems.hasProblem()) {
Path problemsPath = Paths.get(params.getOutputDir() + "/rdflint-problems.yml");
LintProblemFormatter.out(System.out, problems);
LintProblemFormatter.yaml(Files.newOutputStream(problemsPath), problems);
final String minErrorLevel = cmd.getOptionValue("minErrorLevel", "WARN");
final LintProblem.ErrorLevel errorLevel = LintProblem.ErrorLevel.valueOf(minErrorLevel);
if (problems.hasProblemOfLevelOrWorse(errorLevel)) {
System.exit(1);
}
}
}
}