mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Reformat changed text: added user notification when FilesTooBigException is thrown, that we can't calculate changed ranges
This commit is contained in:
+13
-17
@@ -250,7 +250,7 @@ public class FormatChangedTextUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<TextRange> getChangedTextRanges(@NotNull Project project, @NotNull PsiFile file) {
|
||||
public static List<TextRange> getChangedTextRanges(@NotNull Project project, @NotNull PsiFile file) throws FilesTooBigForDiffException {
|
||||
Change change = ChangeListManager.getInstance(project).getChange(file.getVirtualFile());
|
||||
if (change == null) {
|
||||
return ContainerUtilRt.emptyList();
|
||||
@@ -281,7 +281,10 @@ public class FormatChangedTextUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<TextRange> calculateChangedTextRanges(@NotNull Project project, @NotNull PsiFile file, @NotNull String contentFromVcs) {
|
||||
private static List<TextRange> calculateChangedTextRanges(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull String contentFromVcs) throws FilesTooBigForDiffException
|
||||
{
|
||||
Document documentFromVcs = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(contentFromVcs, true, false);
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
|
||||
@@ -289,23 +292,16 @@ public class FormatChangedTextUtil {
|
||||
return ContainerUtil.emptyList();
|
||||
}
|
||||
|
||||
try {
|
||||
List<Range> changedRanges;
|
||||
|
||||
LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(document);
|
||||
if (tracker != null) {
|
||||
changedRanges = tracker.getRanges();
|
||||
}
|
||||
else {
|
||||
changedRanges = new RangesBuilder(document, documentFromVcs).getRanges();
|
||||
}
|
||||
|
||||
return getChangedTextRanges(document, changedRanges);
|
||||
List<Range> changedRanges;
|
||||
LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(document);
|
||||
if (tracker != null) {
|
||||
changedRanges = tracker.getRanges();
|
||||
}
|
||||
catch (FilesTooBigForDiffException e) {
|
||||
LOG.error("Error while calculating changed ranges for: " + file.getVirtualFile(), e);
|
||||
return ContainerUtil.emptyList();
|
||||
else {
|
||||
changedRanges = new RangesBuilder(document, documentFromVcs).getRanges();
|
||||
}
|
||||
|
||||
return getChangedTextRanges(document, changedRanges);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,6 +18,10 @@ package com.intellij.codeInsight.actions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.formatting.FormattingProgressTask;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -27,6 +31,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.diff.FilesTooBigForDiffException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -90,6 +95,17 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
CodeStyleManager.getInstance(myProject).reformatText(file, ranges);
|
||||
return !FormattingProgressTask.FORMATTING_CANCELLED_FLAG.get();
|
||||
}
|
||||
catch (FilesTooBigForDiffException e) {
|
||||
LOG.info("Error while calculating changed ranges for: " + file.getVirtualFile(), e);
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
Notification notification = new Notification(ApplicationBundle.message("reformat.changed.text.file.too.big.notification.groupId"),
|
||||
ApplicationBundle.message("reformat.changed.text.file.too.big.notification.title"),
|
||||
ApplicationBundle.message("reformat.changed.text.file.too.big.notification.text", file.getName()),
|
||||
NotificationType.INFORMATION);
|
||||
notification.notify(file.getProject());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
return false;
|
||||
@@ -102,7 +118,7 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<TextRange> getRangesToFormat(boolean processChangedTextOnly, PsiFile file) {
|
||||
private Collection<TextRange> getRangesToFormat(boolean processChangedTextOnly, PsiFile file) throws FilesTooBigForDiffException {
|
||||
if (processChangedTextOnly) {
|
||||
return FormatChangedTextUtil.getChangedTextRanges(myProject, file);
|
||||
}
|
||||
|
||||
@@ -644,4 +644,8 @@ group.richcopy=Rich-text copy
|
||||
combobox.richcopy.color.scheme=Color scheme
|
||||
combobox.richcopy.color.scheme.active=Active scheme
|
||||
|
||||
settings.code.style.default.general=Default (General)
|
||||
settings.code.style.default.general=Default (General)
|
||||
|
||||
reformat.changed.text.file.too.big.notification.groupId=Reformat changed text
|
||||
reformat.changed.text.file.too.big.notification.title=Couldn't calculate changed ranges
|
||||
reformat.changed.text.file.too.big.notification.text=file {0} is too big or there are too many changes
|
||||
|
||||
Reference in New Issue
Block a user