Reputation: 1
We are using Xtext LSP for our language contribution in Vscode but facing a challenge . We want to implement support for basic project where we attach a project configuration with all the xtext resources.
A project is defined by a .projectConfig
file in a folder so we want resource of this file to be accessible across different modules like code Generator, CommandConribution, etc.
So, We created a class ProjectConfigResourceDescription
that extends Adapter
which, includes basic information of workspace i.e. artifact id, group id and version.
public class ProjectConfigResourceDescription extends AdapterImpl{
String artifactName;
String groupName;
String verison;
public ProjectConfigResourceDescription(String artifactName,String groupName,String version)
{
this.artifactName=artifactName;
this.groupName=groupName;
this.verison=version;
}
We need to attach the object of class ProjectConfigResourceDescription
with Xtext resource
while activating the workspace(lsp)
. So that we can get the artifact id, group id and version at the time of code Generation.
We implemented the attachToEmfObject
method to fulfil our purpose.
public <T> void attachToEmfObject(Notifier emfObject,T element) {
if (findInEmfObject(emfObject,element.getClass()) != null)
throw new IllegalStateException("The given EMF object already contains an adapter for ProjectConfigDescription");
emfObject.eAdapters().add((Adapter) element);
}
Currently, we attach the object at a particular attachToResource event, that has to be triggered manually by the user.
What is the best way to attach this ProjectConfigResourceDescription
object to Xtext resource at the time of Activation and keep track of Changes to this Object?
Upvotes: 0
Views: 52
Reputation: 862
First I'm not sure what the link is with LSP.
If I understand correctly, you have some DSL made with Xtext. Instances are serialized by Xtext in files such as "x.dsl". You have some additional data in ".projectConfig". I assume ".projectConfig" lives alongside "x.dsl" (in the same directory, or some easily-found associated directory).
I think the easiest way would be to manually load this file whenever you want to operate on your DSL instance. This way you don't have to insert yourself in the EMF/Xtext/Resource lifecycle. Simply modify your e.g. Code Generator APIs to take an additional parameter.
Upvotes: 1