Skip to content

Commit

Permalink
Avoid unnecessarily storing document in actions (eclipse-cdt#607)
Browse files Browse the repository at this point in the history
With the first part of the fix in eclipse-cdt#603 we recreate the document
regularly (on each context change) therefore we need to let any
consumers of the document fetch the current version of the document
from the editor (by calling getAdapter(IDocument.class)) when
it is needed, rather than caching it.

Fixes eclipse-cdt#603
  • Loading branch information
jonahgraham authored Nov 3, 2023
1 parent 27bee70 commit 08abfa2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextOperationTarget;
Expand Down Expand Up @@ -580,8 +581,9 @@ public <T> T getAdapter(Class<T> required) {
if (fColumnSupport == null)
fColumnSupport = createColumnSupport();
return (T) fColumnSupport;
} else if (IDocument.class.equals(required)) {
return (T) getDocument();
}

return super.getAdapter(required);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ protected IAction createAction(IDisassemblyPart disassemblyPart, IVerticalRulerI
if (fDelegate != null) {
fDelegate.dispose();
}
return fDelegate = new ToggleBreakpointAction(disassemblyPart, disassemblyPart.getTextViewer().getDocument(),
rulerInfo);
return fDelegate = new ToggleBreakpointAction(disassemblyPart, null, rulerInfo);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbenchPart;
Expand All @@ -36,11 +35,9 @@ public class RulerToggleBreakpointHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
if (part instanceof IDisassemblyPart) {
IDisassemblyPart disassemblyPart = (IDisassemblyPart) part;
IDocument document = disassemblyPart.getTextViewer().getDocument();
final IVerticalRulerInfo rulerInfo = part.getAdapter(IVerticalRulerInfo.class);
if (rulerInfo != null) {
final ToggleBreakpointAction toggleBpAction = new ToggleBreakpointAction(part, document, rulerInfo);
final ToggleBreakpointAction toggleBpAction = new ToggleBreakpointAction(part, null, rulerInfo);
try {
toggleBpAction.update();
if (toggleBpAction.isEnabled()) {
Expand Down

0 comments on commit 08abfa2

Please sign in to comment.