Changes for page Running KEITH
Last modified by Richard Kreissig on 2023/09/14 08:48
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -169,7 +169,7 @@ 169 169 170 170 === Known issues: === 171 171 172 - Refreshing the browser is not enough for the diagram to work. If the diagram is needed the language server has to be restarted before the browser is refreshed. This is a known issue in theia-sprotty.172 +\\ 173 173 174 174 = Developing for KEITH = 175 175 ... ... @@ -193,6 +193,7 @@ 193 193 class KiCoolLanguageServerExtension implements ILanguageServerExtension, CommandExtension, ILanguageClientProvider { 194 194 // fancy extension stuff 195 195 196 + var KeithLanguageClient client 196 196 // A language server extension must implement the initialize method, 197 197 // it is however only called if the extension is registered via a language. 198 198 // This should never be the case, so this is never called. ... ... @@ -199,6 +199,16 @@ 199 199 override initialize(ILanguageServerAccess access) { 200 200 this.languageServerAccess = access 201 201 } 203 + 204 + // implement ILanguageClientProvider 205 + override setLanguageClient(LanguageClient client) { 206 + this.client = client as KeithLanguageClient 207 + } 208 + 209 + // implement ILanguageClientProvider 210 + override getLanguageClient() { 211 + return this.client 212 + } 202 202 203 203 } 204 204 {{/code}} ... ... @@ -205,7 +205,7 @@ 205 205 206 206 The CommandExtension defines all commands (requests or notifications) that are send from client to server. An example how this looks like can be seen in the code snippet Example CommandExtension is an example how to [[define a server side extension interface.>>doc:||anchor="Registeranextension(onserverside)"]] 207 207 208 - \\219 +The ILanguageClientProvider should be implemented by an extension that plans to send [[messages from the server to the client>>doc:||anchor="ServerClientcommunicationinterface"]]. 209 209 210 210 This language server extension is provided by a corresponding contribution, which is later used to access it: 211 211 ... ... @@ -293,6 +293,61 @@ 293 293 294 294 This defines three json-rpc commands: "keith/kicool/compile", "keith/kicool/show", "keith/kicool/get-systems". These are implemented in KiCoolLanguageServerExtension. 295 295 307 +\\ 308 + 309 +== Server Client communication interface == 310 + 311 +Not only messages from client to server but rather messages from server client might be needed. 312 + 313 +Messages that can be send from server to client are defined in the KeithLanguageClient: 314 + 315 +{{code title="Example KeithLanguageLCient"}} 316 +/** 317 + * LanguageClient that implements additional methods necessary for server client communication in KEITH. 318 + * 319 + * @author really fancy name 320 + * 321 + */ 322 + @JsonSegment("keith") 323 +interface KeithLanguageClient extends LanguageClient { 324 + 325 + @JsonNotification("kicool/compile") 326 + def void compile(Object results, String uri, boolean finished); 327 + 328 + @JsonNotification("kicool/cancel-compilation") 329 + def void cancelCompilation(boolean success); 330 + 331 + // Not only notifications, but also server client requests should be possible, but currently there is no use case for that. 332 +} 333 +{{/code}} 334 + 335 +These messages can be caught on the client side by defining the message that is caught like this: 336 + 337 +{{code title="Client side message definition"}} 338 +export const snapshotDescriptionMessageType = new NotificationType<CodeContainer, void>('keith/kicool/compile'); 339 +{{/code}} 340 + 341 +This message type is bound to a method that should be called whenever the client receives such a message. 342 + 343 +{{code title="Client side message registration"}} 344 +const lClient: ILanguageClient = await this.client.languageClient 345 +lClient.onNotification(snapshotDescriptionMessageType, this.handleNewSnapshotDescriptions.bind(this)) 346 +{{/code}} 347 + 348 +The method should receive all parameters specific in the KeithLanguageClient interface on the serevr side. 349 + 350 +Such a notification from server to client is send like this: 351 + 352 +{{code title="Server side message sending"}} 353 +future.thenAccept([ 354 + // client is the KeithLanguageClient registered in a LanguageServerExtension that implements a ILanguageClientProvider 355 + // compile is the command defined in the KeithLanguageClientInterface 356 + client.compile(new CompilationResults(this.snapshotMap.get(uri)), uri, finished) 357 +]) 358 +{{/code}} 359 + 360 +\\ 361 + 296 296 == Register and calling an extension (on client side) == 297 297 298 298 Language server extension do not have to be registered on the client side. It is just called. ... ... @@ -299,7 +299,7 @@ 299 299 300 300 You can send a request or a notification to the language server like this: 301 301 302 -{{code}} 368 +{{code title="Client side message sending"}} 303 303 const lclient = await this.client.languageClient 304 304 const snapshotsDescriptions: CodeContainer = await lclient.sendRequest("keith/kicool/compile", [uri, KeithDiagramManager.DIAGRAM_TYPE + '_sprotty', command, 305 305 this.compilerWidget.compileInplace]) as CodeContainer ... ... @@ -313,10 +313,10 @@ 313 313 314 314 In this example client is an instance of a language client. It is usually injected like this: 315 315 316 -{{code}} 382 +{{code title="Client side LanguageClientContribution injection"}} 383 +@inject(KeithLanguageClientContribution) public readonly client: KeithLanguageClientContribution 317 317 constructor( 318 - @inject(KeithLanguageClientContribution) public readonly client: KeithLanguageClientContribution 319 - // other injected classes 385 + // other injected classes that are relevant for the constructor 320 320 ) { 321 321 // constructor stuff 322 322 }
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 -5780 29941 +57803004 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/5780 2994/Running KEITH1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/57803004/Running KEITH