Welcome to Jgen Vs Code Extension
Introduction
Language Server Protocol is an open-source protocol for language services developed by Microsoft. It enables code editors and IDEs to communicate with external language services to provide features such as syntax highlighting, code completion, code navigation, code checking, code modification.
Langium is a tool for linguistic engineering that supports the Language Server protocol and is open-source, is similar to the Xtext grammar. It is written in TypeScript and works under Node.js. Langium can be used for various tasks such as code analysis, code generation, and auto-completion.
Jgen, the DSL, is constructed on the Spring Boot REST API Ecore metamodel, developed using Langium. Additionally, a CLI is implemented to generate code from DSL, facilitating transformation M2M between Ecore and Jgen metamodels, as well as transformation M2T when generating Spring Boot RESTful APIs.
The VS Code extension for the Jgen DSL allows the implementation of code validations, code completion, syntax highlighting, and a server protocol language. It features a tree view that synchronizes with the Jgen editor.
Features
- Domain specific language using Langium.
- Semantic validators for our DSL based on TypeScript code.
- Customizing the Jgen CLI.
- Parser for Jgen DSL that outputs JSON format.
- Transformation M2M between Ecore model and Jgen DSL.
- Generate Java RESTful APIs from Jgen DSL.
- Building an Extension.
- Open Jgen file.
- Initialize Jgen file.
- Import Ecore / JSON file.
- Tree view for Extension.
- Monaco Editor.
- Generation in the Web.
This is the Ecore metamodel for our DSL. It represents the metamodel of the basic functionalities of Spring Boot REST APIs. We need this metamodel for our M2M or M2T transformations, allowing us to perform transformations between different metamodels or generate code from the metamodel.

Jgen Extension Architecture
This diagram illustrates the general architecture of our Jgen extension:

Language Server Protocol (LSP)
The communication between the VS Code extension runtime / Web editor and the language server is facilitated through the LSP protocol to enable functionalities such as auto-completion, syntax highlighting, validation, generation, and more.

Get started
- Run
npm run langium:generate
to generate TypeScript code from the grammar definition.
- Run
npm run build
to compile all TypeScript code.
- Run
npm run build:web
and npm run serve
to start web editor.
- Press
F5
to open a new window with the Jgen extension loaded.
- Create a new file with a file name suffix
.jgen
.
- Verify that syntax highlighting, validation, completion, etc. are working as expected.
- Run
./bin/cli
to see options for the CLI; ./bin/cli generate <file>
generates code for a given DSL file.
- To generate REST code for a given DSL file with a specified destination, use the following command:
./bin/cli generateRESTfulAPI --help
to see options and help for the generateRESTfulAPI
command.
./bin/cli generateRESTfulAPI -d <destination-path> -p <file>
for file path or ./bin/cli generateRESTfulAPI -d <destination-path> -c "<jgen-content>"
for direct content. Replace <destination-path>
with the desired directory path where you want to store the generated code.
- To validate Grammar for a given DSL instance use the following command:
./bin/cli validateGrammar <file>
.
- To generate Ecore code / JSON format for a given DSL file with a specified destination, use the following command:
./bin/cli generateEcore / generateJson -d <destination-path> <file>
.
References
- Documentation about the Langium framework is available at https://langium.org/docs/
- Vs Code Extension Guidelines is available at https://code.visualstudio.com/api/ux-guidelines/overview
- MDE course available at https://portail.fil.univ-lille.fr/portail/index.php?dipl=MInfo&sem=GL&ue=IDM&label=Cours