The goal is create a DSL which is able reference some elements from an external model. The external model could be any database, another DSL (a langium or a non-langium DSL) or some other model data. You require a node-module to query the external model.
The use case is to create glue model between different modeling worlds. Imagine a DSL to, e.g., glue an OpenAPI specification to a UML model: here you need a parser for an OpenAPI specification and one for the UML model. Your own DSL could reference both of these external models and act as glue between the two worlds.
In this demo, we demonstrate how to reference elements from a JSON file. Thus, the JSON file acts as external model / database.
The implementation is preliminary and needs to be discussed.
- An additional service
HelloJsonExternalJsonModel
for the JSON-database is registered inHelloJsonAddedServices
. The responsibility of this module is to (1) load JSON files and (2) access the data in the JSON files (what elements are visible and from which file location do they come from). - The
HelloJsonCompletionProvider
is responsible to auto complete references while being entered in the model. - The
HelloJsonValidator
is responsible to indicate errors, if a reference is not found. - The
HelloJsonDefinitionProvider
is responsible for the "Goto definition" functionality: You can press F12 on a reference to the JSON file and the jump to the location in the external model.
It seems mandatory, that the grammar element for the reference is kept simple, since the implementations sketched above are very simplistic. Simple means, that they consist of exactly one reference-field (jsonLink
, see grammar sketch below) - since it seems not to be trivial to distinguish the fields in the completion and goto-definition code.
JsonReference:
'reference' include=[JsonInclude]
':' jsonLink=FQN
Compile the project (npm i
, npm run build
) and press F5. You can then play with the model referencing an example JSON file.