Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText project migrating from Eclipse to LSP : No ContentAssist working(Unable to make the completion work on a XText project using LSP)
XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848471] Fri, 03 December 2021 10:39 Go to next message
Arthur Daussy is currently offline Arthur DaussyFriend
Messages: 14
Registered: September 2014
Junior Member
Hello Everyone,

I've got an existing Xtext grammar and now I'm trying to use it in VSCode through the Xtext LSP integration.

I have looked into sample projects (https://github.com/itemis/xtext-languageserver-example and https://github.com/TypeFox/vscode-xtext-sprotty-example) to check how it was done.
I think that I have done the same operations. That is to say:

* Register in my IDEModule my own implementation of IdeContentProposalProvider
* Build it using appassembler-maven-plugin to get the bin/ and lib/ folder
* Deployed in my VSCode extension to deploy a self contained extension.

But the completion is not working (whereas the validation works fine). Do you have any leads that would help me on that matter?

Here are some more information. I started to debug the completion request up to org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createProposals(String, TextRegion, int, XtextResource, IIdeContentProposalAcceptor).
I noticed the context array is empty. So I track the context creation up to _org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeIsAtEndOfDatatypeNode()_ and noticed that my parser fails to _getFollowElements(InternalParser parser, AbstractRule rule)_. Going deeper, I noticed that the problem is coming from _org.eclipse.xtext.xtext.RuleNames.getAntlrRuleName(AbstractRule)_ because _antlrNameToRule_ map contains a different instance of the rule I was looking for. So I searched how this can happen and notices that my Grammar object is instantiated twice even if it contains the @Singleton annotation. Now I stuck trying to understand how this can happen. Would you have any leads that I can look into?

The only specific aspect of my project is that the main project (plugin) defines 2 different languages (A and B) and B is referencing A. I was wondering if it could be the problem.

Here are the version I use:

* Xtext 2.25
* LSP4J 0.10.0
* VSCode 1.62.2
* Java 11

Regards,

Thanks for your help
Re: XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848472 is a reply to message #1848471] Fri, 03 December 2021 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14255
Registered: July 2009
Senior Member
do you have multiple dsls involved inheriting / referncing from each other?
https://github.com/eclipse/xtext-core/issues/993


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 03 December 2021 11:36]

Report message to a moderator

Re: XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848476 is a reply to message #1848472] Fri, 03 December 2021 14:40 Go to previous messageGo to next message
Arthur Daussy is currently offline Arthur DaussyFriend
Messages: 14
Registered: September 2014
Junior Member
Yes, it looks exactly like that.

Thanks to your post, I have read the ticket but not sure I understand the problem correctly.
Let me rephrase to be sure I understand correctly.
My problem is that my Language B relies on Language A and both create their own injector. Since there are two injectors, the @Singleton annotation on the AGrammarAccess does not work and the class is instantiated twice.

I need to keep the Eclipse version working so I would like to avoid modifying the setups used in this version. So if customize the _ResourceServiceProviderServiceLoader_ by providing my own custom _ServerModule_ to remove all setups except one new big setup to register all required modules and create only one injector it could work?
Re: XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848477 is a reply to message #1848476] Fri, 03 December 2021 14:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14255
Registered: July 2009
Senior Member
the idesetups are not used in eclipse

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848635 is a reply to message #1848477] Fri, 10 December 2021 11:06 Go to previous message
Arthur Daussy is currently offline Arthur DaussyFriend
Messages: 14
Registered: September 2014
Junior Member
Yes, that is true.

I have to admit that I had trouble to understand the workaround described in the ticket at first. But I think that I have found an implementation now (using the ideas from the tickets thanks again). Here is the detail:

* Makes sure that BIdeSetUp is registered after AIdeSetUp in the service declaration
* Customize AIdeSetUp to make its injector is publicly and statically available (I'm not really proud of that part but could not figure out how to do better)

class AIdeSetup extends AStandaloneSetup {
	
	/*
	 * Workaround for bug https://github.com/eclipse/xtext-core/issues/993 due to language dependency from B to A. See https://www.eclipse.org/forums/index.php/m/1848471/ for more details
	 */
	public static Injector injector;

	override createInjector() {
		injector = Guice.createInjector(Modules2.mixin(new ARuntimeModule, new AIdeModule))
		return injector;
	}
}


* Customize BIdeModuleSetup to avoid initializing A through the AStandaloneSetup.doSetup(); methods
class BIdeSetup extends BStandaloneSetup {
	override createInjector() {
		Guice.createInjector(Modules2.mixin(new BRuntimeModule, new BIdeModule))
	}

	override Injector createInjectorAndDoEMFRegistration() {

		// The normal implementation initialize the sub grammar but it causes problem see the following link for more details
		// * https://github.com/eclipse/xtext-core/issues/993
		// * https://www.eclipse.org/forums/index.php/m/1848471/
		// Instead we rely on the fact that A has already been initialized and use its injector to retrieve the GrammarAccess
		var Injector injector = createInjector
		register(injector)
		return injector
	}
}


* Customize BIdeModule to confiure the binder so it configure the injector to retreive the AGrammarAccess from the Injector available in AIdeSetup

class BIdeModule extends AbstractBIdeModule
{
	
	override configure(Binder binder) {
		super.configure(binder)
		binder.bind(AGrammarAccess).toProvider([AIdeSetup.injector.getInstance(AGrammarAccess)])
	}
	
}




With that the completion is working now but I'm not sure that this workaround covers all the use cases. Do you see any problem it might cause?

Regards,

Arthur
Previous Topic:Compile into Native using GraalVM
Next Topic:How can I transform an xtext dsl file to xml?
Goto Forum:
  


Current Time: Tue May 17 19:10:41 GMT 2022

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

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

Back to the top