Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many case of usage of Either in LSP4E involve turning Either into a value. That requires some boilerplate: declare variable, if/else. This constructs can allow for instance replacing Either<TextEdit, InsertReplaceEdit> textEdit = item.getTextEdit(); if (textEdit.isLeft()) return offset == LSPEclipseUtils.toOffset(textEdit.getLeft().getRange().getStart(), document); else { Position replace = textEdit.getRight().getReplace().getStart(); Position insert = textEdit.getRight().getInsert().getStart(); Position start = replace; if (replace.getLine() > insert.getLine() || replace.getCharacter() > insert.getCharacter()) start = insert; return offset == LSPEclipseUtils.toOffset(start, document); } by return offset == LSPEclipseUtils.toOffset( textEdit.map( edit -> edit.getRange().getStart(), insertReplaceEdit -> { Position replace = insertReplaceEdit.getReplace().getStart(); Position insert = insertReplaceEdit.getInsert().getStart(); Position start = replace; if (replace.getLine() > insert.getLine() || replace.getCharacter() > insert.getCharacter()) start = insert; }), document); which better captures the logic.
- Loading branch information