Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Load models of imported Ecore in Xtext Language Server(Using library approach)
Load models of imported Ecore in Xtext Language Server [message #1855641] Tue, 25 October 2022 10:50 Go to next message
Byron Trollip is currently offline Byron TrollipFriend
Messages: 4
Registered: April 2022
Junior Member
We have developed an Xtext language that generates an Ecore. The project runs as a Language Server and uses Gradle.

The Xtext grammar also imports a different Ecore that we created separately. This second Ecore is used to represent models that are 'library code' (single instances of predefined objects). The models conforming to the 'library' Ecore have been serialized to XMI and are built into a JAR that is a dependency of the Xtext DSL project.

The use case is to allow cross-references from our grammar to EClasses in the imported Ecore and then scoping to 'library' model objects at runtime.

The project builds correctly, so the grammar is aware of the imported Ecore package.

We understand that the XMI models of the imported Ecore must be loaded at runtime and made available in the index for cross-referencing to occur.

However, we are not able to understand how to load our XMI models correctly into the ResourceSet, so that they can be managed by Xtext at runtime. There does not seem to be much existing information about how to implement this concept within an Xtext Language Server.

Investigations have led us to consider loading the XMI models in the Language Server (IDE) project. Relevant classes that have been identified as potentially useful are: LanguageServerImpl and WorkspaceManager.

The problem is that we do not understand where to load the XMI models, such that they are added to the ResourceSet along with the Xtext resources of documents of our DSL.

Ideally, we want Xtext to load these XMI models eagerly, so that they are available in the ResourceSet in a performant way.

Is there any 'lifecycle hook' in the Xtext DSL or IDE projects that could be extended to allow us to load the XMI models into the ResourceSet to satisfy our requirement?

Alternately, is there another approach we could consider that will achieve the same desired behavior?
Re: Load models of imported Ecore in Xtext Language Server [message #1855642 is a reply to message #1855641] Tue, 25 October 2022 11:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
i haved no idea but the naive approach to do this at the place the resourceset is created does not work?
https://github.com/eclipse/xtext-core/pull/1877
org.eclipse.xtext.ide.server.ProjectManager.createFreshResourceSet(ResourceDescriptionsData)
org.eclipse.xtext.ide.server.ProjectManager.createNewResourceSet(ResourceDescriptionsData)
org.eclipse.xtext.ide.server.ProjectManager.createLiveScopeResourceSet()


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Load models of imported Ecore in Xtext Language Server [message #1855815 is a reply to message #1855642] Fri, 04 November 2022 12:32 Go to previous message
Byron Trollip is currently offline Byron TrollipFriend
Messages: 4
Registered: April 2022
Junior Member
Thanks for the response Christian.

After attempting the approach to manually manage the loading of the XMI models in a custom LanguageServerImpl, we changed our approach to instead base our solution on the TypeFox blog post - Linking Xtext Models With EMF Models found at https://www.typefox.io/blog/linking-xtext-models-with-other-emf-models

We first tried the naive approach that you mentioned by "hacking" the Xtext builder mechanism before realizing that we could not easily extend the ProjectManager due to the Provider<ProjectManager> Guice injection that is used in the WorkspaceManager. Diving deep into the incremental builder code seemed to be the wrong approach in any case, for a functionality that is managed by Xtext with many complex moving parts.

The solution provided in the TypeFox blog post - Linking Xtext Models With EMF Models required us to implement a new Gradle subproject containing the "glue code" to register XMI as a language. This subproject is provided as a dependency to our language server, alongside our grammar subproject. This separation of concerns kept things clean in our grammar project. The XMI language subproject provides a language definition in a custom XmiRuntimeModule as well as registering a resource service provider for *.xmi files in a custom XmiStandaloneSetup. Lastly, we had to add an entry for the XmiStandaloneSetup in a META-INF/services/org.eclipse.xtext.ISetup, so that Xtext can "bootstrap" the XMI language at runtime.

Since the XMI language subproject is not concerned with the contents of any XMI file, we left the work to resolve the EPackage of any loaded XMI documents to the model consumer, in this case the Xtext grammar project, which registers all the required EPackages.

A drawback of this approach is that the XMI files containing the models need to be present as files in the workspace, as discovery of XMIs in JARs did not occur. This is slightly annoying, but we could live with this downside.

If you know of any way to have Xtext scan the contents of JARs in the workspace for registered language file extensions, it would be appreciated.



Previous Topic:Trying to resolve all cross-references of an EObject model from an .aadl file.
Next Topic:Removing insecure log4j dependency
Goto Forum:
  


Current Time: Mon Oct 07 13:47:20 GMT 2024

Powered by FUDForum. Page generated in 0.03490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top