Skip to content

Commit 03c832a

Browse files
authored
Merge pull request #113 from kieler/nre/singleparametercommunication
Adapt Communication to only use one Parameter.
2 parents dc1bce8 + e1ced29 commit 03c832a

File tree

7 files changed

+307
-88
lines changed

7 files changed

+307
-88
lines changed

language-server/de.cau.cs.kieler.language.server/src/de/cau/cs/kieler/language/server/KeithLanguageClient.xtend

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* http://rtsys.informatik.uni-kiel.de/kieler
55
*
6-
* Copyright 2019 by
6+
* Copyright 2019-2024 by
77
* + Kiel University
88
* + Department of Computer Science
99
* + Real-Time and Embedded Systems Group
@@ -14,6 +14,8 @@ package de.cau.cs.kieler.language.server
1414

1515
import com.google.gson.JsonObject
1616
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient
17+
import de.cau.cs.kieler.language.server.kicool.data.DidCompileParam
18+
import de.cau.cs.kieler.language.server.kicool.data.SendCompilationSystemsParam
1719
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
1820
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment
1921
import org.eclipse.lsp4j.services.LanguageClient
@@ -30,8 +32,8 @@ interface KeithLanguageClient extends KGraphLanguageClient, LanguageClient {
3032
/**
3133
* The result object should have the type de.cau.cs.kieler.language.server.kicool.CompilationResults
3234
*/
33-
@JsonNotification("kicool/compile")
34-
def void compile(Object results, String uri, boolean finished, int currentIndex, int maxIndex);
35+
@JsonNotification("kicool/didCompile")
36+
def void didCompile(DidCompileParam param);
3537

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

4547
/**
4648
* Send to client if not the client itself invoked the simulation step.

language-server/de.cau.cs.kieler.language.server/src/de/cau/cs/kieler/language/server/kicool/KiCoolCommandExtension.xtend

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* http://rtsys.informatik.uni-kiel.de/kieler
55
*
6-
* Copyright 2018 by
6+
* Copyright 2018-2024 by
77
* + Kiel University
88
* + Department of Computer Science
99
* + Real-Time and Embedded Systems Group
@@ -13,6 +13,8 @@
1313
package de.cau.cs.kieler.language.server.kicool
1414

1515
import de.cau.cs.kieler.language.server.kicool.data.CodeOfModel
16+
import de.cau.cs.kieler.language.server.kicool.data.CompileParam
17+
import de.cau.cs.kieler.language.server.kicool.data.ShowParam
1618
import java.util.concurrent.CompletableFuture
1719
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification
1820
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
@@ -31,8 +33,7 @@ interface KiCoolCommandExtension {
3133
* Compiles file given by uri with compilationsystem given by command.
3234
*/
3335
@JsonNotification('compile')
34-
def void compile(String uri, String clientId, String command, boolean inplace, boolean showResultingModel,
35-
boolean snapshot);
36+
def void compile(CompileParam param);
3637

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

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

58-
/**
59-
* Request the contents of a CodeContainer as string together with its file name
60-
*/
61-
@JsonRequest("get-code-of-model")
62-
def CompletableFuture<CodeOfModel> getCodeOfModel(String kgraphElemntId, String clientId);
59+
// Currently unused, needs to be converted to use a single parameter.
60+
// /**
61+
// * Request the contents of a CodeContainer as string together with its file name
62+
// */
63+
// @JsonRequest("get-code-of-model")
64+
// def CompletableFuture<CodeOfModel> getCodeOfModel(String kgraphElemntId, String clientId);
6365
}

language-server/de.cau.cs.kieler.language.server/src/de/cau/cs/kieler/language/server/kicool/KiCoolLanguageServerExtension.xtend

+59-55
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* http://rtsys.informatik.uni-kiel.de/kieler
55
*
6-
* Copyright 2018 by
6+
* Copyright 2018-2024 by
77
* + Kiel University
88
* + Department of Computer Science
99
* + Real-Time and Embedded Systems Group
@@ -21,14 +21,16 @@ import de.cau.cs.kieler.kicool.compilation.CompilationContext
2121
import de.cau.cs.kieler.kicool.compilation.Compile
2222
import de.cau.cs.kieler.kicool.deploy.ProjectInfrastructure
2323
import de.cau.cs.kieler.kicool.environments.Environment
24-
import de.cau.cs.kieler.kicool.ide.klighd.models.CodePlaceHolder
2524
import de.cau.cs.kieler.kicool.ide.view.IdeCompilerView
2625
import de.cau.cs.kieler.klighd.lsp.KGraphDiagramState
2726
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageServerExtension
2827
import de.cau.cs.kieler.language.server.ILanguageClientProvider
2928
import de.cau.cs.kieler.language.server.KeithLanguageClient
30-
import de.cau.cs.kieler.language.server.kicool.data.CodeOfModel
3129
import de.cau.cs.kieler.language.server.kicool.data.CompilationResults
30+
import de.cau.cs.kieler.language.server.kicool.data.CompileParam
31+
import de.cau.cs.kieler.language.server.kicool.data.DidCompileParam
32+
import de.cau.cs.kieler.language.server.kicool.data.SendCompilationSystemsParam
33+
import de.cau.cs.kieler.language.server.kicool.data.ShowParam
3234
import de.cau.cs.kieler.language.server.kicool.data.SnapshotDescription
3335
import de.cau.cs.kieler.language.server.kicool.data.SystemDescription
3436
import de.cau.cs.kieler.language.server.registration.RegistrationLanguageServerExtension
@@ -152,22 +154,23 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
152154
/**
153155
* Called by the client to compile a model
154156
*
155-
* @param uri The uri string of the model to compile (for snapshot compilation this is the uri of the original model.
156-
* @param clientId The id of the diagram client.
157-
* @param command The compilation system used to compile.
158-
* @param inplace Whether in-place compilation should be used.
159-
* @param showResultingModel Whether the final model should be shown in the diagram specified by clientId.
160-
* @param snapshot Whether the model to compile is a snapshot model.
157+
* @param param with: <br>
158+
* - uri The uri string of the model to compile (for snapshot compilation this is the uri of the original model. <br>
159+
* - clientId The id of the diagram client. <br>
160+
* - command The compilation system used to compile. <br>
161+
* - inplace Whether in-place compilation should be used. <br>
162+
* - showResultingModel Whether the final model should be shown in the diagram specified by clientId. <br>
163+
* - snapshot Whether the model to compile is a snapshot model.
161164
*/
162-
override compile(String uri, String clientId, String command, boolean inplace, boolean showResultingModel, boolean snapshot) {
163-
val decodedUri = URLDecoder.decode(uri, "UTF-8")
165+
override compile(CompileParam param) {
166+
val decodedUri = URLDecoder.decode(param.uri, "UTF-8")
164167
try {
165168
var Object model
166169
// Get input model for compilation.
167-
if (snapshot) {
170+
if (param.snapshot) {
168171
// Abort if no diagram can be found.
169172
if (diagramState === null || diagramState.getKGraphContext(decodedUri) === null) {
170-
client.compile(null, decodedUri, true, 0, 1000)
173+
client.didCompile(new DidCompileParam(null, decodedUri, true, 0, 1000))
171174
return
172175
}
173176
model = diagramState.getKGraphContext(decodedUri).inputModel
@@ -176,12 +179,12 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
176179
}
177180
// Abort if no model to compile could be found.
178181
if (model === null) {
179-
client.compile(null, decodedUri, true, 0, 1000)
182+
client.didCompile(new DidCompileParam(null, decodedUri, true, 0, 1000))
180183
return
181184
}
182185

183-
this.currentContext = createContextAndStartCompilationThread(model, command, inplace, this.currentContext,
184-
decodedUri, clientId, showResultingModel)
186+
this.currentContext = createContextAndStartCompilationThread(model, param.command, param.inplace, this.currentContext,
187+
decodedUri, param.clientId, param.showResultingModel)
185188
} catch( Exception e) {
186189
e.printStackTrace()
187190
sendError(e.toString())
@@ -250,27 +253,28 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
250253
/**
251254
* Display the current snapshot given by uri and index on the diagram widget given by the clientId.
252255
*
253-
* @param uri uri of model
254-
* @param clientId id of diagramServer
255-
* @param index index of snapshot. -1 equals the original model.
256+
* @param param with: <br>
257+
* - uri uri of model <br>
258+
* - clientId id of diagramServer <br>
259+
* - index index of snapshot. -1 equals the original model.
256260
* @return completable future with index and id of showed model
257261
*/
258-
override show(String uri, String clientId, int index) {
259-
val decodedUri = URLDecoder.decode(uri, "UTF-8")
262+
override show(ShowParam param) {
263+
val decodedUri = URLDecoder.decode(param.uri, "UTF-8")
260264
var Object model
261-
if (index == -1) {
265+
if (param.index == -1) {
262266
// Get model specified by uri
263267
model = getModelFromUri(decodedUri)
264268
} else {
265269
// Get snapshot model from the compilation snapshots
266-
model = this.objectMap.get(decodedUri).get(index)
270+
model = this.objectMap.get(decodedUri).get(param.index)
267271
}
268272

269273
// Send model to client.
270274
val modelToSend = model
271275
return requestManager.runRead [ cancelIndicator |
272-
currentIndex = index
273-
showSnapshot(decodedUri, clientId, modelToSend, cancelIndicator, false)
276+
currentIndex = param.index
277+
showSnapshot(decodedUri, param.clientId, modelToSend, cancelIndicator, false)
274278
]
275279
}
276280

@@ -285,7 +289,7 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
285289
try {
286290
val systemDescriptions = getCompilationSystems(decodedUri, -1, false, false)
287291
val snapshotSystemDescriptions = getCompilationSystems(decodedUri, -1, false, true)
288-
client.sendCompilationSystems(systemDescriptions, snapshotSystemDescriptions)
292+
client.sendCompilationSystems(new SendCompilationSystemsParam(systemDescriptions, snapshotSystemDescriptions))
289293
} catch (Exception e) {
290294
e.printStackTrace()
291295
sendError("Could not retrieve compilation systems" + e)
@@ -436,7 +440,7 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
436440
var future = new CompletableFuture()
437441
future.complete(void)
438442
future.thenAccept [
439-
client.compile(new CompilationResults(this.snapshotMap.get(uri)), uri, finished, currentIndex, maxIndex)
443+
client.didCompile(new DidCompileParam(new CompilationResults(this.snapshotMap.get(uri)), uri, finished, currentIndex, maxIndex))
440444
].exceptionally [ throwable |
441445
LOG.error('Error while sending compilation results.', throwable)
442446
sendError('Error while sending compilation results.' + throwable)
@@ -470,34 +474,34 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
470474

471475
}
472476

473-
override getCodeOfModel(String kgraphElementId, String clientId) {
474-
if (this.diagramState.viewer !== null) {
475-
val Object inputModel = diagramState.viewer.viewContext.inputModel
476-
// Get uri of original model file
477-
val uri = diagramState.getURIString(clientId)
478-
// Get KNode that holds the code that should be displayed
479-
val kNode = diagramState.getIdToKGraphMap(uri).get(kgraphElementId);
480-
// Get model string
481-
val CodePlaceHolder codeModel = if (inputModel instanceof CodePlaceHolder) {
482-
inputModel as CodePlaceHolder
483-
} else if (kNode !== null) {
484-
// if input model is not CodePlaceHolder check if clicked node is associated with it
485-
var Object domainElement = diagramState.viewer.viewContext.getSourceElement(kNode)
486-
if (domainElement instanceof CodePlaceHolder) {
487-
domainElement as CodePlaceHolder
488-
}
489-
}
490-
// Get name of file
491-
val code = new CodeOfModel(codeModel.name, codeModel.code)
492-
return requestManager.runRead[ cancelIndicator |
493-
code
494-
]
495-
} else {
496-
return requestManager.runRead[ cancelIndicator |
497-
new CodeOfModel("Error", "On error occurred while trying to get the code.")
498-
]
499-
}
500-
}
477+
// override getCodeOfModel(String kgraphElementId, String clientId) {
478+
// if (this.diagramState.viewer !== null) {
479+
// val Object inputModel = diagramState.viewer.viewContext.inputModel
480+
// // Get uri of original model file
481+
// val uri = diagramState.getURIString(clientId)
482+
// // Get KNode that holds the code that should be displayed
483+
// val kNode = diagramState.getIdToKGraphMap(uri).get(kgraphElementId);
484+
// // Get model string
485+
// val CodePlaceHolder codeModel = if (inputModel instanceof CodePlaceHolder) {
486+
// inputModel as CodePlaceHolder
487+
// } else if (kNode !== null) {
488+
// // if input model is not CodePlaceHolder check if clicked node is associated with it
489+
// var Object domainElement = diagramState.viewer.viewContext.getSourceElement(kNode)
490+
// if (domainElement instanceof CodePlaceHolder) {
491+
// domainElement as CodePlaceHolder
492+
// }
493+
// }
494+
// // Get name of file
495+
// val code = new CodeOfModel(codeModel.name, codeModel.code)
496+
// return requestManager.runRead[ cancelIndicator |
497+
// code
498+
// ]
499+
// } else {
500+
// return requestManager.runRead[ cancelIndicator |
501+
// new CodeOfModel("Error", "On error occurred while trying to get the code.")
502+
// ]
503+
// }
504+
// }
501505

502506
/**
503507
* Register observer to be included on start of new compilation.

0 commit comments

Comments
 (0)