org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints Java Examples

The following examples show how to use org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints. 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: EndpointsTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testRpcMethods_02() {
	Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Bar.class);
	
	final JsonRpcMethod requestMethod = methods.get("bar/doStuff2");
	assertEquals("bar/doStuff2", 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/myNotification2");
	assertEquals("bar/myNotification2", 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());
}
 
Example #2
Source File: Launcher.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gather all JSON-RPC methods from the local and remote services.
 */
protected Map<String, JsonRpcMethod> getSupportedMethods() {
	Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
	// Gather the supported methods of remote interfaces
	for (Class<?> interface_ : remoteInterfaces) {
		supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(interface_));
	}
	
	// Gather the supported methods of local services
	for (Object localService : localServices) {
		if (localService instanceof JsonRpcMethodProvider) {
			JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
			supportedMethods.putAll(rpcMethodProvider.supportedMethods());
		} else {
			supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
		}
	}
	
	return supportedMethods;
}
 
Example #3
Source File: LauncherTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: DSPLauncherTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@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 = DSPLauncher.createServerLauncher(
			ServiceEndpoints.toServiceObject(server, IDebugProtocolServer.class), inServer, outServer);
	serverListening = serverLauncher.startListening();

	client = new AssertingEndpoint();
	clientLauncher = DSPLauncher.createClientLauncher(
			ServiceEndpoints.toServiceObject(client, IDebugProtocolClient.class), inClient, outClient);
	clientListening = clientLauncher.startListening();

	Logger logger = Logger.getLogger(StreamMessageProducer.class.getName());
	logLevel = logger.getLevel();
	logger.setLevel(Level.SEVERE);
}
 
Example #5
Source File: NullResponseTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNullResponse() throws InterruptedException, ExecutionException {
	LogMessageAccumulator logMessages = new LogMessageAccumulator();
	try {
		logMessages.registerTo(GenericEndpoint.class);
		
		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)));
	} finally {
		logMessages.unregister();
	}
}
 
Example #6
Source File: EndpointsTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #7
Source File: EndpointsTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #8
Source File: Launcher.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create the proxy for calling methods on the remote service.
 */
@SuppressWarnings("unchecked")
protected T createProxy(RemoteEndpoint remoteEndpoint) {
	if (localServices.size() == 1 && remoteInterfaces.size() == 1) {
		return ServiceEndpoints.toServiceObject(remoteEndpoint, remoteInterfaces.iterator().next());
	} else {
		return (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection<Class<?>>) (Object) remoteInterfaces, classLoader);
	}
}
 
Example #9
Source File: Launcher.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create the remote endpoint that communicates with the local services.
 */
protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
	MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler);
	outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream);
	Endpoint localEndpoint = ServiceEndpoints.toEndpoint(localServices);
	RemoteEndpoint remoteEndpoint;
	if (exceptionHandler == null)
		remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, localEndpoint);
	else
		remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, localEndpoint, exceptionHandler);
	jsonHandler.setMethodProvider(remoteEndpoint);
	return remoteEndpoint;
}
 
Example #10
Source File: DebugLauncher.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
	MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler);
	outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream);
	Endpoint localEndpoint = ServiceEndpoints.toEndpoint(localServices);
	RemoteEndpoint remoteEndpoint;
	if (exceptionHandler == null)
		remoteEndpoint = new DebugRemoteEndpoint(outgoingMessageStream, localEndpoint);
	else
		remoteEndpoint = new DebugRemoteEndpoint(outgoingMessageStream, localEndpoint, exceptionHandler);
	jsonHandler.setMethodProvider(remoteEndpoint);
	return remoteEndpoint;
}
 
Example #11
Source File: PatchedLauncherBuilder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
	MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler);
	outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream);
	Endpoint localEndpoint = ServiceEndpoints.toEndpoint(localServices);
	RemoteEndpoint remoteEndpoint;
	if (exceptionHandler == null)
		remoteEndpoint = new PatchedRemoteEndpoint(outgoingMessageStream, localEndpoint);
	else
		remoteEndpoint = new PatchedRemoteEndpoint(outgoingMessageStream, localEndpoint, exceptionHandler);
	jsonHandler.setMethodProvider(remoteEndpoint);
	return remoteEndpoint;
}
 
Example #12
Source File: WebSocketLauncherBuilder.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) {
	MessageConsumer outgoingMessageStream = new WebSocketMessageConsumer(session, jsonHandler);
	outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream);
	Endpoint localEndpoint = ServiceEndpoints.toEndpoint(localServices);
	RemoteEndpoint remoteEndpoint;
	if (exceptionHandler == null)
		remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, localEndpoint);
	else
		remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, localEndpoint, exceptionHandler);
	jsonHandler.setMethodProvider(remoteEndpoint);
	return remoteEndpoint;
}
 
Example #13
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
@BeforeEach
public void setup() {
  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.toServiceObject(this, this.getLanguageClientClass()));
  this.languageServer.supportedMethods();
  File _absoluteFile = new File("").getAbsoluteFile();
  File _file = new File(_absoluteFile, AbstractLanguageServerTest.TEST_PROJECT_PATH);
  this.root = _file;
}
 
Example #14
Source File: LspExtensionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExtension_readIndex() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type C {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op baz() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("type A {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op foo() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("type B {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("op bar() { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.writeFile("model.testlang", _builder);
    this.initialize();
    final TestLangLSPExtension ext = ServiceEndpoints.<TestLangLSPExtension>toServiceObject(this.languageServer, TestLangLSPExtension.class);
    final List<String> actual = IterableExtensions.<String>sort(IterableExtensions.<String>toList(ext.getAllOpNames().get()));
    Assert.assertEquals(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("bar", "baz", "foo")), actual);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #15
Source File: TestLangLSPExtension.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Map<String, JsonRpcMethod> supportedMethods() {
	HashMap<String, JsonRpcMethod> result = new HashMap<>();
	result.putAll(ServiceEndpoints.getSupportedMethods(getClass()));
	result.putAll(ServiceEndpoints.getSupportedMethods(CustomClient.class));
	return result;
}
 
Example #16
Source File: RpcMethodTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCodelensResolve() {
	Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class);
	Assert.assertNotNull(methods.get("codeLens/resolve"));
	Assert.assertNotNull(methods.get("completionItem/resolve"));
}
 
Example #17
Source File: RpcMethodTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testDocumentSymbol() {
	Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class);
	JsonRpcMethod jsonRpcMethod = methods.get("textDocument/documentSymbol");
	Assert.assertNotNull(jsonRpcMethod);
}
 
Example #18
Source File: EndpointsTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testIssue106() {
	Foo foo = ServiceEndpoints.toServiceObject(new GenericEndpoint(new Object()), Foo.class);
	assertEquals(foo, foo);
}
 
Example #19
Source File: TestLangLSPExtension.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void initialize(ILanguageServerAccess access) {
	this.access = access;
	this.access.addBuildListener(this);
	this.client = ServiceEndpoints.toServiceObject((Endpoint) access.getLanguageClient(), CustomClient.class);
}