Skip to content

Commit

Permalink
GLSP Server Error when closing GLSP Eclipse Editor #556
Browse files Browse the repository at this point in the history
* notify the GLSPDiagram about the fact that it will be disposed. Stop
handling actions from that point on
* make access to clientidToDiagramEditor map synchronised in
GLSPEditorRegistry

Signed-off-by: Johannes Faltermeier <jfaltermeier@eclipsesource.com>
  • Loading branch information
jfaltermeier committed Feb 24, 2022
1 parent ad79fbc commit 6623cf3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Optional<GLSPServerManager> getGLSPServerManager(final String editorId) {
return Optional.of(editorIdToServerManager.get(editorId));
}

public Optional<GLSPDiagramEditor> getGLSPEditor(final String clientId) {
public synchronized Optional<GLSPDiagramEditor> getGLSPEditor(final String clientId) {
return Optional.ofNullable(clientIdtoDiagramEditor.get(clientId));
}

Expand All @@ -82,21 +82,30 @@ public GLSPDiagramEditor getGLSPEditorOrThrow(final String clientId) {
"Could not retrieve GLSP Editor. GLSP editor is not properly configured for clientId: " + clientId);
}

private synchronized void partClosed(final IWorkbenchPartReference part) {
if (part.getPart(false) instanceof GLSPDiagramEditor) {
GLSPDiagramEditor editor = (GLSPDiagramEditor) part.getPart(false);
editor.notifyAboutToBeDisposed();
clientIdtoDiagramEditor.remove(editor.getClientId());
}
}

private synchronized void partOpened(final IWorkbenchPartReference part) {
if (part.getPart(false) instanceof GLSPDiagramEditor) {
GLSPDiagramEditor editor = (GLSPDiagramEditor) part.getPart(false);
clientIdtoDiagramEditor.put(editor.getClientId(), editor);
}
}

class GLSPDiagramEditorPartListener implements IPartListener2 {
@Override
public void partClosed(final IWorkbenchPartReference part) {
if (part.getPart(false) instanceof GLSPDiagramEditor) {
GLSPDiagramEditor editor = (GLSPDiagramEditor) part.getPart(false);
clientIdtoDiagramEditor.remove(editor.getClientId());
}
GLSPEditorRegistry.this.partClosed(part);
}

@Override
public void partOpened(final IWorkbenchPartReference part) {
if (part.getPart(false) instanceof GLSPDiagramEditor) {
GLSPDiagramEditor editor = (GLSPDiagramEditor) part.getPart(false);
clientIdtoDiagramEditor.put(editor.getClientId(), editor);
}
GLSPEditorRegistry.this.partOpened(part);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.glsp.server.actions.SelectAllAction;
import org.eclipse.glsp.server.actions.ServerStatusAction;
import org.eclipse.glsp.server.disposable.DisposableCollection;
import org.eclipse.glsp.server.disposable.IDisposable;
import org.eclipse.glsp.server.features.contextactions.RequestContextActions;
import org.eclipse.glsp.server.features.navigation.NavigateToTargetAction;
import org.eclipse.glsp.server.features.undoredo.RedoAction;
Expand Down Expand Up @@ -414,6 +415,11 @@ public void setFocus() {
browser.setFocus();
}

public void notifyAboutToBeDisposed() {
// we are about to be disposed. don't send and accept actions anymore
getActionDispatcher().thenAccept(IDisposable::dispose);
}

@Override
public void dispose() {
super.dispose();
Expand Down

0 comments on commit 6623cf3

Please sign in to comment.