XText project migrating from Eclipse to LSP : No ContentAssist working [message #1848471] |
Fri, 03 December 2021 05:39  |
Eclipse User |
|
|
|
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 #1848635 is a reply to message #1848477] |
Fri, 10 December 2021 06:06  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03768 seconds