I am working on creating a LSP based editor in Theia for one of our DSL, from this DSL we need to cross reference model defined in separate XMI file on the basis of FullQualifiedName.
I am able to implement this for eclipse plugin but unable to implement it for theia based editor. If there is any existing sample that is implementing this functionality in thiea then it would be great.
Solution -
Suppose we have defined a model in EMF which we can edit either using XMI based editor or text based Xtext editor .In a LSP based setup to cross refer the models defined in XMI file from Xtext based editor follow below steps -
1.Create a new project for defining the linkage.
2.Create a Runtime Module class to configure the runtime dependency
package io.typefox.xtextxmi.xtree.treeintegration
import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider
class TreeRuntimeModule extends AbstractGenericResourceRuntimeModule {
override protected getFileExtensions() {
'tree'
}
override protected getLanguageName() {
'io.typefox.xtextxmi.tree.Tree'
}
override bindIQualifiedNameProvider() {
DefaultDeclarativeQualifiedNameProvider
}
// bind additional services here
}
3.Create a Standalone Setup for activation
import com.google.inject.Inject
import org.eclipse.xtext.resource.FileExtensionProvider
import org.eclipse.xtext.ISetup
import org.eclipse.xtext.resource.IResourceServiceProvider
import com.google.inject.Guice
import io.typefox.xtextxmi.tree.TreePackage
import org.eclipse.emf.ecore.resource.Resource
import com.google.inject.Injector
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
class TreeStandaloneSetup implements ISetup {
@Inject
private FileExtensionProvider fileExtensionProvider;
@Inject
private IResourceServiceProvider resourceServiceProvider;
@Inject
private IResourceServiceProvider.Registry registry;
override createInjectorAndDoEMFRegistration() {
val injector = Guice.createInjector(new TreeRuntimeModule)
injector.injectMembers(this);
for (String fileExt : fileExtensionProvider.getFileExtensions())
registry.getExtensionToFactoryMap().put(fileExt, resourceServiceProvider)
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("tree", new XMIResourceFactoryImpl)
// the following implicitly registers the EPackage to the registry
TreePackage.eINSTANCE.eClass()
return injector
}
}
3.Define a ISetup file to register the TreeStandaloneSetup , folder structure should look like this: src->META-INF->services->org.eclipse.xtext.ISetup
Add a entry for full qualified name of Standalone setup class in the ISetup file- io.typefox.xtextxmi.xtree.treeintegration.TreeStandaloneSetup
4.Make sure to add this project to the classpath of ".ide" project , if it is maven/gradle based then simply add it to pom.xml/build.gradle of .ide project.
Note - I have used the sample given in Link & extended it for Eclipse Theia based LSP editor.