Skip to content

Commit

Permalink
Merge pull request #113 from kieler/nre/singleparametercommunication
Browse files Browse the repository at this point in the history
Adapt Communication to only use one Parameter.
  • Loading branch information
a-sr authored May 7, 2024
2 parents dc1bce8 + e1ced29 commit 03c832a
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2019 by
* Copyright 2019-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -14,6 +14,8 @@ package de.cau.cs.kieler.language.server

import com.google.gson.JsonObject
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient
import de.cau.cs.kieler.language.server.kicool.data.DidCompileParam
import de.cau.cs.kieler.language.server.kicool.data.SendCompilationSystemsParam
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment
import org.eclipse.lsp4j.services.LanguageClient
Expand All @@ -30,8 +32,8 @@ interface KeithLanguageClient extends KGraphLanguageClient, LanguageClient {
/**
* The result object should have the type de.cau.cs.kieler.language.server.kicool.CompilationResults
*/
@JsonNotification("kicool/compile")
def void compile(Object results, String uri, boolean finished, int currentIndex, int maxIndex);
@JsonNotification("kicool/didCompile")
def void didCompile(DidCompileParam param);

@JsonNotification("kicool/cancel-compilation")
def void cancelCompilation(boolean success);
Expand All @@ -40,7 +42,7 @@ interface KeithLanguageClient extends KGraphLanguageClient, LanguageClient {
* Both objects should be List<de.cau.cs.kieler.language.server.kicool.SystemDescription>
*/
@JsonNotification("kicool/compilation-systems")
def void sendCompilationSystems(Object systems, Object snapshotSystems)
def void sendCompilationSystems(SendCompilationSystemsParam param)

/**
* Send to client if not the client itself invoked the simulation step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2018 by
* Copyright 2018-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -13,6 +13,8 @@
package de.cau.cs.kieler.language.server.kicool

import de.cau.cs.kieler.language.server.kicool.data.CodeOfModel
import de.cau.cs.kieler.language.server.kicool.data.CompileParam
import de.cau.cs.kieler.language.server.kicool.data.ShowParam
import java.util.concurrent.CompletableFuture
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
Expand All @@ -31,8 +33,7 @@ interface KiCoolCommandExtension {
* Compiles file given by uri with compilationsystem given by command.
*/
@JsonNotification('compile')
def void compile(String uri, String clientId, String command, boolean inplace, boolean showResultingModel,
boolean snapshot);
def void compile(CompileParam param);

/**
* Cancels the current compilation by stopping the current compilation thread.
Expand All @@ -44,7 +45,7 @@ interface KiCoolCommandExtension {
* Build diagram for snapshot with id index for file given by uri. Only works, if the file was already compiled.
*/
@JsonRequest('show')
def CompletableFuture<String> show(String uri, String clientId, int index)
def CompletableFuture<String> show(ShowParam param)

/**
* Returns all compilation systems which are applicable for the file at given uri.
Expand All @@ -55,9 +56,10 @@ interface KiCoolCommandExtension {
@JsonNotification('get-systems')
def void getSystems(String uri);

/**
* Request the contents of a CodeContainer as string together with its file name
*/
@JsonRequest("get-code-of-model")
def CompletableFuture<CodeOfModel> getCodeOfModel(String kgraphElemntId, String clientId);
// Currently unused, needs to be converted to use a single parameter.
// /**
// * Request the contents of a CodeContainer as string together with its file name
// */
// @JsonRequest("get-code-of-model")
// def CompletableFuture<CodeOfModel> getCodeOfModel(String kgraphElemntId, String clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2018 by
* Copyright 2018-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -21,14 +21,16 @@ import de.cau.cs.kieler.kicool.compilation.CompilationContext
import de.cau.cs.kieler.kicool.compilation.Compile
import de.cau.cs.kieler.kicool.deploy.ProjectInfrastructure
import de.cau.cs.kieler.kicool.environments.Environment
import de.cau.cs.kieler.kicool.ide.klighd.models.CodePlaceHolder
import de.cau.cs.kieler.kicool.ide.view.IdeCompilerView
import de.cau.cs.kieler.klighd.lsp.KGraphDiagramState
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageServerExtension
import de.cau.cs.kieler.language.server.ILanguageClientProvider
import de.cau.cs.kieler.language.server.KeithLanguageClient
import de.cau.cs.kieler.language.server.kicool.data.CodeOfModel
import de.cau.cs.kieler.language.server.kicool.data.CompilationResults
import de.cau.cs.kieler.language.server.kicool.data.CompileParam
import de.cau.cs.kieler.language.server.kicool.data.DidCompileParam
import de.cau.cs.kieler.language.server.kicool.data.SendCompilationSystemsParam
import de.cau.cs.kieler.language.server.kicool.data.ShowParam
import de.cau.cs.kieler.language.server.kicool.data.SnapshotDescription
import de.cau.cs.kieler.language.server.kicool.data.SystemDescription
import de.cau.cs.kieler.language.server.registration.RegistrationLanguageServerExtension
Expand Down Expand Up @@ -152,22 +154,23 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
/**
* Called by the client to compile a model
*
* @param uri The uri string of the model to compile (for snapshot compilation this is the uri of the original model.
* @param clientId The id of the diagram client.
* @param command The compilation system used to compile.
* @param inplace Whether in-place compilation should be used.
* @param showResultingModel Whether the final model should be shown in the diagram specified by clientId.
* @param snapshot Whether the model to compile is a snapshot model.
* @param param with: <br>
* - uri The uri string of the model to compile (for snapshot compilation this is the uri of the original model. <br>
* - clientId The id of the diagram client. <br>
* - command The compilation system used to compile. <br>
* - inplace Whether in-place compilation should be used. <br>
* - showResultingModel Whether the final model should be shown in the diagram specified by clientId. <br>
* - snapshot Whether the model to compile is a snapshot model.
*/
override compile(String uri, String clientId, String command, boolean inplace, boolean showResultingModel, boolean snapshot) {
val decodedUri = URLDecoder.decode(uri, "UTF-8")
override compile(CompileParam param) {
val decodedUri = URLDecoder.decode(param.uri, "UTF-8")
try {
var Object model
// Get input model for compilation.
if (snapshot) {
if (param.snapshot) {
// Abort if no diagram can be found.
if (diagramState === null || diagramState.getKGraphContext(decodedUri) === null) {
client.compile(null, decodedUri, true, 0, 1000)
client.didCompile(new DidCompileParam(null, decodedUri, true, 0, 1000))
return
}
model = diagramState.getKGraphContext(decodedUri).inputModel
Expand All @@ -176,12 +179,12 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
}
// Abort if no model to compile could be found.
if (model === null) {
client.compile(null, decodedUri, true, 0, 1000)
client.didCompile(new DidCompileParam(null, decodedUri, true, 0, 1000))
return
}

this.currentContext = createContextAndStartCompilationThread(model, command, inplace, this.currentContext,
decodedUri, clientId, showResultingModel)
this.currentContext = createContextAndStartCompilationThread(model, param.command, param.inplace, this.currentContext,
decodedUri, param.clientId, param.showResultingModel)
} catch( Exception e) {
e.printStackTrace()
sendError(e.toString())
Expand Down Expand Up @@ -250,27 +253,28 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
/**
* Display the current snapshot given by uri and index on the diagram widget given by the clientId.
*
* @param uri uri of model
* @param clientId id of diagramServer
* @param index index of snapshot. -1 equals the original model.
* @param param with: <br>
* - uri uri of model <br>
* - clientId id of diagramServer <br>
* - index index of snapshot. -1 equals the original model.
* @return completable future with index and id of showed model
*/
override show(String uri, String clientId, int index) {
val decodedUri = URLDecoder.decode(uri, "UTF-8")
override show(ShowParam param) {
val decodedUri = URLDecoder.decode(param.uri, "UTF-8")
var Object model
if (index == -1) {
if (param.index == -1) {
// Get model specified by uri
model = getModelFromUri(decodedUri)
} else {
// Get snapshot model from the compilation snapshots
model = this.objectMap.get(decodedUri).get(index)
model = this.objectMap.get(decodedUri).get(param.index)
}

// Send model to client.
val modelToSend = model
return requestManager.runRead [ cancelIndicator |
currentIndex = index
showSnapshot(decodedUri, clientId, modelToSend, cancelIndicator, false)
currentIndex = param.index
showSnapshot(decodedUri, param.clientId, modelToSend, cancelIndicator, false)
]
}

Expand All @@ -285,7 +289,7 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
try {
val systemDescriptions = getCompilationSystems(decodedUri, -1, false, false)
val snapshotSystemDescriptions = getCompilationSystems(decodedUri, -1, false, true)
client.sendCompilationSystems(systemDescriptions, snapshotSystemDescriptions)
client.sendCompilationSystems(new SendCompilationSystemsParam(systemDescriptions, snapshotSystemDescriptions))
} catch (Exception e) {
e.printStackTrace()
sendError("Could not retrieve compilation systems" + e)
Expand Down Expand Up @@ -436,7 +440,7 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
var future = new CompletableFuture()
future.complete(void)
future.thenAccept [
client.compile(new CompilationResults(this.snapshotMap.get(uri)), uri, finished, currentIndex, maxIndex)
client.didCompile(new DidCompileParam(new CompilationResults(this.snapshotMap.get(uri)), uri, finished, currentIndex, maxIndex))
].exceptionally [ throwable |
LOG.error('Error while sending compilation results.', throwable)
sendError('Error while sending compilation results.' + throwable)
Expand Down Expand Up @@ -470,34 +474,34 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC

}

override getCodeOfModel(String kgraphElementId, String clientId) {
if (this.diagramState.viewer !== null) {
val Object inputModel = diagramState.viewer.viewContext.inputModel
// Get uri of original model file
val uri = diagramState.getURIString(clientId)
// Get KNode that holds the code that should be displayed
val kNode = diagramState.getIdToKGraphMap(uri).get(kgraphElementId);
// Get model string
val CodePlaceHolder codeModel = if (inputModel instanceof CodePlaceHolder) {
inputModel as CodePlaceHolder
} else if (kNode !== null) {
// if input model is not CodePlaceHolder check if clicked node is associated with it
var Object domainElement = diagramState.viewer.viewContext.getSourceElement(kNode)
if (domainElement instanceof CodePlaceHolder) {
domainElement as CodePlaceHolder
}
}
// Get name of file
val code = new CodeOfModel(codeModel.name, codeModel.code)
return requestManager.runRead[ cancelIndicator |
code
]
} else {
return requestManager.runRead[ cancelIndicator |
new CodeOfModel("Error", "On error occurred while trying to get the code.")
]
}
}
// override getCodeOfModel(String kgraphElementId, String clientId) {
// if (this.diagramState.viewer !== null) {
// val Object inputModel = diagramState.viewer.viewContext.inputModel
// // Get uri of original model file
// val uri = diagramState.getURIString(clientId)
// // Get KNode that holds the code that should be displayed
// val kNode = diagramState.getIdToKGraphMap(uri).get(kgraphElementId);
// // Get model string
// val CodePlaceHolder codeModel = if (inputModel instanceof CodePlaceHolder) {
// inputModel as CodePlaceHolder
// } else if (kNode !== null) {
// // if input model is not CodePlaceHolder check if clicked node is associated with it
// var Object domainElement = diagramState.viewer.viewContext.getSourceElement(kNode)
// if (domainElement instanceof CodePlaceHolder) {
// domainElement as CodePlaceHolder
// }
// }
// // Get name of file
// val code = new CodeOfModel(codeModel.name, codeModel.code)
// return requestManager.runRead[ cancelIndicator |
// code
// ]
// } else {
// return requestManager.runRead[ cancelIndicator |
// new CodeOfModel("Error", "On error occurred while trying to get the code.")
// ]
// }
// }

/**
* Register observer to be included on start of new compilation.
Expand Down
Loading

0 comments on commit 03c832a

Please sign in to comment.