Java Code Examples for org.eclipse.lsp4j.jsonrpc.Launcher#getRemoteProxy()

The following examples show how to use org.eclipse.lsp4j.jsonrpc.Launcher#getRemoteProxy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with MIT License 6 votes vote down vote up
@Override
public CompletableFuture<Void> start(File rootPath) {
    setStatus(STARTING);
    this.client = new LSPClient(this.startupLogic);

    this.rootPath = rootPath;

    try {
        var processedArgs = this.argumentPreprocessor.apply(this, new ArrayList<>(this.lspArgs));

        var streamConnectionProvider = new LSPProvider(
                () -> requestManager,
                processedArgs,
                serverPath.get());
        streamConnectionProvider.start();

        Launcher<LanguageServer> launcher =
                Launcher.createLauncher(client, LanguageServer.class, streamConnectionProvider.getInputStream(), streamConnectionProvider.getOutputStream());

        languageServer = launcher.getRemoteProxy();
        client.connect(languageServer);
        launcherFuture = launcher.startListening();

        return (startingFuture = languageServer.initialize(getInitParams()).thenApply(res -> {
            LOGGER.info("Started LSP");

            requestManager = new DefaultRequestManager(this, languageServer, client, res.getCapabilities());
            setStatus(STARTED);
            requestManager.initialized(new InitializedParams());
            setStatus(INITIALIZED);
            return res;
        }).thenRun(() -> LOGGER.info("Done starting LSP!")));

    } catch (Exception e) {
        LOGGER.error("Can't launch language server for project", e);
    }

    return CompletableFuture.runAsync(() -> {});
}
 
Example 2
Source File: SendNotificationTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	this.client = mock(ExecuteCommandProposedClient.class);

	PipedOutputStream clientWritesTo = new PipedOutputStream();
	PipedInputStream clientReadsFrom = new PipedInputStream();
	PipedInputStream serverReadsFrom = new PipedInputStream();
	PipedOutputStream serverWritesTo = new PipedOutputStream();

	serverWritesTo.connect(clientReadsFrom);
	clientWritesTo.connect(serverReadsFrom);

	this.closeables = new Closeable[] { clientWritesTo, clientReadsFrom, serverReadsFrom, serverWritesTo };

	Launcher<JavaLanguageClient> serverLauncher = Launcher.createLauncher(new Object(), JavaLanguageClient.class, serverReadsFrom, serverWritesTo);
	serverLauncher.startListening();
	Launcher<LanguageServer> clientLauncher = Launcher.createLauncher(client, LanguageServer.class, clientReadsFrom, clientWritesTo);
	clientLauncher.startListening();

	this.clientConnection = serverLauncher.getRemoteProxy();
}
 
Example 3
Source File: ProtocolTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * creates a proxy, delegating to a remote endpoint, forwarding to another remote endpoint, that delegates to an actual implementation.
 * @param intf
 * @param impl
 * @return
 * @throws IOException 
 */
public <T> T wrap(Class<T> intf, T impl) {
	PipedInputStream in1 = new PipedInputStream();
	PipedOutputStream out1 = new PipedOutputStream();
	Launcher<T> launcher1 = Launcher.createLauncher(impl, intf, in1, out1);
	
	PipedInputStream in2 = new PipedInputStream();
	PipedOutputStream out2 = new PipedOutputStream();
	Launcher<T> launcher2 = Launcher.createLauncher(new Object(), intf, in2, out2);
	try {
		in1.connect(out2);
		in2.connect(out1);
	} catch (IOException e) {
		throw new IllegalStateException(e);
	}
	launcher1.startListening();
	launcher2.startListening();
	return launcher2.getRemoteProxy();
}
 
Example 4
Source File: RdfLint.java    From rdflint with MIT License 4 votes vote down vote up
/**
 * 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);
      }
    }
  }
}
 
Example 5
Source File: SarosLauncher.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Starts the server.
 *
 * @param args command-line arguments
 * @throws Exception on critical failures
 */
public static void main(String[] args) throws Exception {

  if (args.length > 1) {
    throw new IllegalArgumentException("wrong number of arguments");
  } else if (args.length != 1) {
    throw new IllegalArgumentException("port parameter not supplied");
  } else if (!args[0].matches("\\d+")) {
    throw new IllegalArgumentException("port is not a number");
  }

  URL log4jProperties = SarosLauncher.class.getResource(LOGGING_CONFIG_FILE);
  PropertyConfigurator.configure(log4jProperties);

  log.addAppender(new ConsoleAppender());

  int port = Integer.parseInt(args[0]);
  Socket socket = new Socket("localhost", port);

  log.info("listening on port " + port);

  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            public void run() {
              try {
                socket.close();
              } catch (IOException e) {
                // NOP
              }
            }
          });

  SarosLanguageServer langSvr = new SarosLanguageServer();
  Launcher<ISarosLanguageClient> l =
      Launcher.createLauncher(
          langSvr, ISarosLanguageClient.class, socket.getInputStream(), socket.getOutputStream());

  ISarosLanguageClient langClt = l.getRemoteProxy();
  log.addAppender(new LanguageClientAppender(langClt));
  langSvr.connect(langClt);

  l.startListening();
}