0

I have a DSL language where we need to cross-refer EAttribute that are defined in a separate file. This works fine in the eclipse plugin setup but it is not working in the LSP setup based on Vscode/Theia client.

Grammar Snippet -

Atomic returns Expression:
    {IntConstant} value=INT |
    {StringConstant} value=STRING |
    {BoolConstant} value=('true' | 'false') |
    {VariableRef} variable=[ecore::EAttribute|QualifiedName];

Example -

  1. DSL file - test.mexpression
  iota=1
  1. iota is a variable which is defined in a separate file - variables.ecore
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="vari" nsURI="vvvv" nsPrefix="var">
<eClassifiers xsi:type="ecore:EClass" name="Variables">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="iota" eType="ecore:EDataType 
 http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Cars" eType="ecore:EDataType 
http://www.eclipse.org/emf/2002/Ecore#//EString"
    defaultValueLiteral=""/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Car">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Model" eType="ecore:EDataType 
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>

Language client Snippet -

 export function activate(context: ExtensionContext) {
     // The server is a started as a separate app and listens on port 5007
     let connectionInfo = {
         port: 5008
     };
     let serverOptions = () => {
         // Connect to language server via socket
         let socket = net.connect(connectionInfo);
         let result: StreamInfo = {
             writer: socket,
             reader: socket
         };
         return Promise.resolve(result);
     };
     
     let clientOptions: LanguageClientOptions = {
         documentSelector: ['mexpression','ecore'],
         synchronize: {
             fileEvents: workspace.createFileSystemWatcher('**/*.*')
         }
     };
     
     // Create the language client and start the client.
     let lc = new LanguageClient('Xtext Server', serverOptions, clientOptions);

Am I missing something here ? or We have to create a standalone setup for variable file & register it via service providers to make it work in LSP environment.

kuldeep singh
  • 25
  • 1
  • 7
  • you need to make sure you provide a language server for ecore. a lightweight solution could be to create a manifest for the org.eclipse.xtext.ecore.EcoreSupport similar as described here https://stackoverflow.com/questions/66968029/how-to-implement-the-xtext-xmi-cross-reference-for-lsp-based-editor-in-theia – Christian Dietrich Jun 04 '21 at 16:54
  • Cross-referencing is working but workspace manager is throwing below error while saving variable file - java.lang.ClassCastException: class org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl cannot be cast to class org.eclipse.xtext.resource.XtextResource (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl and org.eclipse.xtext.resource.XtextResource are in unnamed module of loader 'app') at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:436) at org.eclipse.xtext.ide.server.LanguageServerImpl$1.lambda$doRead$1(LanguageServerImpl.java:1093) at – kuldeep singh Jun 05 '21 at 12:56
  • yes you may have to work around this. (dont know what exact line 1093 does in your Xtext version) – Christian Dietrich Jun 05 '21 at 19:26
  • Xtext version being used - 2.23.0.v20200831-0745 Code at line 1093- return requestManager.runRead(cancelIndicator -> workspaceManager.doRead(uriExtensions.toUri(uri), (document, resource) -> function.apply(new ILanguageServerAccess.Context(resource, document, workspaceManager.isDocumentOpen(resource.getURI()), cancelIndicator)))); Code at line 436 causing exception within doRead- XtextResource resource = (XtextResource) projectMnr.getResource(resourceURI); – kuldeep singh Jun 07 '21 at 05:45
  • i still dont see which service is calling this. – Christian Dietrich Jun 07 '21 at 09:12
  • Stack trace - java.lang.ClassCastException: class org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl cannot be cast to class org.eclipse.xtext.resource.XtextResource (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl and org.eclipse.xtext.resource.XtextResource are in unnamed module of loader 'app') at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:436) at org.eclipse.xtext.ide.server.LanguageServerImpl$1.lambda$doRead$1(LanguageServerImpl.java:1093) at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:66) – kuldeep singh Jun 09 '21 at 08:33
  • Adding more details - On save of variable file a build is run which is initiating the doRead method of WorkspaceManager.Flow- Variable File save -> LanguageServerImpl(afterBuild) ->LanguageServerImpl.access(doRead) ->RequestManager(runRead)->WorkspaceManager(doRead) – kuldeep singh Jun 09 '21 at 08:51
  • from this i still dont get: why is doRead called, why is there not the internal build only? did you configure the client to know the ecore file extension? – Christian Dietrich Jun 09 '21 at 12:01
  • Added the language client code in the question section. – kuldeep singh Jun 09 '21 at 13:55
  • Getting Same error even when I hover over conetnts in XMI variable file - java.lang.ClassCastException: class org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl cannot be cast to class org.eclipse.xtext.resource.XtextResource (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl and org.eclipse.xtext.resource.XtextResource are in unnamed module of loader 'app') at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:436) at org.eclipse.xtext.ide.server.LanguageServerImpl.hover(LanguageServerImpl.java:713) – kuldeep singh Jun 09 '21 at 16:03
  • my proposal was not to add ecore in the client but just ship it. dont know if this works with changes. with a client working on ecore you need to adapt all the code that cannot deal with it. – Christian Dietrich Jun 09 '21 at 18:35
  • you may file an enhancement request at github.com/eclipse/xtext-core. but i have doubts we will find the time to fix it soon. i also have no clue how to properly implement stuff like content assist and co – Christian Dietrich Jun 09 '21 at 18:44
  • maybe you also can configure the clent to notifiy the server via didChangeWatchedFiles and not do contant assist and co for ecore – Christian Dietrich Jun 09 '21 at 18:57
  • If we do not register variable file in the language client then changes/updates to the file are not reflecting on LanguageServer. – kuldeep singh Jun 10 '21 at 15:33
  • thus the question if you can look into didChangeWatchedFiles – Christian Dietrich Jun 10 '21 at 17:15
  • I don't need content assist or co on variable file, but it is failing on file save as well. Though I don't know much about didChangeWatchedFiles but will give it a go. – kuldeep singh Jun 14 '21 at 16:58

0 Answers0