private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); if (d!=0) return d; return p1.getCharacter() - p2.getCharacter(); } };
/** * Sole constructor. Creates a new comparator for {@link Position position} * instances. */ public PositionComparator() { delegate = (left, right) -> start().compare(left.getLine(), right.getLine()) .compare(left.getCharacter(), right.getCharacter()).result(); }
/** * Checks whether the given position is valid, i.e. it has non-negative line and character values. */ public static boolean isValid(Position position) { return position.getLine() >= 0 && position.getCharacter() >= 0; }
private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); if (d!=0) return d; return p1.getCharacter() - p2.getCharacter(); } };
private static boolean isTopLevelNode(String docUri, WorkspaceDocumentManager documentManager, LSCompiler lsCompiler, LSServiceOperationContext context, Position position) { Pair<BLangNode, Object> bLangNode = getBLangNode(position.getLine(), position.getCharacter(), docUri, documentManager, lsCompiler, context); // Only supported for top-level nodes return (bLangNode.getLeft().parent instanceof BLangPackage); }
public int toOffset(Position p) { int startOfLine = startOfLine(p.getLine()); return startOfLine+p.getCharacter(); }
/** * {@code true} if {@code left} is strictly before than {@code right}. Otherwise, * {@code false}. * <p> * If you want to allow equality, use {@link Position#equals}. */ public static boolean isBefore(Position left, Position right) { Preconditions.checkNotNull(left, "left"); Preconditions.checkNotNull(right, "right"); if (left.getLine() < right.getLine()) { return true; } if (left.getLine() > right.getLine()) { return false; } return left.getCharacter() < right.getCharacter(); }
/** * {@code true} if {@left} is strictly before than {@code right}. Otherwise, * {@code false}. * <p> * If you want to allow equality, use {@link Position#equals}. */ public static boolean isBefore(Position left, Position right) { Preconditions.checkNotNull(left, "left"); Preconditions.checkNotNull(right, "right"); if (left.getLine() < right.getLine()) { return true; } if (left.getLine() > right.getLine()) { return false; } return left.getCharacter() < right.getCharacter(); }
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(); }
Position clone(Position position) { if (position == null) { return null; } int line = position.getLine(); int character = position.getCharacter(); Position cloned = new Position(); cloned.setLine(line); cloned.setCharacter(character); return cloned; } }
public List<? extends Location> typeDefinition(TextDocumentPositionParams position, IProgressMonitor monitor) { ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri()); Location location = null; if (unit != null && !monitor.isCanceled()) { location = computeTypeDefinitionNavigation(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); } return location == null ? null : Arrays.asList(location); }
public List<? extends Location> definition(TextDocumentPositionParams position, IProgressMonitor monitor) { ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri()); Location location = null; if (unit != null && !monitor.isCanceled()) { location = computeDefinitionNavigation(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); } return location == null ? null : Arrays.asList(location); }
private int getOffset(TextDocumentPositionParams param, ITypeRoot typeRoot) { int offset = 0; try { IDocument document = JsonRpcHelpers.toDocument(typeRoot.getBuffer()); offset = document.getLineOffset(param.getPosition().getLine()) + param.getPosition().getCharacter(); } catch (JavaModelException | BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return offset; }
public PositionDto(org.eclipse.lsp4j.Position o) { int lineVal = (int)makeDto(o.getLine());; setLine((int)lineVal); int characterVal = (int)makeDto(o.getCharacter());; setCharacter((int)characterVal); }
public Hover hover(TextDocumentPositionParams position, IProgressMonitor monitor) { ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri()); List<Either<String, MarkedString>> content = null; if (unit != null && !monitor.isCanceled()) { content = computeHover(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); } else { content = Collections.singletonList(Either.forLeft("")); } Hover $ = new Hover(); $.setContents(content); return $; }
/** * 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 IRegion getRegion(Range range, IDocument document) { try { int offset = document.getLineOffset(range.getStart().getLine()) + range.getStart().getCharacter(); int endOffset = document.getLineOffset(range.getEnd().getLine()) + range.getEnd().getCharacter(); int length = endOffset - offset; return new Region(offset, length); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return null; }
/** * Gets the start offset for the diagnostic. * * @param unit * @param range * @return starting offset or negative value if can not be determined */ public static int getStartOffset(ICompilationUnit unit, Range range){ try { return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter()); } catch (JavaModelException e) { return -1; } } /**
private static ExtendedTextEdit doConvert(TextEdit edit, StringBuilder currentLine) { ExtendedTextEdit extendedEdit = new ExtendedTextEdit(); extendedEdit.setRange(edit.getRange()); extendedEdit.setNewText(edit.getNewText()); extendedEdit.setLineText(currentLine.toString()); extendedEdit.setInLineStart(edit.getRange().getStart().getCharacter()); if (edit.getRange().getEnd().getLine() == edit.getRange().getStart().getLine()) { extendedEdit.setInLineEnd(edit.getRange().getEnd().getCharacter()); } else { extendedEdit.setInLineEnd(Math.max(0, currentLine.length() - 1)); } return extendedEdit; }
public List<? extends DocumentHighlight> documentHighlight(TextDocumentPositionParams position, IProgressMonitor monitor) { ITypeRoot type = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri()); return computeOccurrences(type, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); }