本文整理汇总了Java中org.eclipse.lsp4j.jsonrpc.CompletableFutures类的典型用法代码示例。如果您正苦于以下问题:Java CompletableFutures类的具体用法?Java CompletableFutures怎么用?Java CompletableFutures使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompletableFutures类属于org.eclipse.lsp4j.jsonrpc包,在下文中一共展示了CompletableFutures类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDocumentResolve
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentResolve() throws Exception, ExecutionException {
LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
@Override
public CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params) {
return CompletableFutures.computeAsync(canceler -> {
params.setTarget("resolved");
return params;
});
}
});
CompletableFuture<DocumentLink> future = languageServer.getTextDocumentService().documentLinkResolve(
new DocumentLink(new Range(new Position(0, 0), new Position(0, 0)), "unresolved")
);
DocumentLink resolved = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals("resolved", resolved.getTarget());
}
示例2: resolveCompletionItem
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Override
public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem unresolved) {
return CompletableFutures.computeAsync(
cancel -> {
server.configured().docs.resolveCompletionItem(unresolved);
return unresolved;
});
}
示例3: testDocumentLink_01
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentLink_01() throws Exception, ExecutionException {
LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
@Override
public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) {
return CompletableFutures.computeAsync(canceler -> {
return new ArrayList<>();
});
}
});
CompletableFuture<List<DocumentLink>> future = languageServer.getTextDocumentService().documentLink(new DocumentLinkParams(new TextDocumentIdentifier("test")));
List<DocumentLink> list = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertTrue(list.isEmpty());
}
示例4: testDocumentLink_02
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentLink_02() throws Exception, ExecutionException {
LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
@Override
public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) {
return CompletableFutures.computeAsync(canceler -> {
return null;
});
}
});
CompletableFuture<List<DocumentLink>> future = languageServer.getTextDocumentService().documentLink(new DocumentLinkParams(new TextDocumentIdentifier("test")));
List<DocumentLink> list = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertNull(list);
}
示例5: testCancellationResponse
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
// create client messages
String requestMessage = "{\"type\":\"request\","
+ "\"seq\":1,\n"
+ "\"command\":\"askServer\",\n"
+ "\"arguments\": { value: \"bar\" }\n"
+ "}";
String cancellationMessage = "{\"type\":\"event\","
+ "\"command\":\"$/cancelRequest\",\n"
+ "\"body\": { id: 1 }\n"
+ "}";
String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;
// create server side
ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream();
MyServer server = new MyServer() {
@Override
public CompletableFuture<MyParam> askServer(MyParam param) {
return CompletableFutures.computeAsync(cancelToken -> {
try {
long startTime = System.currentTimeMillis();
do {
cancelToken.checkCanceled();
Thread.sleep(50);
} while (System.currentTimeMillis() - startTime < TIMEOUT);
} catch (InterruptedException e) {
Assert.fail("Thread was interrupted unexpectedly.");
}
return param;
});
}
};
DebugLauncher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out);
serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals("Content-Length: 133\r\n\r\n" +
"{\"type\":\"response\",\"request_seq\":1,\"success\":false,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}",
out.toString());
}
示例6: testCancellationResponse
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
// create client messages
String requestMessage = "{\"type\":\"request\","
+ "\"seq\":1,\n"
+ "\"command\":\"askServer\",\n"
+ "\"arguments\": { value: \"bar\" }\n"
+ "}";
String cancellationMessage = "{\"type\":\"event\","
+ "\"command\":\"$/cancelRequest\",\n"
+ "\"body\": { id: 1 }\n"
+ "}";
String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;
// create server side
ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream();
MyServer server = new MyServer() {
@Override
public CompletableFuture<MyParam> askServer(MyParam param) {
return CompletableFutures.computeAsync(cancelToken -> {
try {
long startTime = System.currentTimeMillis();
do {
cancelToken.checkCanceled();
Thread.sleep(50);
} while (System.currentTimeMillis() - startTime < TIMEOUT);
} catch (InterruptedException e) {
Assert.fail("Thread was interrupted unexpectedly.");
}
return param;
});
}
};
DebugLauncher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out);
serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals("Content-Length: 163\r\n\r\n" +
"{\"type\":\"response\",\"seq\":1,\"request_seq\":1,\"command\":\"askServer\",\"success\":false,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}",
out.toString());
}
示例7: testCancellationResponse
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
// create client messages
String requestMessage = "{\"jsonrpc\":\"2.0\","
+ "\"id\":\"1\",\n"
+ "\"method\":\"askServer\",\n"
+ "\"params\": { value: \"bar\" }\n"
+ "}";
String cancellationMessage = "{\"jsonrpc\":\"2.0\","
+ "\"method\":\"$/cancelRequest\",\n"
+ "\"params\": { id: 1 }\n"
+ "}";
String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;
// create server side
ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream();
MyServer server = new MyServer() {
@Override
public CompletableFuture<MyParam> askServer(MyParam param) {
return CompletableFutures.computeAsync(cancelToken -> {
try {
long startTime = System.currentTimeMillis();
do {
cancelToken.checkCanceled();
Thread.sleep(50);
} while (System.currentTimeMillis() - startTime < TIMEOUT);
} catch (InterruptedException e) {
Assert.fail("Thread was interrupted unexpectedly.");
}
return param;
});
}
};
Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out);
serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals("Content-Length: 132" + CRLF + CRLF
+ "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32800,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}}",
out.toString());
}