org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage Java Examples
The following examples show how to use
org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage.
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: RemoteEndpoint.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Override public void handle(Message message, List<MessageIssue> issues) { if (issues.isEmpty()) { throw new IllegalArgumentException("The list of issues must not be empty."); } if (message instanceof RequestMessage) { RequestMessage requestMessage = (RequestMessage) message; handleRequestIssues(requestMessage, issues); } else if (message instanceof ResponseMessage) { ResponseMessage responseMessage = (ResponseMessage) message; handleResponseIssues(responseMessage, issues); } else { logIssues(message, issues); } }
Example #2
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testExceptionInCompletableFuture() throws Exception { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); CompletableFuture<Object> future = endpoint.request("foo", "myparam"); CompletableFuture<Void> chained = future.thenAccept(result -> { throw new RuntimeException("BAAZ"); }); endpoint.consume(init(new ResponseMessage(), it -> { it.setId("1"); it.setResult("Bar"); })); try { chained.get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.fail("Expected an ExecutionException."); } catch (ExecutionException exception) { assertEquals("java.lang.RuntimeException: BAAZ", exception.getMessage()); } }
Example #3
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testCancellation() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().cancel(true); ResponseMessage message = (ResponseMessage) consumer.messages.get(0); assertNotNull(message); ResponseError error = message.getError(); assertNotNull(error); assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue()); assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled"); }
Example #4
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testHandleRequestIssues() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.handle(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); }), Collections.singletonList(new MessageIssue("bar"))); ResponseMessage responseMessage = (ResponseMessage) consumer.messages.get(0); assertNotNull(responseMessage.getError()); assertEquals("bar", responseMessage.getError().getMessage()); }
Example #5
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testRequest2() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId(1); it.setMethod("foo"); it.setParams("myparam"); })); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().complete("success"); assertEquals("foo", entry.getKey().getMethod()); assertEquals("myparam", entry.getKey().getParams()); ResponseMessage responseMessage = (ResponseMessage) consumer.messages.get(0); assertEquals("success", responseMessage.getResult()); assertEquals(Either.forRight(1), responseMessage.getRawId()); }
Example #6
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testRequest1() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().complete("success"); assertEquals("foo", entry.getKey().getMethod()); assertEquals("myparam", entry.getKey().getParams()); ResponseMessage responseMessage = (ResponseMessage) consumer.messages.get(0); assertEquals("success", responseMessage.getResult()); assertEquals(Either.forLeft("1"), responseMessage.getRawId()); }
Example #7
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testErrorResponse_AllOrders() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Location>() {}.getType(), new TypeToken<Void>() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"id\":2", "\"message\": \"failed\"", "\"error\": {\"code\": 123456, \"message\": \"failed\", \"data\": {\"uri\": \"failed\"}}" }; testAllPermutations(properties, json -> { ResponseMessage message = (ResponseMessage) handler.parseMessage(json); Assert.assertEquals("failed", message.getError().getMessage()); Object data = message.getError().getData(); JsonObject expected = new JsonObject(); expected.addProperty("uri", "failed"); Assert.assertEquals(expected, data); Assert.assertNull(message.getResult()); }); }
Example #8
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testNormalResponse_AllOrders() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Location>() {}.getType(), new TypeToken<Void>() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"id\":2", "\"result\": {\"uri\": \"dummy://mymodel.mydsl\"}" }; testAllPermutations(properties, json -> { ResponseMessage message = (ResponseMessage) handler.parseMessage(json); Object result = message.getResult(); Class<? extends Object> class1 = result.getClass(); Assert.assertEquals(Location.class, class1); Assert.assertEquals("dummy://mymodel.mydsl", ((Location)result).uri); Assert.assertNull(message.getError()); }); }
Example #9
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testResponseErrorData() { MessageJsonHandler handler = new MessageJsonHandler(Collections.emptyMap()); ResponseMessage message = (ResponseMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"error\": { \"code\": -32001, \"message\": \"foo\",\n" + " \"data\": { \"uri\": \"file:/foo\", \"version\": 5, \"list\": [\"a\", \"b\", \"c\"] }\n" + " }\n" + "}"); ResponseError error = message.getError(); Assert.assertTrue("Expected a JsonObject in error.data", error.getData() instanceof JsonObject); JsonObject data = (JsonObject) error.getData(); Assert.assertEquals("file:/foo", data.get("uri").getAsString()); Assert.assertEquals(5, data.get("version").getAsInt()); JsonArray list = data.get("list").getAsJsonArray(); Assert.assertEquals("a", list.get(0).getAsString()); Assert.assertEquals("b", list.get(1).getAsString()); Assert.assertEquals("c", list.get(2).getAsString()); }
Example #10
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testEither_02() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Either<MyEnum, Map<String,String>>>() {}.getType(), new TypeToken<Object>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"result\": 2\n" + "}"); Either<MyEnum, List<Map<String, String>>> result = (Either<MyEnum, List<Map<String,String>>>) ((ResponseMessage)message).getResult(); Assert.assertTrue(result.isLeft()); Assert.assertEquals(MyEnum.B, result.getLeft()); }
Example #11
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testParseList_02() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Set<Entry>>() {}.getType(), new TypeToken<Set<Entry>>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id)->"foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": [\n" + " {\"name\":\"$schema\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":1,\"character\":3},\"end\":{\"line\":1,\"character\":55}}}},\n" + " {\"name\":\"type\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":2,\"character\":3},\"end\":{\"line\":2,\"character\":19}}}},\n" + " {\"name\":\"title\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":3,\"character\":3},\"end\":{\"line\":3,\"character\":50}}}},\n" + " {\"name\":\"additionalProperties\",\"kind\":17,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":4,\"character\":4},\"end\":{\"line\":4,\"character\":32}}}},\n" + " {\"name\":\"properties\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":5,\"character\":3},\"end\":{\"line\":5,\"character\":20}}}}\n" + "]}"); Set<Entry> result = (Set<Entry>) ((ResponseMessage)message).getResult(); Assert.assertEquals(5, result.size()); for (Entry e : result) { Assert.assertTrue(e.location.uri, e.location.uri.startsWith("file:/home/mistria")); } }
Example #12
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testParseList_01() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<List<? extends Entry>>() {}.getType(), new TypeToken<List<? extends Entry>>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id)->"foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": [\n" + " {\"name\":\"$schema\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":1,\"character\":3},\"end\":{\"line\":1,\"character\":55}}}},\n" + " {\"name\":\"type\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":2,\"character\":3},\"end\":{\"line\":2,\"character\":19}}}},\n" + " {\"name\":\"title\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":3,\"character\":3},\"end\":{\"line\":3,\"character\":50}}}},\n" + " {\"name\":\"additionalProperties\",\"kind\":17,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":4,\"character\":4},\"end\":{\"line\":4,\"character\":32}}}},\n" + " {\"name\":\"properties\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":5,\"character\":3},\"end\":{\"line\":5,\"character\":20}}}}\n" + "]}"); List<? extends Entry> result = (List<? extends Entry>) ((ResponseMessage) message).getResult(); Assert.assertEquals(5, result.size()); for (Entry e : result) { Assert.assertTrue(e.location.uri, e.location.uri.startsWith("file:/home/mistria")); } }
Example #13
Source File: RemoteEndpoint.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
protected void handleResponse(ResponseMessage responseMessage) { PendingRequestInfo requestInfo; synchronized (sentRequestMap) { requestInfo = sentRequestMap.remove(responseMessage.getId()); } if (requestInfo == null) { // We have no pending request information that matches the id given in the response LOG.log(Level.WARNING, "Unmatched response message: " + responseMessage); } else if (responseMessage.getError() != null) { // The remote service has replied with an error requestInfo.future.completeExceptionally(new ResponseErrorException(responseMessage.getError())); } else { // The remote service has replied with a result object requestInfo.future.complete(responseMessage.getResult()); } }
Example #14
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testMissingSuccessResponse_AllOrders() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Location>() {}.getType(), new TypeToken<Void>() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", "\"request_seq\":5", "\"message\": \"failed\"", "\"body\": {\"uri\": \"failed\"}" }; testAllPermutations(properties, json -> { ResponseMessage message = (ResponseMessage) handler.parseMessage(json); Assert.assertEquals("failed", message.getError().getMessage()); Object data = message.getError().getData(); Map<String, String> expected = new HashMap<>(); expected.put("uri", "failed"); Assert.assertEquals(expected, data); Assert.assertNull(message.getResult()); }); }
Example #15
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testNormalResponseExtraFields_AllOrders() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Location>() {}.getType(), new TypeToken<Void>() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", "\"request_seq\":5", "\"success\":true", "\"body\": {\"uri\": \"dummy://mymodel.mydsl\"}", "\"message\": null" }; testAllPermutations(properties, json -> { ResponseMessage message = (ResponseMessage) handler.parseMessage(json); Object result = message.getResult(); Class<? extends Object> class1 = result.getClass(); Assert.assertEquals(Location.class, class1); Assert.assertEquals("dummy://mymodel.mydsl", ((Location)result).uri); Assert.assertNull(message.getError()); }); }
Example #16
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testNormalResponse_AllOrders() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Location>() {}.getType(), new TypeToken<Void>() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", "\"request_seq\":5", "\"success\":true", "\"body\": {\"uri\": \"dummy://mymodel.mydsl\"}" }; testAllPermutations(properties, json -> { ResponseMessage message = (ResponseMessage) handler.parseMessage(json); Object result = message.getResult(); Class<? extends Object> class1 = result.getClass(); Assert.assertEquals(Location.class, class1); Assert.assertEquals("dummy://mymodel.mydsl", ((Location)result).uri); Assert.assertNull(message.getError()); }); }
Example #17
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testEither_02() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Either<Integer, Map<String,String>>>() {}.getType(), new TypeToken<Object>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" + "\"success\":true,\n" + "\"body\": 2\n" + "}"); Either<Integer, List<Map<String, String>>> result = (Either<Integer, List<Map<String,String>>>) ((ResponseMessage)message).getResult(); Assert.assertTrue(result.isLeft()); Assert.assertEquals(Integer.valueOf(2), result.getLeft()); }
Example #18
Source File: HTMLLanguageServer.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Override public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) { if (message instanceof ResponseMessage) { ResponseMessage responseMessage = (ResponseMessage) message; if (responseMessage.getResult() instanceof InitializeResult) { Map<String, Object> htmlOptions = new HashMap<>(); Map<String, Object> validateOptions = new HashMap<>(); validateOptions.put("scripts", true); validateOptions.put("styles", true); htmlOptions.put("validate", validateOptions); htmlOptions.put("format", Collections.singletonMap("enable", Boolean.TRUE)); Map<String, Object> html = new HashMap<>(); html.put("html", htmlOptions); DidChangeConfigurationParams params = new DidChangeConfigurationParams(html); languageServer.getWorkspaceService().didChangeConfiguration(params); } } }
Example #19
Source File: DebugRemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testRequest() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new DebugRemoteEndpoint(consumer, endp); endpoint.consume(new RequestMessage() {{ setId("1"); setMethod("foo"); setParams("myparam"); }}); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().complete("success"); assertEquals("foo", entry.getKey().getMethod()); assertEquals("myparam", entry.getKey().getParams()); assertEquals("success", ((ResponseMessage)consumer.messages.get(0)).getResult()); }
Example #20
Source File: DebugRemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testCancellation() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new DebugRemoteEndpoint(consumer, endp); endpoint.consume(new RequestMessage() {{ setId("1"); setMethod("foo"); setParams("myparam"); }}); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().cancel(true); ResponseMessage message = (ResponseMessage) consumer.messages.get(0); assertNotNull(message); ResponseError error = message.getError(); assertNotNull(error); assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue()); assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled"); }
Example #21
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testParseList_02() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Set<Entry>>() {}.getType(), new TypeToken<Set<Entry>>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id)->"foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" + "\"success\":true,\n" + " \"body\": [\n" + " {\"name\":\"$schema\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":1,\"character\":3},\"end\":{\"line\":1,\"character\":55}}}},\n" + " {\"name\":\"type\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":2,\"character\":3},\"end\":{\"line\":2,\"character\":19}}}},\n" + " {\"name\":\"title\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":3,\"character\":3},\"end\":{\"line\":3,\"character\":50}}}},\n" + " {\"name\":\"additionalProperties\",\"kind\":17,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":4,\"character\":4},\"end\":{\"line\":4,\"character\":32}}}},\n" + " {\"name\":\"properties\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":5,\"character\":3},\"end\":{\"line\":5,\"character\":20}}}}\n" + "]}"); Set<Entry> result = (Set<Entry>) ((ResponseMessage)message).getResult(); Assert.assertEquals(5, result.size()); for (Entry e : result) { Assert.assertTrue(e.location.uri, e.location.uri.startsWith("file:/home/mistria")); } }
Example #22
Source File: DebugMessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testParseList() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<List<? extends Entry>>() {}.getType(), new TypeToken<List<? extends Entry>>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); handler.setMethodProvider((id)->"foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" + "\"success\":true,\n" + " \"body\": [\n" + " {\"name\":\"$schema\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":1,\"character\":3},\"end\":{\"line\":1,\"character\":55}}}},\n" + " {\"name\":\"type\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":2,\"character\":3},\"end\":{\"line\":2,\"character\":19}}}},\n" + " {\"name\":\"title\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":3,\"character\":3},\"end\":{\"line\":3,\"character\":50}}}},\n" + " {\"name\":\"additionalProperties\",\"kind\":17,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":4,\"character\":4},\"end\":{\"line\":4,\"character\":32}}}},\n" + " {\"name\":\"properties\",\"kind\":15,\"location\":{\"uri\":\"file:/home/mistria/runtime-EclipseApplication-with-patch/EclipseConEurope/something.json\",\"range\":{\"start\":{\"line\":5,\"character\":3},\"end\":{\"line\":5,\"character\":20}}}}\n" + "]}"); List<? extends Entry> result = (List<? extends Entry>) ((ResponseMessage)message).getResult(); Assert.assertEquals(5, result.size()); for (Entry e : result) { Assert.assertTrue(e.location.uri, e.location.uri.startsWith("file:/home/mistria")); } }
Example #23
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testParseEmptyList() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<List<? extends Entry>>() {}.getType(), new TypeToken<List<? extends Entry>>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id)->"foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": []}"); List<Entry> result = (List<Entry>) ((ResponseMessage)message).getResult(); Assert.assertEquals(0, result.size()); }
Example #24
Source File: LanguageServerWrapper.java From lsp4intellij with Apache License 2.0 | 5 votes |
public void logMessage(Message message) { if (message instanceof ResponseMessage) { ResponseMessage responseMessage = (ResponseMessage) message; if (responseMessage.getError() != null && (responseMessage.getId() .equals(Integer.toString(ResponseErrorCode.RequestCancelled.getValue())))) { LOG.error(new ResponseErrorException(responseMessage.getError())); } } }
Example #25
Source File: RemoteEndpointTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testExceptionInEndpoint() { LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); TestEndpoint endp = new TestEndpoint() { @Override public CompletableFuture<Object> request(String method, Object parameter) { throw new RuntimeException("BAAZ"); } }; TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); ResponseMessage response = (ResponseMessage) consumer.messages.get(0); assertEquals("Internal error.", response.getError().getMessage()); assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); String exception = (String) response.getError().getData(); String expected = "java.lang.RuntimeException: BAAZ\n\tat org.eclipse.lsp4j.jsonrpc.test.RemoteEndpointTest"; assertEquals(expected, exception.replaceAll("\\r", "").substring(0, expected.length())); } finally { logMessages.unregister(); } }
Example #26
Source File: LanguageServerWrapper.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private void logMessage(Message message) { if (message instanceof ResponseMessage && ((ResponseMessage) message).getError() != null && ((ResponseMessage) message).getId() .equals(Integer.toString(ResponseErrorCode.RequestCancelled.getValue()))) { ResponseMessage responseMessage = (ResponseMessage) message; LOGGER.warn("", new ResponseErrorException(responseMessage.getError())); } else if (LOGGER.isDebugEnabled()) { LOGGER.info(message.getClass().getSimpleName() + '\n' + message.toString()); } }
Example #27
Source File: CSSLanguageServer.java From wildwebdeveloper with Eclipse Public License 2.0 | 5 votes |
@Override public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) { if (message instanceof ResponseMessage) { ResponseMessage responseMessage = (ResponseMessage)message; if (responseMessage.getResult() instanceof InitializeResult) { // enable validation: so far, no better way found than changing conf after init. DidChangeConfigurationParams params = new DidChangeConfigurationParams(getInitializationOptions(rootUri)); languageServer.getWorkspaceService().didChangeConfiguration(params); } } }
Example #28
Source File: JSonLanguageServer.java From wildwebdeveloper with Eclipse Public License 2.0 | 5 votes |
@Override public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) { if (message instanceof ResponseMessage) { ResponseMessage responseMessage = (ResponseMessage) message; if (responseMessage.getResult() instanceof InitializeResult) { // Send json/schemaAssociations notification to register JSON Schema on JSON // Language server side. JSonLanguageServerInterface server = (JSonLanguageServerInterface) languageServer; Map<String, List<String>> schemaAssociations = getSchemaAssociations(); server.sendJSonchemaAssociations(schemaAssociations); } } }
Example #29
Source File: ValidationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testInvalidCodeLens() { ResponseMessage message = new ResponseMessage(); message.setId("1"); CodeLens codeLens = new CodeLens(new Range(new Position(3, 32), new Position(3, 35)), null, null); // forbidden self reference! codeLens.setData(codeLens); message.setResult(codeLens); assertIssues(message, "An element of the message has a direct or indirect reference to itself."); }
Example #30
Source File: MessageJsonHandlerTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) @Test public void testEither_05() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken<Either<List<MyClass>, MyClassList>>() {}.getType(), new TypeToken<Object>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); handler.setMethodProvider((id) -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"result\": [{\n" + " value:\"foo\"\n" + "}]}"); Either<List<MyClass>, MyClassList> result = (Either<List<MyClass>, MyClassList>) ((ResponseMessage)message).getResult(); Assert.assertTrue(result.isLeft()); Assert.assertEquals("foo", result.getLeft().get(0).getValue()); message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"result\": {\n" + " items: [{\n" + " value:\"bar\"\n" + "}]}}"); result = (Either<List<MyClass>, MyClassList>) ((ResponseMessage)message).getResult(); Assert.assertTrue(result.isRight()); Assert.assertEquals("bar", result.getRight().getItems().get(0).getValue()); }