Search in sources :

Example 1 with FrozenDocument

use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.

the class PsiDocumentManagerBase method getLastCommittedDocument.

@NotNull
public DocumentEx getLastCommittedDocument(@NotNull Document document) {
    if (document instanceof FrozenDocument)
        return (DocumentEx) document;
    if (document instanceof DocumentWindow) {
        DocumentWindow window = (DocumentWindow) document;
        Document delegate = window.getDelegate();
        if (delegate instanceof FrozenDocument)
            return (DocumentEx) window;
        if (!window.isValid()) {
            throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window);
        }
        UncommittedInfo info = myUncommittedInfos.get(delegate);
        DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document);
        if (answer == null)
            answer = freezeWindow(window);
        if (info != null)
            answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer);
        return (DocumentEx) answer;
    }
    assert document instanceof DocumentImpl;
    UncommittedInfo info = myUncommittedInfos.get(document);
    return info != null ? info.myFrozen : ((DocumentImpl) document).freeze();
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) Document(com.intellij.openapi.editor.Document) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FrozenDocument

use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.

the class MarkerCache method applyEvents.

private static UpdatedRanges applyEvents(@NotNull List<DocumentEvent> events, final UpdatedRanges struct) {
    FrozenDocument frozen = struct.myResultDocument;
    ManualRangeMarker[] resultMarkers = struct.myMarkers.clone();
    for (DocumentEvent event : events) {
        final FrozenDocument before = frozen;
        final DocumentEvent corrected;
        if (event instanceof RetargetRangeMarkers) {
            RetargetRangeMarkers retarget = (RetargetRangeMarkers) event;
            corrected = new RetargetRangeMarkers(frozen, retarget.getStartOffset(), retarget.getEndOffset(), retarget.getMoveDestinationOffset());
        } else {
            corrected = new DocumentEventImpl(frozen, event.getOffset(), event.getOldFragment(), event.getNewFragment(), event.getOldTimeStamp(), event.isWholeTextReplaced(), ((DocumentEventImpl) event).getInitialStartOffset(), ((DocumentEventImpl) event).getInitialOldLength());
            frozen = frozen.applyEvent(event, 0);
        }
        int i = 0;
        while (i < resultMarkers.length) {
            ManualRangeMarker currentRange = resultMarkers[i];
            int sameMarkersEnd = i + 1;
            while (sameMarkersEnd < resultMarkers.length && resultMarkers[sameMarkersEnd] == currentRange) {
                sameMarkersEnd++;
            }
            ManualRangeMarker updatedRange = currentRange == null ? null : currentRange.getUpdatedRange(corrected, before);
            while (i < sameMarkersEnd) {
                resultMarkers[i] = updatedRange;
                i++;
            }
        }
    }
    return new UpdatedRanges(struct.myEventCount + events.size(), frozen, struct.mySortedInfos, resultMarkers);
}
Also used : FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) ManualRangeMarker(com.intellij.openapi.editor.impl.ManualRangeMarker) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) RetargetRangeMarkers(com.intellij.openapi.editor.impl.event.RetargetRangeMarkers)

Example 3 with FrozenDocument

use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.

the class SelfElementInfo method getRange.

@Override
@Nullable
public Segment getRange() {
    if (hasRange()) {
        Document document = getDocumentToSynchronize();
        if (document != null) {
            PsiDocumentManagerBase documentManager = myManager.getPsiDocumentManager();
            List<DocumentEvent> events = documentManager.getEventsSinceCommit(document);
            if (!events.isEmpty()) {
                SmartPointerTracker tracker = myManager.getTracker(getVirtualFile());
                if (tracker != null) {
                    return tracker.getUpdatedRange(this, (FrozenDocument) documentManager.getLastCommittedDocument(document), events);
                }
            }
        }
    }
    return calcPsiRange();
}
Also used : Document(com.intellij.openapi.editor.Document) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)3 Document (com.intellij.openapi.editor.Document)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 ManualRangeMarker (com.intellij.openapi.editor.impl.ManualRangeMarker)1 DocumentEventImpl (com.intellij.openapi.editor.impl.event.DocumentEventImpl)1 RetargetRangeMarkers (com.intellij.openapi.editor.impl.event.RetargetRangeMarkers)1 PsiDocumentManagerBase (com.intellij.psi.impl.PsiDocumentManagerBase)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1