Skip to content

Adapting a Model Language to Work with KLighD VSCode

Niklas Rentz edited this page Jun 2, 2022 · 2 revisions

Existing Syntheses for EMF models can be extended to provide a language server for that language with KLighD diagram support. The OSGiViz Language Server will serve as an example project with a working implementation, here I will go into detail on the important parts to adapt that to a different language.

You need to create a new bundle for the language server of your language as in the example with four classes to define your diagram contribution:

  • a language registration to set up your language on startup of the server. For Xtext languages you can use its language server setup, for other EMF models such as in this example you need to initialize the language's package by instanciating it and put the file extension of the models to be registered with its resource factory, here the XMIResourceFactoryImpl,
  • an LS extension to define your model extension, its readable name and a list of keywords for that language (empty here),
  • an LS creator registering that LS extension,
  • and a language server, just referring to the other classes you defined.

This language server can be executed from Eclipse directly with a launch configuration similar to these ones. These are different, depending if you launch KLighD direcly from the sources in your workspace or from direct dependencies. To adapt these, just replace the OSGiViz classpath entries for your model/language.

To launch the LS as a built jar, you would need to adapt the language server cli build process. Here we use Maven with a custom jar build, which is currently necessary to build KLighD into a standalone application due to a troublemaker dependency (SWT). This will be changed soon in one of the next KLighD releases to allow a default Maven shade build to work here as well.

This jar can then be used together with the KLighD CLI to view the diagrams via the browser.