Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion team/bundles/org.eclipse.compare/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Export-Package: org.eclipse.compare;
Require-Bundle: org.eclipse.ui;bundle-version="[3.206.0,4.0.0)",
org.eclipse.swt;bundle-version="[3.136.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.8.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.32.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui.views;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

import org.eclipse.compare.ICompareFilter;
Expand Down Expand Up @@ -91,6 +92,7 @@
import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension5;
import org.eclipse.jface.text.source.ISourceViewerExtension6;

Check failure on line 95 in team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Import

The import org.eclipse.jface.text.source.ISourceViewerExtension6 cannot be resolved
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
Expand Down Expand Up @@ -138,6 +140,9 @@

public class UnifiedDiffManager {

private static final Predicate<ICodeMining> UNIFIED_DIFF_MINING_FILTER = mining -> mining
.getProvider() instanceof UnifiedDiffCodeMiningProvider;

private static final String CURRENT_SELECTED_UNIFIED_DIFF_ANNO_KEY = "CURRENT_SELECTED_UNIFIED_DIFF_ANNO_KEY"; //$NON-NLS-1$
private static final String UNDO_LISTENER_KEY = "UNIFIED_DIFF_UNDO_LISTENER_KEY"; //$NON-NLS-1$
private static final String DOCUMENT_LISTENER_KEY = "UNIFIED_DIFF_DOCUMENT_LISTENER_KEY"; //$NON-NLS-1$
Expand Down Expand Up @@ -527,7 +532,10 @@
setToolbarActionPresentations(viewer, toolbarActionPresentations);
addPaintListener(viewer, model, mode);
addMouseMoveListener(viewer, model);
if (viewer instanceof ISourceViewerExtension5 ext) {
if (!unifiedDiffs.isEmpty() && viewer instanceof ISourceViewerExtension6 ext) {

Check failure on line 535 in team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Type

ISourceViewerExtension6 cannot be resolved to a type
// Adding the filter indirectly updates code minings; no separate updateCodeMinings() call is needed.
ext.addCodeMiningFilter(UNIFIED_DIFF_MINING_FILTER);
} else if (viewer instanceof ISourceViewerExtension5 ext) {
ext.updateCodeMinings();
}
drawToolBarForAllDiffs(viewer, model, additionalActions, mode, toolbarActionPresentations);
Expand Down Expand Up @@ -1548,9 +1556,10 @@
}
}
diffs1.clear();
// open unified diff a second time for the same viewer; the old code minings
// need to be removed before adding new ones
if (tv instanceof ISourceViewerExtension5 ext) {
if (tv instanceof ISourceViewerExtension6 ext) {

Check failure on line 1559 in team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Type

ISourceViewerExtension6 cannot be resolved to a type
// Removing the filter indirectly updates code minings; no separate updateCodeMinings() call is needed.
ext.removeCodeMiningFilter(UNIFIED_DIFF_MINING_FILTER);
} else if (tv instanceof ISourceViewerExtension5 ext) {
ext.updateCodeMinings();
}
}
Expand Down Expand Up @@ -2398,6 +2407,11 @@

diffsByViewer.remove(tv);
fileByViewer.remove(tv);
if (tw != null && !tw.isDisposed() && tv.getTextWidget() == tw
&& tv instanceof ISourceViewerExtension6 ext) {

Check failure on line 2411 in team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Type

ISourceViewerExtension6 cannot be resolved to a type
// Removing the filter indirectly updates code minings; no separate updateCodeMinings() call is needed.
ext.removeCodeMiningFilter(UNIFIED_DIFF_MINING_FILTER);
}

if (tw == null || tw.isDisposed()) {
// SWT removes listeners automatically when the widget is disposed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Predicate;

import org.eclipse.compare.ICompareFilter;
import org.eclipse.compare.contentmergeviewer.ITokenComparator;
Expand All @@ -51,13 +53,15 @@
import org.eclipse.compare.unifieddiff.internal.HideAllDiffsRunnable;
import org.eclipse.compare.unifieddiff.internal.KeepAllRunnable;
import org.eclipse.compare.unifieddiff.internal.UndoAllRunnable;
import org.eclipse.compare.unifieddiff.internal.UnifiedDiffCodeMiningProvider;
import org.eclipse.compare.unifieddiff.internal.UnifiedDiffCodeMiningProvider.UnifiedDiffLineHeaderCodeMining;
import org.eclipse.compare.unifieddiff.internal.UnifiedDiffManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.InstanceScope;
Expand All @@ -70,11 +74,16 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
import org.eclipse.jface.text.codemining.ICodeMining;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IAnnotationModelExtension;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension5;
import org.eclipse.jface.text.source.ISourceViewerExtension6;
import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -110,6 +119,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@SuppressWarnings("restriction")
@ExtendWith(WorkspaceResetExtension.class)
Expand Down Expand Up @@ -1098,6 +1109,65 @@ public void testHideAllDiffsCommandDisposesTheUnifiedDiff() throws Exception {
assertEquals(0, countAnnotations(annotationModel(), DETAILED_DELETION_ANNO_TYPE));
}

@ParameterizedTest
@ValueSource(strings = { "org.eclipse.compare.hideAllDiffs", "org.eclipse.compare.acceptAllDiffs",
"org.eclipse.compare.hideCurrentDiff", "org.eclipse.compare.acceptCurrentDiff" })
public void testOtherMiningsAreRestoredAfterResolvingDiffs(String command) throws Exception {
ProblemMiningProvider provider = installProblemMining();
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
waitForProblemMining(provider, false);
assertNotNull(waitForLineHeaderAnnotation(), "unified diff minings must remain visible");
executeEditorCommand(command);
if (command.contains("accept")) {
waitForDocumentContent(RIGHT);
}
waitForUnifiedDiffCount(0);
waitForProblemMining(provider, true);
assertEquals(0, provider.disposals, "filtering must not dispose installed providers");
}

@Test
public void testOtherMiningsAreRestoredAfterEmptyReopenAndModeChanges() throws Exception {
ProblemMiningProvider provider = installProblemMining();
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
waitForProblemMining(provider, false);
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_READ_ONLY_MODE).open().isOK());
waitForProblemMining(provider, false);
assertTrue(UnifiedDiff.create(editor, LEFT, UnifiedDiffMode.OVERLAY_READ_ONLY_MODE).open().isOK());
waitForProblemMining(provider, true);
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
waitForProblemMining(provider, false);
executeEditorCommand("org.eclipse.compare.hideAllDiffs");
waitForProblemMining(provider, true);
}

@Test
public void testFilterLifecycleDoesNotRequestDuplicateProviderRefreshes() throws Exception {
ProblemMiningProvider provider = installProblemMining();
int initialRequests = provider.requests;
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
assertEquals(initialRequests + 1, provider.requests, "open must refresh providers only once");
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
assertEquals(initialRequests + 3, provider.requests,
"reopen must refresh once for clearing the old session and once for the new session");
executeEditorCommand("org.eclipse.compare.hideAllDiffs");
waitForProblemMining(provider, true);
}

@Test
public void testClosingDiffDoesNotRemoveAnotherClientsMiningFilter() throws Exception {
ProblemMiningProvider provider = installProblemMining();
var extension = (ISourceViewerExtension6) viewer();
Predicate<ICodeMining> otherFilter = mining -> mining.getProvider() != provider;
extension.addCodeMiningFilter(otherFilter);
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.OVERLAY_MODE).open().isOK());
waitForProblemMining(provider, false);
executeEditorCommand("org.eclipse.compare.hideAllDiffs");
waitForProblemMining(provider, false);
extension.removeCodeMiningFilter(otherFilter);
waitForProblemMining(provider, true);
}

@Test
public void testAcceptAllDiffsCommandAppliesAllChanges() throws Exception {
setEditorContent(LEFT);
Expand Down Expand Up @@ -1460,11 +1530,13 @@ public void testUnifiedDiffEventListenerReportsDocumentUndoAfterTheDocumentChang
List<UnifiedDiffEvent> events = new ArrayList<>();
List<String> documentContentsAtNotification = new ArrayList<>();
setEditorContent(LEFT);
ProblemMiningProvider provider = installProblemMining();
assertTrue(UnifiedDiff.create(editor, RIGHT, UnifiedDiffMode.REPLACE_MODE).eventListener(event -> {
events.add(event);
documentContentsAtNotification.add(document().get());
}).open().isOK());
waitForDocumentContent(RIGHT);
waitForProblemMining(provider, false);

IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(document());
assertTrue(undoManager.undoable(), "opening a replace-mode diff must create an undoable document change");
Expand All @@ -1476,6 +1548,7 @@ public void testUnifiedDiffEventListenerReportsDocumentUndoAfterTheDocumentChang
assertEquals(List.of(LEFT), documentContentsAtNotification,
"the undo event must be sent after the document has been restored");
assertNull(UnifiedDiffManager.get(viewer()), "undoing the only replace-mode hunk must dispose the unified diff");
waitForProblemMining(provider, true);
}

@Test
Expand Down Expand Up @@ -1785,6 +1858,55 @@ private ITextViewer viewer() {
return viewer;
}

private ProblemMiningProvider installProblemMining() throws Exception {
ProblemMiningProvider provider = new ProblemMiningProvider();
((ISourceViewerExtension5) viewer()).setCodeMiningProviders(
new ICodeMiningProvider[] { new UnifiedDiffCodeMiningProvider(), provider });
waitForProblemMining(provider, true);
return provider;
}

private void waitForProblemMining(ProblemMiningProvider provider, boolean visible) throws Exception {
long deadline = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < deadline) {
processEvents();
boolean found = false;
for (Iterator<Annotation> annotations = annotationModel().getAnnotationIterator(); annotations.hasNext();) {
if (annotations.next() instanceof LineHeaderAnnotation header) {
found |= header.getMinings().stream().anyMatch(mining -> mining.getProvider() == provider);
}
}
if (found == visible) {
return;
}
Thread.sleep(20);
}
throw new AssertionError("Problem mining visibility did not become " + visible);
}

private static final class ProblemMiningProvider extends AbstractCodeMiningProvider {
private int disposals;
private int requests;

@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
IProgressMonitor monitor) {
requests++;
try {
LineHeaderCodeMining mining = new LineHeaderCodeMining(1, viewer.getDocument(), this) {};
mining.setLabel("Synthetic problem annotation");
return CompletableFuture.completedFuture(List.of(mining));
} catch (BadLocationException e) {
throw new AssertionError(e);
}
}

@Override
public void dispose() {
disposals++;
}
}

/**
* Dispatches a synthetic {@link SWT#MouseMove} event with the given
* widget-relative y coordinate to every {@link MouseMoveListener} attached to
Expand Down
Loading