Search in sources :

Example 6 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class VcsAwareFormatChangedTextUtil method calculateChangedLinesNumber.

@Override
public int calculateChangedLinesNumber(@NotNull Document document, @NotNull CharSequence contentFromVcs) {
    try {
        List<Range> changedRanges = getRanges(document, contentFromVcs);
        int linesChanges = 0;
        for (Range range : changedRanges) {
            linesChanges += countLines(range);
        }
        return linesChanges;
    } catch (FilesTooBigForDiffException e) {
        LOG.info("File too big, can not calculate changed lines number");
        return -1;
    }
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange)

Example 7 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class PersistentRangeMarker method translateViaDiff.

@Nullable
static Pair<TextRange, LinesCols> translateViaDiff(@NotNull final DocumentEventImpl event, @NotNull LinesCols linesCols) {
    try {
        int myStartLine = event.translateLineViaDiffStrict(linesCols.myStartLine);
        Document document = event.getDocument();
        if (myStartLine < 0 || myStartLine >= document.getLineCount()) {
            return null;
        }
        int start = document.getLineStartOffset(myStartLine) + linesCols.myStartColumn;
        if (start >= document.getTextLength())
            return null;
        int myEndLine = event.translateLineViaDiffStrict(linesCols.myEndLine);
        if (myEndLine < 0 || myEndLine >= document.getLineCount()) {
            return null;
        }
        int end = document.getLineStartOffset(myEndLine) + linesCols.myEndColumn;
        if (end > document.getTextLength() || end < start)
            return null;
        if (end > event.getDocument().getTextLength() || myEndLine < myStartLine || myStartLine == myEndLine && linesCols.myEndColumn < linesCols.myStartColumn || event.getDocument().getLineCount() < myEndLine) {
            return null;
        }
        return Pair.create(new TextRange(start, end), new LinesCols(myStartLine, linesCols.myStartColumn, myEndLine, linesCols.myEndColumn));
    } catch (FilesTooBigForDiffException e) {
        return null;
    }
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class ReformatCodeProcessor method prepareTask.

@Override
@NotNull
protected FutureTask<Boolean> prepareTask(@NotNull final PsiFile file, final boolean processChangedTextOnly) throws IncorrectOperationException {
    return new FutureTask<>(() -> {
        FormattingProgressTask.FORMATTING_CANCELLED_FLAG.set(false);
        try {
            CharSequence before = null;
            Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
            if (getInfoCollector() != null) {
                LOG.assertTrue(document != null);
                before = document.getImmutableCharSequence();
            }
            CaretVisualPositionKeeper caretPositionKeeper = new CaretVisualPositionKeeper(document);
            if (processChangedTextOnly) {
                ChangedRangesInfo info = FormatChangedTextUtil.getInstance().getChangedRangesInfo(file);
                if (info != null) {
                    CodeStyleManager.getInstance(myProject).reformatTextWithContext(file, info);
                }
            } else {
                Collection<TextRange> ranges = getRangesToFormat(file);
                CodeStyleManager.getInstance(myProject).reformatText(file, ranges);
            }
            caretPositionKeeper.restoreOriginalLocation();
            if (before != null) {
                prepareUserNotificationMessage(document, before);
            }
            return !FormattingProgressTask.FORMATTING_CANCELLED_FLAG.get();
        } catch (FilesTooBigForDiffException e) {
            handleFileTooBigException(LOG, e, file);
            return false;
        } catch (IncorrectOperationException e) {
            LOG.error(e);
            return false;
        } finally {
            myRanges.clear();
        }
    });
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) FutureTask(java.util.concurrent.FutureTask) TextRange(com.intellij.openapi.util.TextRange) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ChangedRangesInfo(com.intellij.psi.codeStyle.ChangedRangesInfo) Document(com.intellij.openapi.editor.Document) CaretVisualPositionKeeper(com.intellij.openapi.editor.ex.util.CaretVisualPositionKeeper) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class LineStatusTrackerBase method doUpdateRanges.

private void doUpdateRanges(int beforeChangedLine1, int beforeChangedLine2, // before -> after
int linesShift, int beforeTotalLines, @NotNull List<Range> rangesBefore, @NotNull List<Range> changedRanges, @NotNull List<Range> rangesAfter) {
    try {
        int vcsTotalLines = getLineCount(myVcsDocument);
        Range lastRangeBefore = ContainerUtil.getLastItem(rangesBefore);
        Range firstRangeAfter = ContainerUtil.getFirstItem(rangesAfter);
        //noinspection UnnecessaryLocalVariable
        int afterChangedLine1 = beforeChangedLine1;
        int afterChangedLine2 = beforeChangedLine2 + linesShift;
        int vcsLine1 = getVcsLine1(lastRangeBefore, beforeChangedLine1);
        int vcsLine2 = getVcsLine2(firstRangeAfter, beforeChangedLine2, beforeTotalLines, vcsTotalLines);
        List<Range> newChangedRanges = getNewChangedRanges(afterChangedLine1, afterChangedLine2, vcsLine1, vcsLine2);
        shiftRanges(rangesAfter, linesShift);
        if (!changedRanges.equals(newChangedRanges)) {
            myRanges = new ArrayList<>(rangesBefore.size() + newChangedRanges.size() + rangesAfter.size());
            myRanges.addAll(rangesBefore);
            myRanges.addAll(newChangedRanges);
            myRanges.addAll(rangesAfter);
            for (Range range : changedRanges) {
                range.invalidate();
            }
            myToBeDestroyedRanges.addAll(changedRanges);
            myToBeInstalledRanges.addAll(newChangedRanges);
            if (myRanges.isEmpty()) {
                fireFileUnchanged();
            }
        }
    } catch (ProcessCanceledException ignore) {
    } catch (FilesTooBigForDiffException e1) {
        destroyRanges();
        installAnathema();
    }
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) TextRange(com.intellij.openapi.util.TextRange) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 10 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class DiffPanelImpl method rediff.

void rediff() {
    try {
        if (myTopMessageDiffPanel != null) {
            myPanel.removeTopComponent(myTopMessageDiffPanel);
        }
        LineBlocks blocks = myData.updateEditors();
        setLineBlocks(blocks != null ? blocks : LineBlocks.EMPTY);
        if (blocks != null && blocks.getCount() == 0) {
            if (myData.isContentsEqual()) {
                setFileContentsAreIdentical();
            }
        }
    } catch (FilesTooBigForDiffException e) {
        setTooBigFileErrorContents();
    }
}
Also used : LineBlocks(com.intellij.openapi.diff.impl.splitter.LineBlocks) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException)

Aggregations

FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)12 TextRange (com.intellij.openapi.util.TextRange)6 Document (com.intellij.openapi.editor.Document)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 DiffFragment (com.intellij.openapi.diff.ex.DiffFragment)2 DiffString (com.intellij.openapi.diff.impl.string.DiffString)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 FutureTask (java.util.concurrent.FutureTask)2 TestFrameworks (com.intellij.codeInsight.TestFrameworks)1 FormatChangedTextUtil (com.intellij.codeInsight.actions.FormatChangedTextUtil)1 FileRevisionTimestampComparator (com.intellij.history.FileRevisionTimestampComparator)1 LocalHistory (com.intellij.history.LocalHistory)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Fragment (com.intellij.openapi.diff.impl.fragments.Fragment)1 LineFragment (com.intellij.openapi.diff.impl.fragments.LineFragment)1 DiffCorrection (com.intellij.openapi.diff.impl.processing.DiffCorrection)1 DiffFragmentsProcessor (com.intellij.openapi.diff.impl.processing.DiffFragmentsProcessor)1 LineBlocks (com.intellij.openapi.diff.impl.splitter.LineBlocks)1