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;
}
}
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;
}
}
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();
}
});
}
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();
}
}
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();
}
}
Aggregations