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

The following examples show how to use org.eclipse.lsp4j.jsonrpc.messages.Either#isLeft() . 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
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();
}
 
Example 2
Source Project: netbeans   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static void applyCodeAction(LSPBindings server, Either<Command, CodeAction> cmd) {
    try {
        Command command;

        if (cmd.isLeft()) {
            command = cmd.getLeft();
        } else {
            Utils.applyWorkspaceEdit(cmd.getRight().getEdit());
            command = cmd.getRight().getCommand();
        }
        if (command != null) {
            server.getWorkspaceService().executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments())).get();
        }
    } catch (InterruptedException | ExecutionException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 3
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 4
private TextEdit getTextEdit(Either<Command, CodeAction> codeAction) {
	Command c = codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
	Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
	Assert.assertNotNull(c.getArguments());
	Assert.assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
	WorkspaceEdit we = (WorkspaceEdit) c.getArguments().get(0);
	Iterator<Entry<String, List<TextEdit>>> editEntries = we.getChanges().entrySet().iterator();
	Entry<String, List<TextEdit>> entry = editEntries.next();
	TextEdit edit = entry.getValue().get(0);
	return edit;
}
 
Example 5
Source Project: n4js   File: StringLSP4J.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString2(Either<String, MarkedString> ms) {
	if (ms == null) {
		return "";
	}
	if (ms.isLeft()) {
		return ms.getLeft();
	} else {
		return toString(ms.getRight());
	}
}
 
Example 6
Source Project: lsp4j   File: EitherTypeAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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());
	}
}
 
Example 7
private WorkspaceEdit getWorkspaceEdit(Either<Command, CodeAction> codeAction) {
	Command c = codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
	assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
	assertNotNull(c.getArguments());
	assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
	return (WorkspaceEdit) c.getArguments().get(0);
}
 
Example 8
Source Project: n4js   File: StringLSP4J.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString6(Either<TextDocumentEdit, ResourceOperation> documentChanges) {
	if (documentChanges == null) {
		return "";
	}
	if (documentChanges.isLeft()) {
		return toString(documentChanges.getLeft());
	} else {
		return toString(documentChanges.getRight());
	}
}
 
Example 9
Source Project: n4js   File: StringLSP4J.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString7(Either<String, MarkupContent> documentation) {
	if (documentation == null) {
		return "";
	}
	if (documentation.isLeft()) {
		return documentation.getLeft();
	} else {
		return toString(documentation.getRight());
	}
}
 
Example 10
Source Project: n4js   File: StringLSP4J.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString8(Either<String, Two<Integer, Integer>> documentation) {
	if (documentation == null) {
		return "";
	}
	if (documentation.isLeft()) {
		return documentation.getLeft();
	} else {
		Two<Integer, Integer> right = documentation.getRight();
		return "(" + right.getFirst() + "," + right.getSecond() + ")";
	}
}
 
Example 11
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 12
private boolean checkCodeActionProvider(Either<Boolean, CodeActionOptions> provider) {
    return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
            && provider.getRight() != null));
}
 
Example 13
private Collection<? extends LookupElement> toProposals(Project project, Editor editor, Document document, int offset, Either<List<CompletionItem>, CompletionList> completion, LanguageServer languageServer) {
    List<CompletionItem> items = completion.isLeft()?completion.getLeft():completion.getRight().getItems();
    return items.stream().map(item -> createLookupItem(project, editor, offset, item, languageServer)).collect(Collectors.toList());
    //return Collections.singletonList(LookupElementBuilder.create("quarkus.application.name=").withPresentableText("quarkus.application.name="));
}
 
Example 14
public Command getCommand(Either<Command, CodeAction> codeAction) {
	return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
 
Example 15
public static Command getCommand(Either<Command, CodeAction> codeAction) {
	return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
 
Example 16
private boolean isTagSupported(Either<Boolean, DiagnosticsTagSupport> tagSupport) {
	return tagSupport.isLeft() ? tagSupport.getLeft() : tagSupport.getRight().getValueSet() != null;
}
 
Example 17
Source Project: netbeans   File: NavigatorPanelImpl.java    License: Apache License 2.0 4 votes vote down vote up
private static Children createChildren(String currentFileUri, Either<SymbolInformation, DocumentSymbol> sym) {
    if (sym.isLeft()) {
        return LEAF;
    }
    return createChildren(currentFileUri, sym.getRight());
}
 
Example 18
Source Project: netbeans   File: LanguageClientImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void setBindings(LSPBindings bindings) {
    this.bindings = bindings;
    ServerCapabilities serverCapabilities = bindings.getInitResult().getCapabilities();
    Either<Boolean, CodeActionOptions> codeActions = serverCapabilities.getCodeActionProvider();
    allowCodeActions = codeActions != null && (!codeActions.isLeft() || codeActions.getLeft());
}
 
Example 19
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 20
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));
}