Skip to content

Commit

Permalink
lsp: added more synchronization while accessing the view context and
Browse files Browse the repository at this point in the history
syntheses.
Avoids exceptions caused by broken references in instantiated syntheses
  • Loading branch information
NiklasRentzCAU committed Jul 5, 2022
1 parent 3657c1f commit a787732
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ class KGraphDiagramUpdater extends DiagramUpdater {
(diagramServers as List<KGraphDiagramServer>).forEach [ KGraphDiagramServer server |
// Only update an erroneous model if there was no diagram shown before.
if (!hasErrors || server.currentRoot.type == "NONE") {
prepareModel(server, model_, uri)
updateLayout(server)
synchronized (diagramState) {
prepareModel(server, model_, uri)
updateLayout(server)
}
}
]
return null as Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,19 @@ class KGraphLanguageServerExtension extends SyncDiagramLanguageServer
* @return A list of the IDs and displayable names of all available syntheses.
*/
def List<SetSynthesesActionData> getAvailableSynthesesData(Class<?> currentModelClass) {
val KlighdDataManager kdm = KlighdDataManager.instance
return kdm.getAvailableSyntheses(currentModelClass).map [
val synthesisId = kdm.getSynthesisID(it)
var displayedName = ""
if (it instanceof ReinitializingDiagramSynthesisProxy) {
displayedName = it.delegate.class.simpleName
} else {
displayedName = it.class.simpleName
}
return new SetSynthesesActionData(synthesisId, displayedName)
].toList
synchronized (diagramState) {
val KlighdDataManager kdm = KlighdDataManager.instance
return kdm.getAvailableSyntheses(currentModelClass).map [
val synthesisId = kdm.getSynthesisID(it)
var displayedName = ""
if (it instanceof ReinitializingDiagramSynthesisProxy) {
displayedName = it.delegate.class.simpleName
} else {
displayedName = it.class.simpleName
}
return new SetSynthesesActionData(synthesisId, displayedName)
].toList
}
}

override setSynthesisOptions(SetSynthesisOptionsParam param) {
Expand Down Expand Up @@ -436,10 +438,12 @@ class KGraphLanguageServerExtension extends SyncDiagramLanguageServer
// With that new diagram server, do a similar procedure to generate a diagram as for usual diagrams (except,
// use the 'model' as its model.
if (diagramUpdater instanceof KGraphDiagramUpdater) {
(diagramUpdater as KGraphDiagramUpdater).prepareModel(diagramServer, model, uri)
AbstractLanguageServer.addToMainThreadQueue([
(diagramUpdater as KGraphDiagramUpdater).updateLayout(diagramServer)
])
synchronized (diagramState) {
(diagramUpdater as KGraphDiagramUpdater).prepareModel(diagramServer, model, uri)
AbstractLanguageServer.addToMainThreadQueue([
(diagramUpdater as KGraphDiagramUpdater).updateLayout(diagramServer)
])
}
// Also, update the syntheses available for the given diagram.
if (!update) {
val availableSynthesesData = getAvailableSynthesesData(model.class)
Expand Down

0 comments on commit a787732

Please sign in to comment.