<
From version < 18.1 >
edited by Soeren Domroes
on 2019/04/18 12:04
To version < 22.1 >
edited by Soeren Domroes
on 2019/05/16 10:52
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -175,9 +175,9 @@
175 175  
176 176  We use java ServiceLoader to register stuff. Here is a small example how a LanguageServerExtension is registered via a ServiceLoader and how it is used:
177 177  
178 -== ServiceLoader Example ==
178 +== Register LanguageServerExtensions (ServiceLoader Example) ==
179 179  
180 -This is a LanguageServerExtension. It has to be used in the de.cau.cs.kieler.language.server plugin. Since the language-sever-plugin should not have dependencies to all plugins that define a language server extension dependency inversion is used to prevent that. A ServiceLoader does exactly that.
180 +This is a LanguageServerExtension. It has to be used in the de.cau.cs.kieler.language.server plugin. Since the language-server-plugin should not have dependencies to all plugins that define a language server extension dependency inversion is used to prevent that. A ServiceLoader does exactly that.
181 181  
182 182  Here is such an example extension, the KiCoolLanguageServerExtension:
183 183  
... ... @@ -190,11 +190,34 @@
190 190   *
191 191   */
192 192  @Singleton
193 -class KiCoolLanguageServerExtension implements ILanguageServerExtension, CommandExtension {
194 - // fancy extension stuff
193 +class KiCoolLanguageServerExtension implements ILanguageServerExtension, CommandExtension, ILanguageClientProvider {
194 + // fancy extension stuff
195 +
196 + var KeithLanguageClient client
197 + // A language server extension must implement the initialize method,
198 + // it is however only called if the extension is registered via a language.
199 + // This should never be the case, so this is never called.
200 + override initialize(ILanguageServerAccess access) {
201 + this.languageServerAccess = access
202 + }
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 + }
213 +
195 195  }
196 196  {{/code}}
197 197  
217 +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)"]]
218 +
219 +The ILanguageClientProvider should be implemented by an extension that plans to send [[messages from the server to the client>>doc:||anchor="ServerClientcommunicationinterface"]].
220 +
198 198  This language server extension is provided by a corresponding contribution, which is later used to access it:
199 199  
200 200  {{code}}
... ... @@ -240,7 +240,7 @@
240 240  
241 241  What is still missing are the contents of the CommandExtension implemented by the KiCoolLanguageServerExtension. This is an interface defining all additional commands. The CommandExtension looks like this.
242 242  
243 -{{code}}
266 +{{code title="Example CommandExtension"}}
244 244  package de.cau.cs.kieler.kicool.ide.language.server
245 245  
246 246  import java.util.concurrent.CompletableFuture
... ... @@ -281,6 +281,61 @@
281 281  
282 282  This defines three json-rpc commands: "keith/kicool/compile", "keith/kicool/show", "keith/kicool/get-systems". These are implemented in KiCoolLanguageServerExtension.
283 283  
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}}
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}}
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}}
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 +
284 284  == Register and calling an extension (on client side) ==
285 285  
286 286  Language server extension do not have to be registered on the client side. It is just called.
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -57802987
1 +57802997
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/57802987/Running KEITH
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/57802997/Running KEITH