Search in sources :

Example 1 with Position

use of org.graalvm.tools.lsp.server.types.Position in project graal by oracle.

the class SourceSectionReference method behind.

public boolean behind(Range range) {
    Position end = range.getEnd();
    int otherEndLine = end.getLine() + 1;
    int otherEndColumn = end.getCharacter() + 1;
    if (otherEndLine < this.startLine || otherEndLine == this.startLine && otherEndColumn < this.startColumn) {
        // range is fully before us in the text
        return true;
    }
    return false;
}
Also used : Position(org.graalvm.tools.lsp.server.types.Position)

Example 2 with Position

use of org.graalvm.tools.lsp.server.types.Position in project graal by oracle.

the class SourceSectionReference method before.

public boolean before(Range range) {
    Position start = range.getStart();
    int otherStartLine = start.getLine() + 1;
    int otherStartColumn = start.getCharacter() + 1;
    if (this.endLine < otherStartLine || this.endLine == otherStartLine && this.endColumn < otherStartColumn) {
        // range is fully behind us in the text
        return true;
    }
    return false;
}
Also used : Position(org.graalvm.tools.lsp.server.types.Position)

Example 3 with Position

use of org.graalvm.tools.lsp.server.types.Position in project graal by oracle.

the class SourceUtils method applyTextDocumentChanges.

public static String applyTextDocumentChanges(List<? extends TextDocumentContentChangeEvent> list, Source source, TextDocumentSurrogate surrogate, TruffleLogger logger) {
    Source currentSource = null;
    String text = source.getCharacters().toString();
    StringBuilder sb = new StringBuilder(text);
    for (TextDocumentContentChangeEvent event : list) {
        if (currentSource == null) {
            currentSource = source;
        } else {
            currentSource = Source.newBuilder(currentSource.getLanguage(), sb, currentSource.getName()).cached(false).build();
        }
        Range range = event.getRange();
        if (range == null) {
            // The whole file has changed
            // Clear StringBuilder
            sb.setLength(0);
            sb.append(event.getText());
            continue;
        }
        Position start = range.getStart();
        Position end = range.getEnd();
        int startLine = start.getLine() + 1;
        int endLine = end.getLine() + 1;
        int replaceBegin = currentSource.getLineStartOffset(startLine) + start.getCharacter();
        int replaceEnd = currentSource.getLineStartOffset(endLine) + end.getCharacter();
        sb.replace(replaceBegin, replaceEnd, event.getText());
        if (surrogate != null && surrogate.hasCoverageData()) {
            updateCoverageData(surrogate, currentSource, event.getText(), range, replaceBegin, replaceEnd, logger);
        }
    }
    return sb.toString();
}
Also used : Position(org.graalvm.tools.lsp.server.types.Position) Range(org.graalvm.tools.lsp.server.types.Range) Source(com.oracle.truffle.api.source.Source) TextDocumentContentChangeEvent(org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent)

Example 4 with Position

use of org.graalvm.tools.lsp.server.types.Position in project graal by oracle.

the class SourceSectionReference method includes.

public boolean includes(Range range) {
    Position start = range.getStart();
    Position end = range.getEnd();
    int otherStartLine = start.getLine() + 1;
    int otherEndLine = end.getLine() + 1;
    if (this.startLine < otherStartLine && otherEndLine < this.endLine) {
        // range is fully included and we do not have to check the columns
        return true;
    }
    int otherStartColumn = start.getCharacter() + 1;
    int otherEndColumn = end.getCharacter() + 1;
    return (startLine < otherStartLine || startLine == otherStartLine && startColumn <= otherStartColumn) && (otherEndLine < endLine || otherEndLine == endLine && otherEndColumn <= endColumn);
}
Also used : Position(org.graalvm.tools.lsp.server.types.Position)

Aggregations

Position (org.graalvm.tools.lsp.server.types.Position)4 Source (com.oracle.truffle.api.source.Source)1 Range (org.graalvm.tools.lsp.server.types.Range)1 TextDocumentContentChangeEvent (org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent)1