Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Configure single Language Server with multiple grammars (IResourceServiceProvider)
Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1799936] Mon, 17 December 2018 11:51 Go to next message
Eclipse UserFriend
Hi,

we are working on migrating an existing Xtext project from an Eclipse application to a Language Server solution.
The project has multiple grammars/languages in separate sub-projects. Currently only the language(s) of one sub-project are integrated with the language server.

How can we integrate multiple languages from different subprojects into the Language Server so their ISetup is loaded?

Details

Existing setup (based on "New Project Wizard" and existing code base):

  • org.example.mylang
    • MyLangA.xtext
    • MyLangB.xtext
    • GenerateMyLang.mwe2
      • generates infrastructure for MyLangA.xtext and MyLangB.xtext.
        Uses standard XtextGenerator as created by the wizard with 2 custom language = XtextGeneratorLanguage for MyLangA and MyLangB
      • genericIde generates META-INF/services/org.eclipse.xtext.ISetup file with MyLangAIdeSetup and MyLangBIdeSetup in org.example.mylang.ide
      • StandaloneSetup bean does registerGenModelFile and registerGeneratedEPackage for platform:/resource/org.example.other/model/generated/Other.genmodel

  • org.example.mylang.ide
    • Gradle mainClassName = "org.eclipse.xtext.ide.server.ServerLauncher"

  • org.example.other
    • Other.xtext
    • GenerateOther.mwe2
      • generates infrastructure for Other.xtext
      • No genericIde / org.example.other.ide


The org.eclipse.xtext.ISetup implementations for the org.example.mylang languages (MyLangA/BIdeSetup) are loaded by the ResourceServiceProviderServiceLoader so the correct IResourceServiceProviders are registered for their file extensions (e.g. langa and langb).
The generated OtherStandaloneSetupGenerated implementation registers to the IResourceServiceProvider.Registry.INSTANCE which is different from the IResourceServiceProvider.Registry created by ResourceServiceProviderServiceLoader, so the Other language is not recognized by the language server.

What would be the recommended Xtext MWE2 workflow and project configuration/layout so that:


  • META-INF/services/org.eclipse.xtext.ISetup is generated containing the service providers for all languages (MyLangA, MyLangB, Other)
  • the ResourceServiceProviderServiceLoader of a single Language Server loads these ISetup implementations for all languages (MyLangA, MyLangB, Other)


Thanks for your help, cheers
Goan
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800005 is a reply to message #1799936] Tue, 18 December 2018 13:52 Go to previous messageGo to next message
Eclipse UserFriend
simply put all ide projects and thus the services to the place where you start the server from.
xtext will read all service info files

=> i dont understand what exactly is not working for you

[Updated on: Tue, 18 December 2018 13:52] by Moderator

Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800022 is a reply to message #1799936] Wed, 19 December 2018 02:27 Go to previous messageGo to next message
Eclipse UserFriend
I assume from here that there is only .ide project and thus only one org.eclipse.xtext.ISetup, which can only refer to one language setup. There must be one for each language, i.e. multiple .ide projects.
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800023 is a reply to message #1800022] Wed, 19 December 2018 02:30 Go to previous messageGo to next message
Eclipse UserFriend
well yes but i wonder how Goan managed not the have an ide project for other.
is it a legacy project with old workflow?
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800026 is a reply to message #1800023] Wed, 19 December 2018 03:01 Go to previous messageGo to next message
Eclipse UserFriend
If multiple languages are shared in one project (which is not that unusual), the default project layout would result also in one .ide and one .ui project. So this has to change for the ide part.
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800040 is a reply to message #1800026] Wed, 19 December 2018 05:05 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your answers!

Quote:
well yes but i wonder how Goan managed not the have an ide project for other.
is it a legacy project with old workflow?


Yes it is a legacy project (workflows used old generator, no LSP only Eclipse) that we are migrating to a Language Server only solution.
For this we started with a fresh project created by the wizard (only "Generic IDE Support", Gradle) that created the org.example.mylang and org.example.mylang.ide projects. Then we integrated the existing code base.

The org.example.other project was taken as it was and therefore has no respective org.example.other.ide project. It contains the Other.xtext language which is used by MyLangA.xtext and MyLangB.xtext. For this we created a custom but pretty standard org.example.other::GenerateOther.mwe2 workflow that generates Other.genmodel and is consumed by org.example.mylang::GenerateMyLang.mwe2 via StandaloneSetup bean (see details of first post).
Also org.example.other contains an Resource.ecore+genmodel without a grammar (represents a resource file which is cross-referenced in MyLangA+B) which org.example.other::GenerateOther.mwe2 processes with an EcoreGenerator.

Quote:
=> i dont understand what exactly is not working for you


Only the ISetups for MyLangAIdeSetup + MyLangBIdeSetup are picked up by the Language Servers so the Other.xtext (and Resource.ecore) don't work with the Language Server.
We tried calling org.example.other::OtherStandaloneSetup in by org.example.mylang::MyLangAStandaloneSetup. It seemed to do the required registration of the IResourceServiceProvider (to IResourceServiceProvider.Registry.INSTANCE) but it was not working as the Language Server's ResourceServiceProviderServiceLoader creates is own IResourceServiceProvider.Registry and does not use IResourceServiceProvider.Registry.INSTANCE as we found out while debugging. Confusing but there probably is a reason for that?

Possible solutions


  1. Create a org.example.other.ide project and add genericIde config to the org.example.other::GenerateOther.mwe2 so META-INF/services/org.eclipse.xtext.ISetup is generated.
    Create a new org.example.mylang.server project as the new Language Server application (mainClassName = "org.eclipse.xtext.ide.server.ServerLauncher") that has org.example.other.ide and the org.example.mylang.ide as Gradle dependencies. The Language Server then loads all generated META-INF/services/org.eclipse.xtext.ISetup of the dependency ide projects.
  2. Use a single GenerateAll.mwe2 workflow for all languages so a single XtextGenerator (output of multiple ones seem to overwrite/delete each other) can generate the META-INF/services/org.eclipse.xtext.ISetup for all languages in a single org.example.mylang.ide project. Not sure where to put this workflow (in org.example.mylang?) and if the org.example.other sub-project can be kept or needs to be integrated into one project containing the workflow (e.g. org.example.mylang)?


In the meantime we went with option 1 as it seemed to match the existing structure and it is working. Is this the recommended way?
Also what is the recommended way so the ISetup for org.example.other::Resource.ecore is also loaded by the language server? As there is no grammar for it Xtext does not seem to generate a setup. So far we created a manual ISetup class but this needs to be included in the service loader config file as well. Can the setup be generated with the org.example.other::GenerateOther.mwe2 or its inclusion in the generated org.example.other.ide::META-INF/services/org.eclipse.xtext.ISetup be configured in the workflow?

Cheers
Goan
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800042 is a reply to message #1800040] Wed, 19 December 2018 05:26 Go to previous messageGo to next message
Eclipse UserFriend
the recommendation is to migrate other to the new workflow as well
since you need
- an content assist parser
- tons of bindings in ide module
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800057 is a reply to message #1800042] Wed, 19 December 2018 06:29 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, so we go along with option 1. The content assist parser and binding are created all right in the org.example.other.ide module.

Would be great if could also advice for:

Quote:
Also what is the recommended way so the ISetup for org.example.other::Resource.ecore is also loaded by the language server? As there is no grammar for it Xtext does not seem to generate a setup. So far we created a manual ISetup class but this needs to be included in the service loader config file as well. Can the setup be generated with the org.example.other::GenerateOther.mwe2 or its inclusion in the generated org.example.other.ide::META-INF/services/org.eclipse.xtext.ISetup be configured in the workflow?

[Updated on: Wed, 19 December 2018 06:30] by Moderator

Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800059 is a reply to message #1800057] Wed, 19 December 2018 06:55 Go to previous messageGo to next message
Eclipse UserFriend
you can package multiple service loader files to the classpath
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800069 is a reply to message #1800059] Wed, 19 December 2018 09:07 Go to previous messageGo to next message
Eclipse UserFriend
Sorry I don't get what you mean by "package"? The org.example.server language server now already loads multiple config files (from the 2 org.example.*.ide projects) exposed to the classpath.

My last question was:
How to create the ISetup for Resource.ecore which has no grammar but only an ecore+genmodel file (which is processed by an EcoreGenerator)?
Can the respective ResourceIdeSetup and service loader config file be generated automatically? Or do we need to create this all manually?

The current org.example.other::GenerateOther.mwe2:

Workflow {
	    
	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "org.example.other"
				rootPath = ".."
				runtimeTest = {
					enabled = true
				}
				genericIde = {
					enabled = true
				}
				mavenLayout = true
			}
			code = {
				encoding = "UTF-8"
				lineDelimiter = "\n"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "org.example.other.Other"
			fileExtensions = "other"

			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}
	
	component = org.eclipse.emf.mwe2.ecore.EcoreGenerator {
		genModel = "platform:/resource/org.example.other/model/Resource.genmodel"
		srcPath ="platform:/resource/org.example.other/src"
	}
	
}
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800070 is a reply to message #1800069] Wed, 19 December 2018 09:19 Go to previous messageGo to next message
Eclipse UserFriend
if you put a service loader to others jar
and add this jar to the mydsl.ide project as dependency
then the loader will pick up both service files
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800085 is a reply to message #1800070] Wed, 19 December 2018 11:46 Go to previous messageGo to next message
Eclipse UserFriend
Yes I've already done that for org.example.server which depends on the *.ide projects. It works and picks up the ide service config files from the *.ide JARs. So this part of my problem is solved :)

My last question (my last post above) is not about the service loader mechanism.
It is about how to create the ISetup implementing service class themselves (which is contained in the JAR) but not for a language, but for a Resource.ecore which has no grammar but only an ecore+genmodel definition. The workflow uses an an EcoreGenerator, so no ISetup implementation is generated by Xtext.
Is it possible to generate an ResourceIdeSetup for an Resource.ecore/genmodel file without a Resource.xtext grammar? Or does it (and any other supporting classes like the content assist you mentioned) need to be created manually?

Sorry if I was not clear enough. If its still not clear, please tell me which pieces are missing.
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800087 is a reply to message #1800085] Wed, 19 December 2018 12:01 Go to previous messageGo to next message
Eclipse UserFriend
the thing you build is basically a resource service provider. (samne as you would do for standalone and eclipse)
thus you need to translate what is described here to lsp/ide:
https://blogs.itemis.com/en/combining-emf-models-with-xtext-dsls
https://typefox.io/linking-xtext-models-with-other-emf-models
https://www.dietrich-it.de/xtext/uml/iresourceserviceprovider/2011/07/17/xtext-2-0-and-uml.html

dont know if somebody hgas done this before or if there are any open issues.
so feedback would be welcome
Re: Configure single Language Server with multiple grammars (IResourceServiceProvider) [message #1800193 is a reply to message #1800087] Fri, 21 December 2018 03:16 Go to previous message
Eclipse UserFriend
Thanks for your help and links. We'll provide feedback here or in case of any encountered issues on Github.
Previous Topic:Configure single Language Server with multiple grammars (IResourceServiceProvider)
Next Topic:How to add information about relations between entities to the index
Goto Forum:
  


Current Time: Thu Jun 19 00:18:54 EDT 2025

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

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

Back to the top