use of org.springframework.ide.vscode.commons.util.text.IRegion in project sts4 by spring-projects.
the class ListLineTracker method getLineInformationOfOffset.
@Override
public final IRegion getLineInformationOfOffset(int position) throws BadLocationException {
if (position > fTextLength)
throw new BadLocationException();
if (position == fTextLength) {
int size = fLines.size();
if (size == 0)
return new Region(0, 0);
Line l = fLines.get(size - 1);
return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length));
}
return getLineInformation(findLine(position));
}
use of org.springframework.ide.vscode.commons.util.text.IRegion in project sts4 by spring-projects.
the class YamlHoverInfoProvider method getHoverRegion.
private IRegion getHoverRegion(YamlFileAST ast, int offset) {
if (ast != null) {
Node n = ast.findNode(offset);
if (n != null && n.getNodeId() == NodeId.scalar) {
int start = n.getStartMark().getIndex();
int end = n.getEndMark().getIndex();
return new Region(start, end - start);
}
}
return null;
}
use of org.springframework.ide.vscode.commons.util.text.IRegion in project sts4 by spring-projects.
the class IndentUtil method getReferenceIndent.
public String getReferenceIndent(int offset, IDocument doc) {
// Apply indentfix, this is magic vscode seems to apply to edits returned by language server. So our harness has to
// mimick that behavior. See https://github.com/Microsoft/language-server-protocol/issues/83
IRegion referenceLine = doc.getLineInformationOfOffset(offset);
DocumentRegion queryPrefix = new DocumentRegion(doc, referenceLine.getOffset(), offset);
return queryPrefix.leadingWhitespace().toString();
}
use of org.springframework.ide.vscode.commons.util.text.IRegion in project sts4 by spring-projects.
the class VscodeHoverEngineAdapter method handle.
@Override
public Hover handle(TextDocumentPositionParams params) {
// a trivial pre-resolved future.
try {
SimpleTextDocumentService documents = server.getTextDocumentService();
TextDocument doc = documents.get(params);
if (doc != null) {
int offset = doc.toOffset(params.getPosition());
Tuple2<Renderable, IRegion> hoverTuple = hoverInfoProvider.getHoverInfo(doc, offset);
if (hoverTuple != null) {
Renderable hoverInfo = hoverTuple.getT1();
IRegion region = hoverTuple.getT2();
Range range = doc.toRange(region.getOffset(), region.getLength());
String rendered = render(hoverInfo, type);
if (StringUtil.hasText(rendered)) {
Hover hover = new Hover(ImmutableList.of(Either.forLeft(rendered)), range);
return hover;
}
}
}
} catch (Exception e) {
logger.error("error computing hover", e);
}
return SimpleTextDocumentService.NO_HOVER;
}
use of org.springframework.ide.vscode.commons.util.text.IRegion in project sts4 by spring-projects.
the class DocumentEdits method deleteLineBackward.
/**
* Deletes the line of text with given line number, including either the following or
* preceding newline. If there is a choice between the preceding or following newline,
* the preceding newline is deleted. This will leave the cursor at the end of
* the preceding line.
* <p>
* Note: a similar operation 'deleteLineForward' could be implemented prefering to
* delete the following newline. This would be equivalent except that it will leave the
* cursor at the start of the following line.
*/
public void deleteLineBackward(int lineNumber) throws BadLocationException {
IRegion line = doc.getLineInformation(lineNumber);
int startOfDeletion;
int endOfDeletion;
if (lineNumber > 0) {
IRegion previousLine = doc.getLineInformation(lineNumber - 1);
startOfDeletion = endOf(previousLine);
endOfDeletion = endOf(line);
} else if (lineNumber < doc.getNumberOfLines() - 1) {
IRegion nextLine = doc.getLineInformation(lineNumber + 1);
startOfDeletion = line.getOffset();
endOfDeletion = nextLine.getOffset();
} else {
startOfDeletion = line.getOffset();
endOfDeletion = endOf(line);
}
delete(startOfDeletion, endOfDeletion);
}
Aggregations