/** * Get the number of lines in the document. Empty document has line count: {@code 1}. */ public int getLineCount() { int _line = this.getPosition(this.contents.length()).getLine(); return (_line + 1); }
/** * 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 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); }
/** * Add the top level node to context if cursor position matches the line of signature. * * @param node node to be compared and added to the context */ private void addTopLevelNodeToContext(BLangNode node, String name, PackageID currentPkg, String symbolKindOfParentNode, String symbolKindOfCurrentNode, BSymbol owner) { if (node.getPosition().sLine == this.position.getLine()) { addPosition(node, this.previousNode, name, currentPkg, symbolKindOfCurrentNode, symbolKindOfParentNode, name, owner); } }
public int toOffset(Position p) { int startOfLine = startOfLine(p.getLine()); return startOfLine+p.getCharacter(); }
public static Condition<Diagnostic> isDiagnosticOnLine(int line) { return new Condition<>( (d) -> d.getRange().getStart().getLine()==line, "Diagnostic on line "+line ); }
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(); }
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); }
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> 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); }
public PositionTreeVisitor(LSContext context) { this.context = context; this.position = context.get(DocumentServiceKeys.POSITION_KEY).getPosition(); this.symTable = SymbolTable.getInstance(context.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY)); this.position.setLine(this.position.getLine() + 1); this.nodeStack = new Stack<>(); this.context.put(NodeContextKeys.NODE_STACK_KEY, nodeStack); }
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); }
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 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 $; }
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; }
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); }