Skip to content

NaoMod/XText-Language-Server-in-VSCode

Repository files navigation

XText DSL Language Server in VSCode

This project contains an XText project describing a very simple DSL to represent families. A language server can automatically be produced from this XText project and archived into a fat jar. This jar is then used in a Visual Studio Code extension. By convention, the file containing programs written in this DSL have the '.fml' extension and will be referred to as FML files.

The requirements to run the extension are :

  • JDK between [9, 17[

  • VSCode 1.49.0 or superior

The build sections provided in the following documentation are optional, as output files are also included in this repository. However, you can still re-build the server and client modules, especially if you want to experiment and make changes to the original code. The following tools are required :

Server Implementation with XText

Architecture

The folder server/naomod.family.parent is the root folder for the XText project. It contains 3 modules : * naomod.family : Contains the defintion of our DSL. The grammar is defined in src/naomod/family/Family.xtext while the static semantics are implemented in src_maomod/family/validation/FamilyValidator.java.

Family DSL definition

  • naomod.family.ide : contains information about the IDE generated for our DSL. Nothing was manually changes in this module.

  • naomod.family.tests : Contains tests for the other modules. There is currently a parsing test for a simple example of an FML file.

Build

Run : make buildServer

This command compiles the XText project, then generates a fatjar in server/naomod.family.parent/naomod.family.ide/target/ and copies it into client/src/.

VSCode Extension

Architecture

The file client/syntaxes/family.tmLanguage.json describes the syntax highlighting rules for the Family DSL. Since version 3.16.0 of LSP, it is possible to integrate this functionality in the language server, thanks to 'Semantic Tokens'. However, XText seems to either not support it (despite what’s reported on their documentation) or to require specific configuration.

The file client/src/naomod.family.ide-1.0.0-SNAPSHOT-ls.jar is the fatjar of the server generated during the server build.

The file client/src/extension.ts specifies the behavior for the activation and deactivation of our extension. During the activation, the language server is launched from the fatjar. It is automatically stopped during the deactivation.

Build

Run : make buildClient to fetch all the dependencies needed to run the client.

Running the Extension

Open this project inside VSCode. Using the Run and Debug tab, start the 'Lauch Client' configuration.

Launch Client configuration

This will start a new VSCode instance with our extension activated. To test it, you can open the file examples/sample.fml. You can see the content of the file benefits from syntactic coloration as well as static analysis thanks to the language server.

Sample FML using our language server

You can play around using the syntax showed in the example, either by creating a new file or editing the existing one.

Build Shortcuts

make clean to clean the build files for both client and server.

make build to build both client and server.