Skip to content

Commit 3aaea37

Browse files
committed
Defer expensive project reference computation during selection changes
CloseUnrelatedProjectsAction.getSelectedResources() calls computeRelated() which triggers buildConnectedComponents() and getReferencedProjects() for every project in the workspace. This is expensive because it can trigger classpath container resolution. Previously, the inherited updateSelection() called getSelectedResources() on every selection change, causing this expensive computation to run on the UI thread during startup and navigation. This blocked the IDE. Override updateSelection() to perform only a cheap enablement check: verify the selection contains at least one open IProject. The expensive computeRelated() call is deferred to getSelectedResources(), which is only invoked when the action is actually executed via run(). This is correct because getSelectedResources() already handles the selectionDirty flag and recomputes projectsToClose lazily when needed. Fixes #2636
1 parent 6de4edc commit 3aaea37

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CloseUnrelatedProjectsAction.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.eclipse.jface.dialogs.IDialogConstants;
3131
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
3232
import org.eclipse.jface.preference.IPreferenceStore;
33+
import org.eclipse.jface.viewers.IStructuredSelection;
3334
import org.eclipse.jface.window.IShellProvider;
3435
import org.eclipse.osgi.util.NLS;
3536
import org.eclipse.swt.widgets.Shell;
@@ -130,6 +131,25 @@ public CloseUnrelatedProjectsAction(IShellProvider provider){
130131
initAction();
131132
}
132133

134+
/**
135+
* Overrides to avoid calling the expensive
136+
* {@link #computeRelated(List)} during selection changes. Uses only
137+
* the raw selection to determine enablement.
138+
*/
139+
@Override
140+
protected boolean updateSelection(IStructuredSelection s) {
141+
selectionDirty = true;
142+
if (!selectionIsOfType(IResource.PROJECT)) {
143+
return false;
144+
}
145+
for (IResource resource : super.getSelectedResources()) {
146+
if (resource instanceof IProject project && project.isOpen()) {
147+
return true;
148+
}
149+
}
150+
return false;
151+
}
152+
133153
@Override
134154
public void run() {
135155
if (promptForConfirmation()) {

0 commit comments

Comments
 (0)