Java Code Examples for org.eclipse.lsp4j.jsonrpc.messages.Either#isRight()

The following examples show how to use org.eclipse.lsp4j.jsonrpc.messages.Either#isRight() . 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
private boolean shouldPrepareRename(ILanguageServerAccess access) {
	Either<Boolean, RenameOptions> provider = null;
	if (access != null) {
		InitializeResult initializeResult = access.getInitializeResult();
		if (initializeResult != null) {
			ServerCapabilities capabilities = initializeResult.getCapabilities();
			if (capabilities != null) {
				provider = capabilities.getRenameProvider();
			}
		}
	}
	if (provider != null && provider.isRight()) {
		return Boolean.TRUE.equals(provider.getRight().getPrepareProvider());
	} else {
		return false;
	}
}
 
Example 2
Source Project: lsp4intellij   File: EditorEventManager.java    License: Apache License 2.0 5 votes vote down vote up
private String extractLabel(SignatureInformation signatureInformation, Either<String, Tuple.Two<Integer, Integer>> label) {
    if (label.isLeft()) {
        return label.getLeft();
    } else if (label.isRight()) {
        return signatureInformation.getLabel().substring(label.getRight().getFirst(), label.getRight().getSecond());
    } else {
        return "";
    }
}
 
Example 3
public void documentSaved(long timestamp) {
    this.modificationStamp = timestamp;
    ServerCapabilities serverCapabilities = languageServerWrapper.getServerCapabilities();
    if(serverCapabilities != null ) {
        Either<TextDocumentSyncKind, TextDocumentSyncOptions> textDocumentSync = serverCapabilities.getTextDocumentSync();
        if(textDocumentSync.isRight() && textDocumentSync.getRight().getSave() == null) {
            return;
        }
    }
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri.toString());
    DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(identifier, document.getText());
    languageServerWrapper.getInitializedServer().thenAcceptAsync(ls -> ls.getTextDocumentService().didSave(params));
}
 
Example 4
/**
 * Checks if the action has the same title as this. If it has, then assert that
 * that action is equivalent to this in kind and content.
 */
public void assertEquivalent(Either<Command, CodeAction> action) throws Exception {
	String title = getTitle(action);
	assertEquals("Unexpected command :", name, title);
	if (!ALL_KINDS.equals(kind) && action.isRight()) {
		assertEquals(title + " has the wrong kind ", kind, action.getRight().getKind());
	}
	String actionContent = evaluateCodeActionCommand(action);
	assertEquals(title + " has the wrong content ", content, actionContent);
}
 
Example 5
private void writeIntId(JsonWriter out, Either<String, Number> id) throws IOException {
	if (id == null)
		writeNullValue(out);
	else if (id.isLeft())
		out.value(Integer.parseInt(id.getLeft()));
	else if (id.isRight())
		out.value(id.getRight());
}
 
Example 6
protected void writeId(JsonWriter out, Either<String, Number> id) throws IOException {
	if (id == null)
		writeNullValue(out);
	else if (id.isLeft())
		out.value(id.getLeft());
	else if (id.isRight())
		out.value(id.getRight());
}
 
Example 7
private boolean checkCodeActionProvider(Either<Boolean, CodeActionOptions> provider) {
    return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
            && provider.getRight() != null));
}
 
Example 8
Source Project: MSPaintIDE   File: DefaultRequestManager.java    License: MIT License 4 votes vote down vote up
private boolean checkProvider(Either<Boolean, StaticRegistrationOptions> provider) {
    return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
            && provider.getRight() != null));
}
 
Example 9
Source Project: MSPaintIDE   File: DefaultRequestManager.java    License: MIT License 4 votes vote down vote up
private boolean checkCodeActionProvider(Either<Boolean, CodeActionOptions> provider) {
    return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
            && provider.getRight() != null));
}
 
Example 10
/**
 * Validate all fields of the given object.
 */
protected void validate(Object object, List<MessageIssue> issues, Deque<Object> objectStack, Deque<Object> accessorStack) throws Exception {
	if (object == null 
			|| object instanceof Enum<?> 
			|| object instanceof String 
			|| object instanceof Number
			|| object instanceof Boolean
			|| object instanceof JsonElement
			|| object instanceof Throwable) {
		return;
	}
	if (objectStack.contains(object)) {
		issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself."
				+ " Path: " + createPathString(accessorStack),
				ResponseErrorCode.InvalidParams.getValue()));
		return;
	}
	objectStack.push(object);
	if (object instanceof List<?>) {
		ListIterator<?> iter = ((List<?>) object).listIterator();
		while (iter.hasNext()) {
			accessorStack.push(iter.nextIndex());
			Object element = iter.next();
			if (element == null) {
				issues.add(new MessageIssue("Lists must not contain null references."
						+ " Path: " + createPathString(accessorStack),
						ResponseErrorCode.InvalidParams.getValue()));
			}
			validate(element, issues, objectStack, accessorStack);
			accessorStack.pop();
		}
	} else if (object instanceof Either<?, ?>) {
		Either<?, ?> either = (Either<?, ?>) object;
		if (either.isLeft()) {
			validate(either.getLeft(), issues, objectStack, accessorStack);
		} else if (either.isRight()) {
			validate(either.getRight(), issues, objectStack, accessorStack);
		} else {
			issues.add(new MessageIssue("An Either instance must not be empty."
					 + " Path: " + createPathString(accessorStack),
					ResponseErrorCode.InvalidParams.getValue()));
		}
	} else {
		for (Method method : object.getClass().getMethods()) {
			if (isGetter(method)) {
				accessorStack.push(method);
				Object value = method.invoke(object);
				if (value == null && method.getAnnotation(NonNull.class) != null) {
					issues.add(new MessageIssue("The accessor '" + method.getDeclaringClass().getSimpleName()
							 + "." + method.getName() + "()' must return a non-null value."
							 + " Path: " + createPathString(accessorStack),
							ResponseErrorCode.InvalidParams.getValue()));
				}
				validate(value, issues, objectStack, accessorStack);
				accessorStack.pop();
			}
		}
	}
	objectStack.pop();
}