Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content Assist Problem in the second Grammar
Content Assist Problem in the second Grammar [message #1800972] Thu, 10 January 2019 13:46 Go to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
I have two XText Grammars (Grammar1 and Grammar2) and the following mwe2 workflow

Workflow {


	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "base"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				genericIde = {
					enabled = true
				}
				mavenLayout = true
			}
			code = {
				encoding = "UTF-8"
				lineDelimiter = "\n"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}

		/* Custom `XtextGeneratorLanguage` instead of StandardLanguage:
		 * - omit `GeneratorFragment2` because custom generators are used
		 * - omit unnecessary IDE fragments
		 */
		language = XtextGeneratorLanguage {
			grammarUri = grammar1.xtext
			name = "org.xtext.grammar1"
			fileExtensions = "grammar1"
			referencedResource = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
			fragment = grammarAccess.GrammarAccessFragment2 {}
			fragment = ecore.EMFGeneratorFragment2 {}
			fragment = serializer.SerializerFragment2 {}
			fragment = resourceFactory.ResourceFactoryFragment2 {}
			fragment = parser.antlr.XtextAntlrGeneratorFragment2 {}
			fragment = validation.ValidatorFragment2 {}
			fragment = scoping.ImportNamespacesScopingFragment2 {}
			fragment = index.ResourceDescriptionStrategyFragment {}
			fragment = exporting.QualifiedNamesFragment2 {}
			fragment = builder.BuilderIntegrationFragment2 {}
			fragment = formatting.Formatter2Fragment2 {}
			fragment = ui.labeling.LabelProviderFragment2 {}
			fragment = ui.outline.QuickOutlineFragment2 {}
			fragment = ui.outline.OutlineTreeProviderFragment2 {}
			fragment = ui.quickfix.QuickfixProviderFragment2 {}
			fragment = ui.contentAssist.ContentAssistFragment2 {}
			fragment = junit.JUnitFragment {}
			fragment = ui.refactoring.RefactorElementNameFragment2 {}
			fragment = ui.templates.CodetemplatesGeneratorFragment2 {}
			fragment = types.TypesGeneratorFragment2 {}
			fragment = xbase.XtypeGeneratorFragment2 {}
    		fragment = xbase.XbaseGeneratorFragment2 {}
			fragment = ui.compare.CompareFragment2 {}
		}

		language = XtextGeneratorLanguage {
			grammarUri = grammarURI
			referencedResource = "platform:/resource/org/xtext/grammar1.xtext"
			name = "org.xtext.grammar2"
			fileExtensions = "grammar2"
			referencedResource = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
			fragment = grammarAccess.GrammarAccessFragment2 {}
			fragment = ecore.EMFGeneratorFragment2 {}
			fragment = serializer.SerializerFragment2 {}
			fragment = resourceFactory.ResourceFactoryFragment2 {}
			fragment = parser.antlr.XtextAntlrGeneratorFragment2 {}
			fragment = validation.ValidatorFragment2 {
				inheritImplementation = false
			}
			fragment = scoping.ImportNamespacesScopingFragment2 {
				generateXtendStub = false
			}
			fragment = index.ResourceDescriptionStrategyFragment {}
			fragment = exporting.QualifiedNamesFragment2 {}
			fragment = builder.BuilderIntegrationFragment2 {}
			fragment = formatting.Formatter2Fragment2 {}
			fragment = ui.labeling.LabelProviderFragment2 {}
			fragment = ui.outline.QuickOutlineFragment2 {}
			fragment = ui.outline.OutlineTreeProviderFragment2 {}
			fragment = ui.quickfix.QuickfixProviderFragment2 {}
			fragment = xbase.XtypeGeneratorFragment2 {}
    		fragment = xbase.XbaseGeneratorFragment2 {}
			fragment = ui.contentAssist.ContentAssistFragment2 {}
			fragment = junit.JUnitFragment {}
			fragment = ui.refactoring.RefactorElementNameFragment2 {}
			fragment = ui.templates.CodetemplatesGeneratorFragment2 {}
			fragment = ui.compare.CompareFragment2 {}
			fragment = types.TypesGeneratorFragment2 {}
		}
	}
}





The Content Assist for Grammar2 is working, but Content Assist for Grammar1 is not working.

After debugging, I realized that the entryPoint in the XTextResource Representing the first grammar is null. That is why content assist fails.
More specifically, this is where the two grammars differ in term of content assist:

This code is from org.eclipse.xtext.resource.XTextResource
	public ParserRule getEntryPoint() {
		if (entryPoint == null && parseResult != null) {
			entryPoint = NodeModelUtils.getEntryParserRule(parseResult.getRootNode());
		}
		return entryPoint;
	}
	


for the grammar1, the entryPoint is null and so XText resource creates a new one, however, it doesn't match the first rule in the ruleSet, so contentAssist fails
for grammar2, the entryPoint is never null, so content assist always works

I realize that this has been a rather too technical question, but perhaps I am missing something obvious here, why is the entryPoint of the XTextResource representing Grammar1 null?
Re: Content Assist Problem in the second Grammar [message #1800973 is a reply to message #1800972] Thu, 10 January 2019 13:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
please provide a complete example and reproduction steps

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist Problem in the second Grammar [message #1800975 is a reply to message #1800973] Thu, 10 January 2019 14:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
did you analyse why entry point is null? and how do you test?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist Problem in the second Grammar [message #1800980 is a reply to message #1800975] Thu, 10 January 2019 15:04 Go to previous messageGo to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
I will provide a complete example
Re: Content Assist Problem in the second Grammar [message #1801049 is a reply to message #1800980] Fri, 11 January 2019 16:41 Go to previous messageGo to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
@Christian
I now created a very simple project with the exact problem. There are two very simple grammars house and person

Reproduction steps
1) checkout the project => git clone git@github.com:Mehmetcanss/example_xtext_language_server_vscode.git (Repository url: https://github.com/Mehmetcanss/example_xtext_language_server_vscode)
2) change directory to parent folder => cd example_xtext_language_server_vscode/org.xtext.example.mydsl.parent/
3) generate xtext artifacts and build the language server => ./gradlew clean org.xtext.example.mydsl.vscode:installLanguageServerDist
4) Open a visual studio code instance, contest assist works for the house grammar but not for the person grammar.
5) You can use the RunServer class at the ide project to debug

[Updated on: Fri, 11 January 2019 16:43]

Report message to a moderator

Re: Content Assist Problem in the second Grammar [message #1801053 is a reply to message #1801049] Fri, 11 January 2019 17:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i dont see any server calls for person dsl

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist Problem in the second Grammar [message #1801055 is a reply to message #1801053] Fri, 11 January 2019 17:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you please open a bug at github.com/eclipse/xtext-core.
i see the problem here BaseContentAssistParser.getFollowElements


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 11 January 2019 17:34]

Report message to a moderator

Re: Content Assist Problem in the second Grammar [message #1801056 is a reply to message #1801055] Fri, 11 January 2019 17:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
=> imho the problem is the loading of grammars from xtextbin files, person grammar is loaded twice

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 11 January 2019 17:56]

Report message to a moderator

Re: Content Assist Problem in the second Grammar [message #1801062 is a reply to message #1801055] Fri, 11 January 2019 19:24 Go to previous messageGo to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
Thanks for having a look

Yes I know the problem is the BaseContentAssistParser getFollowElements (the searched rule is not in the list of allRules)

And I also think that the grammar is loaded twice

but any ideas how I can overcome this problem in the mean time?

This seems to only happen if one grammar uses the other?

I will open a bug, but a practical workaround would be really appreciated .
Re: Content Assist Problem in the second Grammar [message #1801066 is a reply to message #1801062] Fri, 11 January 2019 19:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you try to comment out the personsetup call in org.xtext.example.mydsl.HouseStandaloneSetupGenerated.createInjectorAndDoEMFRegistration()
and debug via runserver and see if anything breaks? ca seems to work then.
am not sure about bad sideeffects


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist Problem in the second Grammar [message #1801067 is a reply to message #1801066] Fri, 11 January 2019 20:12 Go to previous messageGo to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
IT works! Thanks alot!!!! That has been very helpful.
There doesn't seem to be any side effects. Validation is still working. Everything seems to work. Debug doesn't show anything.
The XTextServiceLoader already calls createInjectorAndDoEmfReg for all ISetup Classes in the ISetup File. So the required doSetups are already called for every grammar.
So a second call inside the HouseStandAloneSetup loads the person grammar a second time by calling doSetup.

This is an XText bug and probably needs to be fixed with version 2.17=)

Thanks again

[Updated on: Fri, 11 January 2019 20:15]

Report message to a moderator

Re: Content Assist Problem in the second Grammar [message #1801068 is a reply to message #1801067] Fri, 11 January 2019 20:25 Go to previous messageGo to next message
Mehmetcan Sinir is currently offline Mehmetcan SinirFriend
Messages: 55
Registered: September 2018
Member
I will create an issue on Monday
Re: Content Assist Problem in the second Grammar [message #1801403 is a reply to message #1801068] Fri, 18 January 2019 11:34 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
https://github.com/eclipse/xtext-core/issues/993

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XtextRunner and Parser class issue
Next Topic:xtend-maven plugin does not work in 2.12.0 release
Goto Forum:
  


Current Time: Thu Mar 28 16:50:02 GMT 2024

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

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

Back to the top