Java 类org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints 实例源码

项目:xtext-core    文件:AbstractLanguageServerTest.java   
@Before
public void setup() {
  try {
    final Injector injector = Guice.createInjector(this.getServerModule());
    injector.injectMembers(this);
    final Object resourceServiceProvider = this.resourceServerProviderRegistry.getExtensionToFactoryMap().get(this.fileExtension);
    if ((resourceServiceProvider instanceof IResourceServiceProvider)) {
      this.languageInfo = ((IResourceServiceProvider)resourceServiceProvider).<LanguageInfo>get(LanguageInfo.class);
    }
    this.languageServer.connect(ServiceEndpoints.<LanguageClientExtensions>toServiceObject(this, LanguageClientExtensions.class));
    this.languageServer.supportedMethods();
    File _absoluteFile = new File("").getAbsoluteFile();
    File _file = new File(_absoluteFile, "/test-data/test-project");
    this.root = _file;
    boolean _mkdirs = this.root.mkdirs();
    boolean _not = (!_mkdirs);
    if (_not) {
      Files.cleanFolder(this.root, null, true, false);
    }
    this.root.deleteOnExit();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:lsp4j    文件:LauncherTest.java   
@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();
}
项目:lsp4j    文件:NullResponseTest.java   
@Test public void testNullResponse() throws InterruptedException, ExecutionException {
    Endpoint endpoint = ServiceEndpoints.toEndpoint(this);
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class);
    MessageJsonHandler handler = new MessageJsonHandler(methods);
    List<Message> msgs = new ArrayList<>();
    MessageConsumer consumer = (message) -> {
        msgs.add(message);
    };
    RemoteEndpoint re = new RemoteEndpoint(consumer, endpoint);

    RequestMessage request = new RequestMessage();
    request.setId("1");
    request.setMethod("shutdown");
    re.consume(request);
    Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":null}", handler.serialize(msgs.get(0)));
    msgs.clear();
    shutdownReturn = new Object();
    re.consume(request);
    Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":{}}", handler.serialize(msgs.get(0)));
}
项目:lsp4j    文件:EndpointsTest.java   
@Test public void testRpcMethods_02() {
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Bar.class);

    final JsonRpcMethod requestMethod = methods.get("bar/doStuff");
    assertEquals("bar/doStuff", requestMethod.getMethodName());
    assertEquals(2, requestMethod.getParameterTypes().length);
    assertEquals(String.class, requestMethod.getParameterTypes()[0]);
    assertEquals(Integer.class, requestMethod.getParameterTypes()[1]);
    assertFalse(requestMethod.isNotification());

    final JsonRpcMethod notificationMethod = methods.get("bar/myNotification");
    assertEquals("bar/myNotification", notificationMethod.getMethodName());
    assertEquals(2, notificationMethod.getParameterTypes().length);
    assertEquals(String.class, notificationMethod.getParameterTypes()[0]);
    assertEquals(Integer.class, notificationMethod.getParameterTypes()[1]);
    assertTrue(notificationMethod.isNotification());

    final JsonRpcMethod delegateMethod = methods.get("hubba");
    assertEquals("hubba", delegateMethod.getMethodName());
    assertEquals(2, delegateMethod.getParameterTypes().length);
    assertEquals(String.class, delegateMethod.getParameterTypes()[0]);
    assertEquals(Integer.class, delegateMethod.getParameterTypes()[1]);
    assertTrue(delegateMethod.isNotification());
}
项目:che    文件:YamlLanguageServerLauncher.java   
@Override
public void onServerInitialized(
    LanguageServerLauncher launcher,
    LanguageServer server,
    ServerCapabilities capabilities,
    String projectPath) {

  try {
    Map<String, String> preferences =
        requestFactory.fromUrl(apiUrl + "/preferences").useGetMethod().request().asProperties();

    Endpoint endpoint = ServiceEndpoints.toEndpoint(server);
    YamlSchemaAssociations serviceObject =
        ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class);
    Map<String, String[]> associations =
        jsonToSchemaAssociations(preferences.get("yaml.preferences"));
    serviceObject.yamlSchemaAssociation(associations);

  } catch (ApiException | IOException e) {
    LOG.error(e.getLocalizedMessage(), e);
  }
}
项目:che    文件:YamlService.java   
/**
 * Route for getting getting schemas from client side and injecting them into yaml language server
 *
 * @param yamlDto A yamlDTO containing the list of schemas you would like to add
 */
@POST
@Path("schemas")
@Consumes(MediaType.APPLICATION_JSON)
public void putSchemas(YamlDTO yamlDto) throws ApiException {

  LanguageServer yamlLS = YamlLanguageServerLauncher.getYamlLanguageServer();

  if (yamlDto != null && yamlLS != null) {

    Endpoint endpoint = ServiceEndpoints.toEndpoint(yamlLS);
    YamlSchemaAssociations serviceObject =
        ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class);

    Map<String, String[]> schemaAssociations = new HashMap<>();
    Map<String, String> yamlDtoSchemas = yamlDto.getSchemas();

    for (Map.Entry<String, String> schema : yamlDtoSchemas.entrySet()) {
      schemaAssociations.put(
          schema.getKey(), new Gson().fromJson(schema.getValue(), String[].class));
    }

    serviceObject.yamlSchemaAssociation(schemaAssociations);
  }
}
项目:che    文件:JsonLanguageServerLauncher.java   
@Override
public void onServerInitialized(
    LanguageServerLauncher launcher,
    LanguageServer server,
    ServerCapabilities capabilities,
    String projectPath) {
  Endpoint endpoint = ServiceEndpoints.toEndpoint(server);
  JsonExtension serviceObject = ServiceEndpoints.toServiceObject(endpoint, JsonExtension.class);
  Map<String, String[]> associations = new HashMap<>();
  associations.put("/*.schema.json", new String[] {"http://json-schema.org/draft-04/schema#"});
  associations.put("/bower.json", new String[] {"http://json.schemastore.org/bower"});
  associations.put("/.bower.json", new String[] {"http://json.schemastore.org/bower"});
  associations.put("/.bowerrc", new String[] {"http://json.schemastore.org/bowerrc"});
  associations.put("/composer.json", new String[] {"https://getcomposer.org/schema.json"});
  associations.put("/package.json", new String[] {"http://json.schemastore.org/package"});
  associations.put("/jsconfig.json", new String[] {"http://json.schemastore.org/jsconfig"});
  associations.put("/tsconfig.json", new String[] {"http://json.schemastore.org/tsconfig"});
  serviceObject.jsonSchemaAssociation(associations);
}
项目:dsp4e    文件:DebugLauncher.java   
/**
 * Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
 * Threads are started with the given executor service. The wrapper function is applied to the incoming and
 * outgoing message streams so additional message handling such as validation and tracing can be included.
 * The {@code configureGson} function can be used to register additional type adapters in the {@link GsonBuilder}
 * in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
 * 
 * @param localService - an object on which classes RPC methods are looked up
 * @param remoteInterface - an interface on which RPC methods are looked up
 * @param in - inputstream to listen for incoming messages
 * @param out - outputstream to send outgoing messages
 * @param executorService - the executor service used to start threads
 * @param wrapper - a function for plugging in additional message consumers
 * @param configureGson - a function for Gson configuration
 */
static <T> DebugLauncher<T> createIoLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out,
        ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper, Consumer<GsonBuilder> configureGson) {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<String, JsonRpcMethod>();
    supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));

    if (localService instanceof JsonRpcMethodProvider) {
        JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
        supportedMethods.putAll(rpcMethodProvider.supportedMethods());
    } else {
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
    }

    MessageJsonHandler jsonHandler = new DebugMessageJsonHandler(supportedMethods, configureGson);
    MessageConsumer outGoingMessageStream = new StreamMessageConsumer(out, jsonHandler);
    outGoingMessageStream = wrapper.apply(outGoingMessageStream);
    RemoteEndpoint serverEndpoint = new RemoteEndpoint(outGoingMessageStream, ServiceEndpoints.toEndpoint(localService));
    jsonHandler.setMethodProvider(serverEndpoint);
    // wrap incoming message stream
    MessageConsumer messageConsumer = wrapper.apply(serverEndpoint);
    StreamMessageProducer reader = new StreamMessageProducer(in, jsonHandler);

    T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);

    return new DebugLauncher<T> () {

        @Override
        public Future<?> startListening() {
            return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, executorService);
        }

        @Override
        public T getRemoteProxy() {
            return remoteProxy;
        }

    };
}
项目:SOMns-vscode    文件:Launcher.java   
/**
 * Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
 * Threads are started with the given executor service. The wrapper function is applied to the incoming and
 * outgoing message streams so additional message handling such as validation and tracing can be included.
 * The {@code configureGson} function can be used to register additional type adapters in the {@link GsonBuilder}
 * in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
 * 
 * @param localService - an object on which classes RPC methods are looked up
 * @param remoteInterface - an interface on which RPC methods are looked up
 * @param in - inputstream to listen for incoming messages
 * @param out - outputstream to send outgoing messages
 * @param executorService - the executor service used to start threads
 * @param wrapper - a function for plugging in additional message consumers
 * @param configureGson - a function for Gson configuration
 */
static <T> Launcher<T> createIoLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out,
        ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper, Consumer<GsonBuilder> configureGson) {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<String, JsonRpcMethod>();
    supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));

    if (localService instanceof JsonRpcMethodProvider) {
        JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
        supportedMethods.putAll(rpcMethodProvider.supportedMethods());
    } else {
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
    }

    MessageJsonHandler jsonHandler = new MessageJsonHandler(supportedMethods, configureGson);
    MessageConsumer outGoingMessageStream = new StreamMessageConsumer(out, jsonHandler);
    outGoingMessageStream = wrapper.apply(outGoingMessageStream);
    RemoteEndpoint serverEndpoint = new RemoteEndpoint(outGoingMessageStream, ServiceEndpoints.toEndpoint(localService));
    jsonHandler.setMethodProvider(serverEndpoint);
    // wrap incoming message stream
    MessageConsumer messageConsumer = wrapper.apply(serverEndpoint);
    StreamMessageProducer reader = new StreamMessageProducer(in, jsonHandler);

    T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);

    return new Launcher<T> () {

        @Override
        public Future<?> startListening() {
            return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, executorService);
        }

        @Override
        public T getRemoteProxy() {
            return remoteProxy;
        }

    };
}
项目:xtext-core    文件:TestLangLSPExtension.java   
@Override
public void initialize(final ILanguageServerAccess access) {
  this.access = access;
  this.access.addBuildListener(this);
  LanguageClient _languageClient = access.getLanguageClient();
  this.client = ServiceEndpoints.<TestLangLSPExtension.CustomClient>toServiceObject(((Endpoint) _languageClient), TestLangLSPExtension.CustomClient.class);
}
项目:xtext-core    文件:TestLangLSPExtension.java   
@Override
public Map<String, JsonRpcMethod> supportedMethods() {
  final HashMap<String, JsonRpcMethod> result = CollectionLiterals.<String, JsonRpcMethod>newHashMap();
  result.putAll(ServiceEndpoints.getSupportedMethods(this.getClass()));
  result.putAll(ServiceEndpoints.getSupportedMethods(TestLangLSPExtension.CustomClient.class));
  return result;
}
项目:lsp4j    文件:JsonSerializeTest.java   
@Before
public void setup() {
  final Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class);
  this.jsonHandler = new MessageJsonHandler(methods) {
    @Override
    public GsonBuilder getDefaultGsonBuilder() {
      return super.getDefaultGsonBuilder().setPrettyPrinting();
    }
  };
}
项目:lsp4j    文件:JsonParseTest.java   
@Before
public void setup() {
  final Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class);
  final Map<String, JsonRpcMethod> clientMethods = ServiceEndpoints.getSupportedMethods(LanguageClient.class);
  final HashMap<String, JsonRpcMethod> all = new HashMap<String, JsonRpcMethod>();
  all.putAll(methods);
  all.putAll(clientMethods);
  MessageJsonHandler _messageJsonHandler = new MessageJsonHandler(all);
  this.jsonHandler = _messageJsonHandler;
}
项目:lsp4j    文件:DebugLauncher.java   
/**
 * Create a new Launcher for a given local service object, a given remote
 * interface and an input and output stream. Threads are started with the given
 * executor service. The wrapper function is applied to the incoming and
 * outgoing message streams so additional message handling such as validation
 * and tracing can be included. The {@code configureGson} function can be used
 * to register additional type adapters in the {@link GsonBuilder} in order to
 * support protocol classes that cannot be handled by Gson's reflective
 * capabilities.
 *
 * @param localService
 *            - an object on which classes RPC methods are looked up
 * @param remoteInterface
 *            - an interface on which RPC methods are looked up
 * @param in
 *            - inputstream to listen for incoming messages
 * @param out
 *            - outputstream to send outgoing messages
 * @param executorService
 *            - the executor service used to start threads
 * @param wrapper
 *            - a function for plugging in additional message consumers
 * @param configureGson
 *            - a function for Gson configuration
 */
static <T> DebugLauncher<T> createIoLauncher(Object localService, Class<T> remoteInterface, InputStream in,
        OutputStream out, ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper,
        Consumer<GsonBuilder> configureGson) {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<String, JsonRpcMethod>();
    supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));

    if (localService instanceof JsonRpcMethodProvider) {
        JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
        supportedMethods.putAll(rpcMethodProvider.supportedMethods());
    } else {
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
    }

    MessageJsonHandler jsonHandler = new DebugMessageJsonHandler(supportedMethods, configureGson);
    MessageConsumer outGoingMessageStream = new StreamMessageConsumer(out, jsonHandler);
    outGoingMessageStream = wrapper.apply(outGoingMessageStream);
    RemoteEndpoint serverEndpoint = new DebugRemoteEndpoint(outGoingMessageStream,
            ServiceEndpoints.toEndpoint(localService));
    jsonHandler.setMethodProvider(serverEndpoint);
    // wrap incoming message stream
    MessageConsumer messageConsumer = wrapper.apply(serverEndpoint);
    StreamMessageProducer reader = new StreamMessageProducer(in, jsonHandler);

    T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);

    return new DebugLauncher<T>() {

        @Override
        public Future<?> startListening() {
            return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, executorService);
        }

        @Override
        public T getRemoteProxy() {
            return remoteProxy;
        }

    };
}
项目:lsp4j    文件:Launcher.java   
/**
 * Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
 * Threads are started with the given executor service. The wrapper function is applied to the incoming and
 * outgoing message streams so additional message handling such as validation and tracing can be included.
 * The {@code configureGson} function can be used to register additional type adapters in the {@link GsonBuilder}
 * in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
 * 
 * @param localService - an object on which classes RPC methods are looked up
 * @param remoteInterface - an interface on which RPC methods are looked up
 * @param in - inputstream to listen for incoming messages
 * @param out - outputstream to send outgoing messages
 * @param executorService - the executor service used to start threads
 * @param wrapper - a function for plugging in additional message consumers
 * @param configureGson - a function for Gson configuration
 */
static <T> Launcher<T> createIoLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out,
        ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper, Consumer<GsonBuilder> configureGson) {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<String, JsonRpcMethod>();
    supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));

    if (localService instanceof JsonRpcMethodProvider) {
        JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
        supportedMethods.putAll(rpcMethodProvider.supportedMethods());
    } else {
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
    }

    MessageJsonHandler jsonHandler = new MessageJsonHandler(supportedMethods, configureGson);
    MessageConsumer outGoingMessageStream = new StreamMessageConsumer(out, jsonHandler);
    outGoingMessageStream = wrapper.apply(outGoingMessageStream);
    RemoteEndpoint serverEndpoint = new RemoteEndpoint(outGoingMessageStream, ServiceEndpoints.toEndpoint(localService));
    jsonHandler.setMethodProvider(serverEndpoint);
    // wrap incoming message stream
    MessageConsumer messageConsumer = wrapper.apply(serverEndpoint);
    StreamMessageProducer reader = new StreamMessageProducer(in, jsonHandler);

    T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);

    return new Launcher<T> () {

        @Override
        public Future<?> startListening() {
            return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, executorService);
        }

        @Override
        public T getRemoteProxy() {
            return remoteProxy;
        }

    };
}
项目:lsp4j    文件:EndpointsTest.java   
@Test public void testRpcMethods_01() {
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Foo.class);

    assertEquals("foo/doStuff", methods.get("foo/doStuff").getMethodName());
    assertEquals(String.class, methods.get("foo/doStuff").getParameterTypes()[0]);
    assertFalse(methods.get("foo/doStuff").isNotification());

    assertEquals("foo/myNotification", methods.get("foo/myNotification").getMethodName());
    assertEquals(String.class, methods.get("foo/myNotification").getParameterTypes()[0]);
    assertTrue(methods.get("foo/myNotification").isNotification());

    assertEquals("hubba", methods.get("hubba").getMethodName());
    assertEquals(String.class, methods.get("hubba").getParameterTypes()[0]);
    assertTrue(methods.get("hubba").isNotification());
}
项目:lsp4j    文件:EndpointsTest.java   
@Test public void testIssue107() {
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(StringConsumer.class);
    final JsonRpcMethod method = methods.get("consumer/accept");
    assertEquals("consumer/accept", method.getMethodName());
    assertEquals(1, method.getParameterTypes().length);
    assertEquals(String.class, method.getParameterTypes()[0]);
    assertTrue(method.isNotification());
}
项目:lsp4j    文件:RpcMethodTest.java   
@Test public void testDocumentSymbol() {
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class);
    JsonRpcMethod jsonRpcMethod = methods.get("textDocument/documentSymbol");
    Assert.assertNotNull(jsonRpcMethod);
}
项目:lsp4j    文件:RpcMethodTest.java   
@Test public void testCodelensResolve() {
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class);
    Assert.assertNotNull(methods.get("codeLens/resolve"));
    Assert.assertNotNull(methods.get("completionItem/resolve"));
}
项目:lsp4j    文件:EndpointsTest.java   
@Test public void testIssue106() {
    Foo foo = ServiceEndpoints.toServiceObject(new GenericEndpoint(new Object()), Foo.class);
    assertEquals(foo, foo);
}