Java 类org.eclipse.lsp4j.jsonrpc.messages.Either 实例源码
项目:camel-language-server
文件:CamelTextDocumentServiceTest.java
@Test
public void testChangeEventUpdatesStoredText() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n");
DidChangeTextDocumentParams changeEvent = new DidChangeTextDocumentParams();
VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
textDocument.setUri(DUMMY_URI);
changeEvent.setTextDocument(textDocument);
TextDocumentContentChangeEvent contentChange = new TextDocumentContentChangeEvent("<to xmlns=\"http://camel.apache.org/schema/blueprint\" uri=\"\"></to>\n");
changeEvent.setContentChanges(Collections.singletonList(contentChange));
camelLanguageServer.getTextDocumentService().didChange(changeEvent);
//check old position doesn't provide completion
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtOldPosition = getCompletionFor(camelLanguageServer, new Position(0, 11));
assertThat(completionsAtOldPosition.get().getLeft()).isEmpty();
//check new position provides completion
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtNewPosition = getCompletionFor(camelLanguageServer, new Position(0, 58));
assertThat(completionsAtNewPosition.get().getLeft()).isNotEmpty();
}
项目:dsp4e
文件:DSPDebugTarget.java
public DSPDebugTarget(ILaunch launch, Process process, InputStream in, OutputStream out,
Map<String, Object> launchArguments) throws CoreException {
super(null);
this.launch = launch;
this.process = process;
DebugLauncher<IDebugProtocolServer> debugProtocolLauncher = DebugLauncher.createLauncher(this,
IDebugProtocolServer.class, in, out, true, new PrintWriter(System.out));
debugProtocolFuture = debugProtocolLauncher.startListening();
debugProtocolServer = debugProtocolLauncher.getRemoteProxy();
complete(debugProtocolServer.initialize(new InitializeRequestArguments().setClientID("lsp4e")
.setAdapterID((String) launchArguments.get("type")).setPathFormat("path")));
Object object = launchArguments.get("program");
targetName = Objects.toString(object, "Debug Adapter Target");
complete(debugProtocolServer.launch(Either.forLeft(launchArguments)));
complete(debugProtocolServer.configurationDone());
IBreakpointManager breakpointManager = getBreakpointManager();
breakpointManager.addBreakpointListener(this);
breakpointManager.addBreakpointManagerListener(this);
breakpointManagerEnablementChanged(breakpointManager.isEnabled());
}
项目:dsp4e
文件:DebugMessageJsonHandlerTest.java
@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()));
DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
handler.setMethodProvider((id) -> "foo");
Message message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": 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());
}
项目:SOMns-vscode
文件:EitherTypeAdapter.java
@SuppressWarnings("unchecked")
protected Either<L, R> create(JsonToken nextToken, JsonReader in) throws IOException {
if (left.isAssignable(nextToken)) {
if (Either3.class.isAssignableFrom(typeToken.getRawType()))
return (Either<L, R>) Either3.forLeft3(left.read(in));
else
return Either.forLeft(left.read(in));
}
if (right.isAssignable(nextToken)) {
if (Either3.class.isAssignableFrom(typeToken.getRawType()))
return (Either<L, R>) Either3.forRight3((Either<?, ?>) right.read(in));
else
return Either.forRight(right.read(in));
}
return null;
}
项目:eclipse.jdt.ls
文件:CompletionHandler.java
Either<List<CompletionItem>, CompletionList> completion(TextDocumentPositionParams position,
IProgressMonitor monitor) {
List<CompletionItem> completionItems = null;
try {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(position.getTextDocument().getUri());
completionItems = this.computeContentAssist(unit,
position.getPosition().getLine(),
position.getPosition().getCharacter(), monitor);
} catch (OperationCanceledException ignorable) {
// No need to pollute logs when query is cancelled
monitor.setCanceled(true);
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Problem with codeComplete for " + position.getTextDocument().getUri(), e);
monitor.setCanceled(true);
}
CompletionList $ = new CompletionList();
if (monitor.isCanceled()) {
$.setIsIncomplete(true);
completionItems = null;
JavaLanguageServerPlugin.logInfo("Completion request cancelled");
} else {
JavaLanguageServerPlugin.logInfo("Completion request completed");
}
$.setItems(completionItems == null ? Collections.emptyList() : completionItems);
return Either.forRight($);
}
项目:eclipse.jdt.ls
文件:JDTLanguageServer.java
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
logInfo(">> document/completion");
CompletionHandler handler = new CompletionHandler();
final IProgressMonitor[] monitors = new IProgressMonitor[1];
CompletableFuture<Either<List<CompletionItem>, CompletionList>> result = computeAsync((cc) -> {
monitors[0] = toMonitor(cc);
if (Boolean.getBoolean(JAVA_LSP_JOIN_ON_COMPLETION)) {
try {
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitors[0]);
} catch (OperationCanceledException ignorable) {
// No need to pollute logs when query is cancelled
} catch (InterruptedException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
return handler.completion(position, monitors[0]);
});
result.join();
if (monitors[0].isCanceled()) {
result.cancel(true);
}
return result;
}
项目:xtext-core
文件:AbstractLanguageServerTest.java
protected String _toExpectation(final Either<?, ?> either) {
StringConcatenation _builder = new StringConcatenation();
{
boolean _isLeft = either.isLeft();
if (_isLeft) {
String _expectation = this.toExpectation(either.getLeft());
_builder.append(_expectation);
_builder.newLineIfNotEmpty();
} else {
String _expectation_1 = this.toExpectation(either.getRight());
_builder.append(_expectation_1);
_builder.newLineIfNotEmpty();
}
}
return _builder.toString();
}
项目:xtext-core
文件:LanguageServerImpl.java
protected Either<List<CompletionItem>, CompletionList> completion(final CancelIndicator origialCancelIndicator, final TextDocumentPositionParams params) {
final LanguageServerImpl.BufferedCancelIndicator cancelIndicator = new LanguageServerImpl.BufferedCancelIndicator(origialCancelIndicator);
final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
ContentAssistService _get = null;
if (resourceServiceProvider!=null) {
_get=resourceServiceProvider.<ContentAssistService>get(ContentAssistService.class);
}
final ContentAssistService contentAssistService = _get;
if ((contentAssistService == null)) {
CompletionList _completionList = new CompletionList();
return Either.<List<CompletionItem>, CompletionList>forRight(_completionList);
}
final Function2<Document, XtextResource, CompletionList> _function = (Document document, XtextResource resource) -> {
return contentAssistService.createCompletionList(document, resource, params, cancelIndicator);
};
final CompletionList completionList = this.workspaceManager.<CompletionList>doRead(uri, _function);
return Either.<List<CompletionItem>, CompletionList>forRight(completionList);
}
项目:lsp4j
文件:LauncherTest.java
@Test public void testRequest() throws Exception {
TextDocumentPositionParams p = new TextDocumentPositionParams();
p.setPosition(new Position(1,1));
p.setTextDocument(new TextDocumentIdentifier("test/foo.txt"));
CompletionList result = new CompletionList();
result.setIsIncomplete(true);
result.setItems(new ArrayList<>());
CompletionItem item = new CompletionItem();
item.setDetail("test");
item.setDocumentation("doc");
item.setFilterText("filter");
item.setInsertText("insert");
item.setKind(CompletionItemKind.Field);
result.getItems().add(item);
server.expectedRequests.put("textDocument/completion", new Pair<>(p, result));
CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = clientLauncher.getRemoteProxy().getTextDocumentService().completion(p);
Assert.assertEquals(Either.forRight(result).toString(), future.get(TIMEOUT, TimeUnit.MILLISECONDS).toString());
client.joinOnEmpty();
}
项目:lsp4j
文件:DebugMessageJsonHandlerTest.java
@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"
+ "\"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());
}
项目:lsp4j
文件:EitherTypeAdapter.java
@SuppressWarnings("unchecked")
protected Either<L, R> create(JsonToken nextToken, JsonReader in) throws IOException {
if (left.isAssignable(nextToken)) {
if (Either3.class.isAssignableFrom(typeToken.getRawType()))
return (Either<L, R>) Either3.forLeft3(left.read(in));
else
return Either.forLeft(left.read(in));
}
if (right.isAssignable(nextToken)) {
if (Either3.class.isAssignableFrom(typeToken.getRawType()))
return (Either<L, R>) Either3.forRight3((Either<?, ?>) right.read(in));
else
return Either.forRight(right.read(in));
}
return null;
}
项目:lsp4j
文件:MessageJsonHandlerTest.java
@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());
}
项目:che
文件:ToJsonGenerator.java
private void generateToJson(
String indent, PrintWriter out, String varName, String valueAccess, Type paramType) {
if (List.class.isAssignableFrom(getRawClass(paramType))) {
new ListConverter(varName, valueAccess, paramType).generateListConversion(indent, out);
} else if (Map.class.isAssignableFrom(getRawClass(paramType))) {
generateMapConversion(indent, out, varName, valueAccess, paramType);
} else if (Either.class.isAssignableFrom(getRawClass(paramType))) {
generateEitherConversion(indent, out, varName, valueAccess, paramType);
} else {
out.println(
String.format(
indent + "%1$s %2$s = %3$s;",
json.element(),
varName,
jsonValueExpression(getRawClass(paramType), valueAccess)));
}
}
项目:che
文件:FromJsonGenerator.java
private void generateFromJson(
String indent, PrintWriter out, String varName, String valueAccess, Type paramType) {
if (List.class.isAssignableFrom(getRawClass(paramType))) {
generateListConversion(indent, out, varName, valueAccess, paramType);
} else if (Map.class.isAssignableFrom(getRawClass(paramType))) {
generateMapConversion(indent, out, varName, valueAccess, paramType);
} else if (Either.class.isAssignableFrom(getRawClass(paramType))) {
generateEitherConversion(indent, out, varName, valueAccess, paramType);
} else {
out.println(
indent
+ String.format(
"%1$s %2$s = %3$s;",
getRawClass(paramType).getName(),
varName,
fromJsonConversion(getRawClass(paramType), valueAccess)));
}
}
项目:che
文件:ToDtoGenerator.java
private void generateToDto(
String indent, PrintWriter out, String varName, String valueAccess, Type paramType) {
Class<?> rawClass = getRawClass(paramType);
if (List.class.isAssignableFrom(rawClass)) {
generateListConversion(indent + INDENT, out, varName, valueAccess, paramType);
} else if (Map.class.isAssignableFrom(rawClass)) {
generateMapConversion(indent + INDENT, out, varName, valueAccess, paramType);
} else if (Either.class.isAssignableFrom(rawClass)) {
generateEitherConversion(indent + INDENT, out, varName, valueAccess, paramType);
} else {
out.println(
String.format(
indent + "%1$s %2$s = %3$s;",
rawClass.getName(),
varName,
dtoValueExpression(rawClass, valueAccess)));
}
}
项目:che
文件:LanguageServerReconcileStrategy.java
@Inject
public LanguageServerReconcileStrategy(
TextDocumentSynchronizeFactory synchronizeFactory,
@Assisted ServerCapabilities serverCapabilities) {
Either<TextDocumentSyncKind, TextDocumentSyncOptions> sync =
serverCapabilities.getTextDocumentSync();
TextDocumentSyncKind documentSync;
if (sync.isLeft()) {
documentSync = sync.getLeft();
} else {
documentSync = sync.getRight().getChange();
}
synchronize = synchronizeFactory.getSynchronize(documentSync);
}
项目:camel-language-server
文件:HoverFuture.java
@Override
public Hover apply(CamelCatalog camelCatalog) {
Hover hover = new Hover();
ComponentModel componentModel = ModelHelper.generateComponentModel(camelCatalog.componentJSonSchema(componentName), true);
hover.setContents(Collections.singletonList((Either.forLeft(componentModel.getDescription()))));
return hover;
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testProvideCompletionForCamelBlueprintNamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11));
assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem);
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testProvideCompletionForToCamelBlueprintNamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 9));
assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem);
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testProvideCompletionForCamelSpringNamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11));
assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem);
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testProvideCompletionforMultiline() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer(
"<camelContext xmlns=\"http://camel.apache.org/schema/spring\">\n" +
"<to uri=\"\" ></to>\n" +
"</camelContext>");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(1, 9));
assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem);
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testDONTProvideCompletionForNotCamelnamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\"></from>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11));
assertThat(completions.get().getLeft()).isEmpty();
assertThat(completions.get().getRight()).isNull();
}
项目:camel-language-server
文件:CamelLanguageServerTest.java
@Test
public void testDONTProvideCompletionWhenNotAfterURIEqualQuote() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 6));
assertThat(completions.get().getLeft()).isEmpty();
assertThat(completions.get().getRight()).isNull();
}
项目:camel-language-server
文件:CamelComponentOptionBooleanValuesTest.java
private void testProvideCamelOptions(String textTotest, int line, int character) throws URISyntaxException, InterruptedException, ExecutionException {
CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest);
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character));
assertThat(completions.get().getLeft()).contains(
new CompletionItem("true"),
new CompletionItem("false"));
}
项目:camel-language-server
文件:CamelLanguageServerCompletionPositionTest.java
@Test
public void testProvideCompletionForCamelBlueprintNamespace() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer(textToTest);
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character));
if(shouldHaveCompletion) {
assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem);
} else {
assertThat(completions.get().getLeft()).doesNotContain(expectedAhcCompletioncompletionItem);
assertThat(completions.get().getRight()).isNull();
}
}
项目:camel-language-server
文件:CamelComponentOptionEnumerationValuesTest.java
private void testProvideCamelOptions(String textTotest, int line, int character) throws URISyntaxException, InterruptedException, ExecutionException {
CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest);
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character));
assertThat(completions.get().getLeft()).contains(
new CompletionItem("InOnly"),
new CompletionItem("RobustInOnly"),
new CompletionItem("InOut"),
new CompletionItem("InOptionalOut"),
new CompletionItem("OutOnly"),
new CompletionItem("RobustOutOnly"),
new CompletionItem("OutIn"),
new CompletionItem("OutOptionalIn"));
}
项目:camel-language-server
文件:AbstractCamelLanguageServerTest.java
protected CompletableFuture<Either<List<CompletionItem>, CompletionList>> getCompletionFor(CamelLanguageServer camelLanguageServer, Position position) {
TextDocumentService textDocumentService = camelLanguageServer.getTextDocumentService();
TextDocumentPositionParams dummyCompletionPositionRequest = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI), position);
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = textDocumentService.completion(dummyCompletionPositionRequest);
return completions;
}
项目:dsp4e
文件:DebugMessageJsonHandlerTest.java
@SuppressWarnings({ "unchecked" })
@Test
public void testEither_01() {
Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
supportedMethods.put("foo", JsonRpcMethod.request("foo",
new TypeToken<Either<String, List<Map<String,String>>>>() {}.getType(),
new TypeToken<Either<String, Integer>>() {}.getType()));
DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
handler.setMethodProvider((id) -> "foo");
Message message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ " \"body\": [\n"
+ " {\"name\":\"foo\"},\n"
+ " {\"name\":\"bar\"}\n"
+ "]}");
Either<String, List<Map<String, String>>> result = (Either<String, List<Map<String,String>>>) ((ResponseMessage)message).getResult();
Assert.assertTrue(result.isRight());
for (Map<String, String> e : result.getRight()) {
Assert.assertNotNull(e.get("name"));
}
message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": \"name\"\n"
+ "}");
result = (Either<String, List<Map<String,String>>>) ((ResponseMessage)message).getResult();
Assert.assertFalse(result.isRight());
Assert.assertEquals("name",result.getLeft());
}
项目:dsp4e
文件:DebugMessageJsonHandlerTest.java
@SuppressWarnings({ "unchecked" })
@Test
public void testEither_04() {
Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
supportedMethods.put("foo", JsonRpcMethod.request("foo",
new TypeToken<Either<MyClass, List<? extends MyClass>>>() {}.getType(),
new TypeToken<Object>() {}.getType()));
DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
handler.setMethodProvider((id) -> "foo");
Message message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": {\n"
+ " value:\"foo\"\n"
+ "}}");
Either<MyClass, List<? extends MyClass>> result = (Either<MyClass, List<? extends MyClass>>) ((ResponseMessage)message).getResult();
Assert.assertTrue(result.isLeft());
Assert.assertEquals("foo", result.getLeft().getValue());
message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": [{\n"
+ " value:\"bar\"\n"
+ "}]}");
result = (Either<MyClass, List<? extends MyClass>>) ((ResponseMessage)message).getResult();
Assert.assertTrue(result.isRight());
Assert.assertEquals("bar", result.getRight().get(0).getValue());
}
项目:dsp4e
文件:DebugMessageJsonHandlerTest.java
@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()));
DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
handler.setMethodProvider((id) -> "foo");
Message message = handler.parseMessage("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": [{\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("{"
+ "\"seq\":2,\n"
+ "\"type\":\"response\",\n"
+ "\"body\": {\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());
}
项目:vscode-javac
文件:JavaTextDocumentService.java
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
TextDocumentPositionParams position) {
Instant started = Instant.now();
URI uri = URI.create(position.getTextDocument().getUri());
Optional<String> content = activeContent(uri);
int line = position.getPosition().getLine() + 1;
int character = position.getPosition().getCharacter() + 1;
LOG.info(String.format("completion at %s %d:%d", uri, line, character));
Configured config = server.configured();
FocusedResult result = config.compiler.compileFocused(uri, content, line, character, true);
List<CompletionItem> items =
Completions.at(result, config.index, config.docs)
.limit(server.maxItems)
.collect(Collectors.toList());
CompletionList list = new CompletionList(items.size() == server.maxItems, items);
Duration elapsed = Duration.between(started, Instant.now());
if (list.isIncomplete())
LOG.info(
String.format(
"Found %d items (incomplete) in %d ms",
items.size(), elapsed.toMillis()));
else LOG.info(String.format("Found %d items in %d ms", items.size(), elapsed.toMillis()));
return CompletableFuture.completedFuture(Either.forRight(list));
}
项目:vscode-javac
文件:Hovers.java
public static Hover hoverText(Element el, Javadocs docs) {
Optional<String> doc = docs.doc(el).map(Hovers::commentText).map(Javadocs::htmlToMarkdown);
String sig = signature(el);
String result =
doc.map(text -> String.format("```java\n%s\n```\n%s", sig, text)).orElse(sig);
return new Hover(Collections.singletonList(Either.forLeft(result)), null);
}
项目:SOMns-vscode
文件:SomLanguageServer.java
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
final TextDocumentPositionParams position) {
CompletionList result = som.getCompletions(
position.getTextDocument().getUri(), position.getPosition().getLine(),
position.getPosition().getCharacter());
return CompletableFuture.completedFuture(Either.forRight(result));
}
项目:SOMns-vscode
文件:TypeUtils.java
/**
* Test whether the given type is Either.
*/
public static boolean isEither(Type type) {
if (type instanceof ParameterizedType) {
return isEither(((ParameterizedType) type).getRawType());
}
if (type instanceof Class) {
return Either.class.isAssignableFrom((Class<?>) type);
}
return false;
}
项目:SOMns-vscode
文件:EitherTypeAdapter.java
@Override
public void write(JsonWriter out, Either<L, R> value) throws IOException {
if (value == null) {
out.nullValue();
} else if (value.isLeft()) {
left.write(out, value.getLeft());
} else {
right.write(out, value.getRight());
}
}
项目:SOMns-vscode
文件:EitherTypeAdapter.java
@Override
public Either<L, R> read(JsonReader in) throws IOException {
JsonToken next = in.peek();
if (next == JsonToken.NULL) {
return null;
}
Either<L, R> result = create(next, in);
if (result == null)
throw new IOException("Unexpected token " + next + ", expected " + left + " | " + right + " tokens.");
return result;
}
项目:eclipse.jdt.ls
文件:HoverHandler.java
public Hover hover(TextDocumentPositionParams position, IProgressMonitor monitor) {
ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri());
List<Either<String, MarkedString>> content = null;
if (unit != null && !monitor.isCanceled()) {
content = computeHover(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor);
}
Hover $ = new Hover();
$.setContents(content);
return $;
}
项目:eclipse.jdt.ls
文件:InitHandlerTest.java
@Test
public void testWillSaveAndWillSaveWaitUntilCapabilities() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
when(mockCapabilies.isWillSaveRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isWillSaveWaitUntilRegistered()).thenReturn(Boolean.TRUE);
InitializeResult result = initialize(true);
Either<TextDocumentSyncKind, TextDocumentSyncOptions> o = result.getCapabilities().getTextDocumentSync();
assertTrue(o.isRight());
assertTrue(o.getRight().getWillSave());
assertTrue(o.getRight().getWillSaveWaitUntil());
}
项目:xtext-core
文件:LanguageServerImpl.java
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(final TextDocumentPositionParams params) {
final Function1<CancelIndicator, Either<List<CompletionItem>, CompletionList>> _function = (CancelIndicator origialCancelIndicator) -> {
return this.completion(origialCancelIndicator, params);
};
return this.requestManager.<Either<List<CompletionItem>, CompletionList>>runRead(_function);
}
项目:xtext-core
文件:HoverService.java
protected Hover hover(final HoverContext context) {
if ((context == null)) {
return IHoverService.EMPTY_HOVER;
}
final List<Either<String, MarkedString>> contents = this.getContents(context);
if ((contents == null)) {
return IHoverService.EMPTY_HOVER;
}
final Range range = this.getRange(context);
if ((range == null)) {
return IHoverService.EMPTY_HOVER;
}
return new Hover(contents, range);
}