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
Source File: Utils.java    From netbeans with 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 2
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 3
Source File: EditorEventManager.java    From lsp4intellij with 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
Source File: DebugMessageTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
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 5
Source File: StringLSP4J.java    From n4js with 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 6
Source File: StringLSP4J.java    From n4js with 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 7
Source File: StringLSP4J.java    From n4js with 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 8
Source File: ReorgQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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 9
Source File: EitherTypeAdapter.java    From lsp4j with 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 10
Source File: StringLSP4J.java    From n4js with 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 11
Source File: MissingEnumQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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 12
Source File: ClientPreferences.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isTagSupported(Either<Boolean, DiagnosticsTagSupport> tagSupport) {
	return tagSupport.isLeft() ? tagSupport.getLeft() : tagSupport.getRight().getValueSet() != null;
}
 
Example 13
Source File: CodeActionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static Command getCommand(Either<Command, CodeAction> codeAction) {
	return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
 
Example 14
Source File: AbstractQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public Command getCommand(Either<Command, CodeAction> codeAction) {
	return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
 
Example 15
Source File: NavigatorPanelImpl.java    From netbeans with 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 16
Source File: LSContentAssistProcessor.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
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 17
Source File: LanguageClientImpl.java    From netbeans with 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 18
Source File: DefaultRequestManager.java    From lsp4intellij with Apache License 2.0 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 19
Source File: DefaultRequestManager.java    From MSPaintIDE with 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 File: DefaultRequestManager.java    From MSPaintIDE with 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));
}