Search in sources :

Example 21 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class OrionLinkedModelGroupOverlay method setPositions.

@Override
public final void setPositions(List<Position> positions) {
    JsArray<OrionLinkedModelPositionOverlay> arr = JavaScriptObject.createArray().cast();
    for (Position position : positions) {
        OrionLinkedModelPositionOverlay pos = JavaScriptObject.createObject().cast();
        pos.setLength(position.getLength());
        pos.setOffset(position.getOffset());
        arr.push(pos);
    }
    setPositions(arr);
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position)

Example 22 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DefaultPartitioner method computePartitioning.

private List<TypedRegion> computePartitioning(final int offset, final int length, final boolean includeZeroLengthPartitions) {
    final List<TypedRegion> result = new ArrayList<>();
    final int contentLength = getContentLength();
    try {
        final int endOffset = offset + length;
        final List<TypedPosition> category = getPositions();
        TypedPosition previous = null;
        TypedPosition current = null;
        int start, end, gapOffset;
        final Position gap = new Position(0);
        final int startIndex = getFirstIndexEndingAfterOffset(category, offset);
        final int endIndex = getFirstIndexStartingAfterOffset(category, endOffset);
        for (int i = startIndex; i < endIndex; i++) {
            current = category.get(i);
            gapOffset = (previous != null) ? previous.getOffset() + previous.getLength() : 0;
            gap.setOffset(gapOffset);
            gap.setLength(current.getOffset() - gapOffset);
            if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
                start = Math.max(offset, gapOffset);
                end = Math.min(endOffset, gap.getOffset() + gap.getLength());
                result.add(new TypedRegionImpl(start, end - start, DEFAULT_CONTENT_TYPE));
            }
            if (current.overlapsWith(offset, length)) {
                start = Math.max(offset, current.getOffset());
                end = Math.min(endOffset, current.getOffset() + current.getLength());
                result.add(new TypedRegionImpl(start, end - start, current.getType()));
            }
            previous = current;
        }
        if (previous != null) {
            gapOffset = previous.getOffset() + previous.getLength();
            gap.setOffset(gapOffset);
            gap.setLength(contentLength - gapOffset);
            if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
                start = Math.max(offset, gapOffset);
                end = Math.min(endOffset, contentLength);
                result.add(new TypedRegionImpl(start, end - start, DEFAULT_CONTENT_TYPE));
            }
        }
        if (result.isEmpty()) {
            result.add(new TypedRegionImpl(offset, length, DEFAULT_CONTENT_TYPE));
        }
    } catch (final BadPositionCategoryException ex) {
        Logger.getLogger(DefaultPartitioner.class.getName()).fine("Bad position in computePartitioning.");
    } catch (final RuntimeException ex) {
        Logger.getLogger(DefaultPartitioner.class.getName()).warning("computePartitioning failed.");
        throw ex;
    }
    return result;
}
Also used : TypedRegionImpl(org.eclipse.che.ide.api.editor.text.TypedRegionImpl) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) ArrayList(java.util.ArrayList) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion)

Example 23 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DefaultPartitioner method updatePositions.

private void updatePositions() {
    // set before the scan as the scan uses the content length
    this.documentPositionMap.setContentLength(getContentLength());
    this.documentPositionMap.resetPositions();
    Position current = null;
    try {
        Token token = scanner.nextToken();
        while (!token.isEOF()) {
            final String contentType = getTokenContentType(token);
            if (isSupportedContentType(contentType)) {
                final TypedPosition position = new TypedPosition(scanner.getTokenOffset(), scanner.getTokenLength(), contentType);
                current = position;
                this.documentPositionMap.addPosition(this.positionCategory, position);
            }
            token = scanner.nextToken();
        }
    } catch (final BadLocationException x) {
        Log.error(DefaultPartitioner.class, "Invalid position: " + String.valueOf(current) + " (max:" + getContentLength() + ").", x);
    } catch (final BadPositionCategoryException x) {
        Log.error(DefaultPartitioner.class, "Invalid position category: " + this.positionCategory, x);
    }
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException) Token(org.eclipse.che.ide.api.editor.text.rules.Token) BadLocationException(org.eclipse.che.ide.api.editor.text.BadLocationException)

Example 24 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DefaultPartitioner method getFirstIndexEndingAfterOffset.

/**
     * Returns the index of the first position which ends after the given offset.
     *
     * @param positions the positions in linear order
     * @param offset the offset
     * @return the index of the first position which ends after the offset
     */
private static int getFirstIndexEndingAfterOffset(final List<TypedPosition> positions, final int offset) {
    int i = -1;
    int j = positions.size();
    while (j - i > 1) {
        final int k = (i + j) >> 1;
        final Position p = positions.get(k);
        if (p.getOffset() + p.getLength() > offset) {
            j = k;
        } else {
            i = k;
        }
    }
    return j;
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition)

Example 25 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DocumentPositionMapImpl method containsPosition.

@Override
public boolean containsPosition(String category, int offset, int length) {
    if (category == null) {
        return false;
    }
    final List<TypedPosition> list = this.positions.get(category);
    if (list == null) {
        return false;
    }
    final int size = list.size();
    if (size == 0) {
        return false;
    }
    int index = computeIndexInPositionList(list, offset, true);
    if (index < size) {
        Position p = list.get(index);
        while (p != null && p.offset == offset) {
            if (p.length == length) {
                return true;
            }
            ++index;
            p = (index < size) ? (Position) list.get(index) : null;
        }
    }
    return false;
}
Also used : TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition)

Aggregations

Position (org.eclipse.che.ide.api.editor.text.Position)36 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)14 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)14 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)8 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)7 ArrayList (java.util.ArrayList)6 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)3 Element (elemental.dom.Element)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 DiagnosticDTO (org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 EditorWithAutoSave (org.eclipse.che.ide.api.editor.EditorWithAutoSave)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1