@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; if (!super.equals(obj)) return false; SemanticHighlightingRegistry.HighlightedRange other = (SemanticHighlightingRegistry.HighlightedRange) obj; if (other.scope != this.scope) return false; return true; }
/** * Returns whether range1 and range2 intersect. Assumes that a range is inclusive on its start and exclusive on its * end, which means that if range1 ends on the same position as range2 starts, this is not considered intersecting. */ public static boolean intersects(Range range1, Range range2) { checkArgument(isValid(range1), String.format("range1 is not valid: %s", range1.toString())); checkArgument(isValid(range2), String.format("range2 is not valid: %s", range2.toString())); Position maxStart = max(range1.getStart(), range2.getStart()); Position minEnd = min(range1.getEnd(), range2.getEnd()); return POSITION_COMPARATOR.compare(maxStart, minEnd) < 0; }
protected TextEdit toTextEdit(final Document document, final String formattedText, final int startOffset, final int length) { TextEdit _textEdit = new TextEdit(); final Procedure1<TextEdit> _function = (TextEdit it) -> { it.setNewText(formattedText); Range _range = new Range(); final Procedure1<Range> _function_1 = (Range it_1) -> { it_1.setStart(document.getPosition(startOffset)); it_1.setEnd(document.getPosition((startOffset + length))); }; Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1); it.setRange(_doubleArrow); }; return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function); }
/** * Returns rendered text-edits. * * @return rendered edits */ @Override public List<TextEdit> getRenderedTextEdits() { List<TextEdit> edits = new ArrayList<>(); //Calculate text-edits positions.forEach( (pos, value) -> value.forEach((placeHolder, content) -> { Position position = new Position(pos.eLine, pos.eCol); Range range = new Range(position, position); TextEdit textEdit = new TextEdit(range, content); edits.add(textEdit); }) ); return edits; }
public List<TextEdit> transform() { List<TextEdit> inverse = new ArrayList<>(); Iterator<TextEdit> editIterator = edits.iterator(); ch = source.get(); while (editIterator.hasNext()) { TextEdit edit = editIterator.next(); advanceTo(edit.getRange().getStart(), sink); Position undoStart = new Position(currentWriteLine, currentWriteChar); for (int i = 0; i < edit.getNewText().length(); i++) { sink.accept((int) edit.getNewText().charAt(i)); } StringBuilder replaced = new StringBuilder(); advanceTo(edit.getRange().getEnd(), forStringBuilder(replaced)); Position undoEnd = new Position(currentWriteLine, currentWriteChar); inverse.add(new TextEdit(new Range(undoStart, undoEnd), replaced.toString())); } // all edits have been processed. Copy the rest of the chars. while (ch >= 0) { sink.accept(ch); ch = source.get(); } return inverse; }
/** * Determines the position of a snippet of text in the document. * * @param contextSnippet A larger snippet containing the actual snippet to look for. * This larger snippet is used to narrow the section of the document * where we look for the actual snippet. This is useful when the snippet * occurs multiple times in the document. * @param focusSnippet The snippet to look for */ public Position positionOf(String longSnippet, String focusSnippet) throws Exception { Range r = rangeOf(longSnippet, focusSnippet); return r==null?null:r.getStart(); }
@Override @Pure public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.range== null) ? 0 : this.range.hashCode()); result = prime * result + ((this.rangeLength== null) ? 0 : this.rangeLength.hashCode()); return prime * result + ((this.text== null) ? 0 : this.text.hashCode()); } }
/** * Gets the end offset for the diagnostic. * * @param unit * @param range * @return starting offset or negative value if can not be determined */ public static int getEndOffset(ICompilationUnit unit, Range range){ try { return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getEnd().getLine(), range.getEnd().getCharacter()); } catch (JavaModelException e) { return -1; } }
private Range getRange(BLangNode node) { Range r = new Range(); int startLine = node.getPosition().getStartLine() - 1; // LSP range is 0 based int startChar = node.getPosition().getStartColumn() - 1; int endLine = node.getPosition().getEndLine() - 1; int endChar = node.getPosition().getEndColumn() - 1; if (endLine <= 0) { endLine = startLine; } if (endChar <= 0) { endChar = startChar + 1; } r.setStart(new Position(startLine, startChar)); r.setEnd(new Position(endLine, endChar)); return r; } }
@Override public DocumentHighlight apply(final Document document, final ITextRegion region, final DocumentHighlightKind kind) { Preconditions.checkNotNull(document, "document"); Preconditions.checkNotNull(region, "region"); Preconditions.checkNotNull(kind, "kind"); final int offset = region.getOffset(); final Position start = document.getPosition(offset); final Position end = document.getPosition(offset + region.getLength()); return new DocumentHighlight(new Range(start, end), kind); }
/** * Returns whether the given range contains the given position, inclusively. */ public static boolean contains(Range range, Position position) { checkArgument(isValid(range), String.format("range is not valid: %s", range.toString())); checkArgument(isValid(position), String.format("position is not valid: %s", position.toString())); return POSITION_COMPARATOR.compare(range.getStart(), position) <= 0 && POSITION_COMPARATOR.compare(range.getEnd(), position) >= 0; }
private String problemSumary(Editor editor, List<Diagnostic> actualProblems) throws Exception { StringBuilder buf = new StringBuilder(); for (Diagnostic p : actualProblems) { buf.append("\n----------------------\n"); String snippet = editor.getText(p.getRange()); buf.append("("+p.getRange().getStart().getLine()+", "+p.getRange().getStart().getCharacter()+")["+snippet+"]:\n"); buf.append(" "+p.getMessage()); } return buf.toString(); }
@Override @Pure public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.range== null) ? 0 : this.range.hashCode()); return prime * result + ((this.newText== null) ? 0 : this.newText.hashCode()); } }
/** * Creates a new range comparator with the give comparator delegate for * {@link Position positions}. * * @param positionComparator * the delegate comparator for the positions. Cannot be * {@code null}. */ @Inject public RangeComparator(final PositionComparator positionComparator) { Preconditions.checkNotNull(positionComparator, "positionComparator"); delegate = (left, right) -> start().compare(left.getStart(), right.getStart(), positionComparator) .compare(left.getEnd(), right.getEnd(), positionComparator).result(); }
.get(NodeContextKeys.PACKAGE_OF_NODE_KEY).name.getValue()), fileName); l.setUri(filePath.toUri().toString()); Range r = new Range(); r.setStart(new Position(bLangNode.getPosition().getStartLine() - 1, bLangNode.getPosition().getStartColumn() - 1)); r.setEnd(new Position(bLangNode.getPosition().getEndLine() - 1, bLangNode.getPosition().getEndColumn() - 1)); l.setRange(r);
public Range newRange(final Resource resource, final int startOffset, final int endOffset) { final Position startPosition = this.newPosition(resource, startOffset); if ((startPosition == null)) { return null; } final Position endPosition = this.newPosition(resource, endOffset); if ((endPosition == null)) { return null; } return new Range(startPosition, endPosition); }
public static Condition<Diagnostic> isDiagnosticOnLine(int line) { return new Condition<>( (d) -> d.getRange().getStart().getLine()==line, "Diagnostic on line "+line ); }
/** * @return <code>true</code> if a list of {@link org.eclipse.lsp4j.TextEdit} * contains any actual changes, <code>false</code> otherwise. */ public static boolean hasChanges(List<org.eclipse.lsp4j.TextEdit> edits) { if (edits == null) { return false; } //@formatter:off return edits.stream() .filter(edit -> (!edit.getRange().equals(ZERO_RANGE) || !"".equals(edit.getNewText()))) .findFirst() .isPresent(); //@formatter:on }