Skip to main content



      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 08:46 Go to next message
Eclipse UserFriend
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 08:51 Go to previous messageGo to next message
Eclipse UserFriend
please provide a complete example and reproduction steps
Re: Content Assist Problem in the second Grammar [message #1800975 is a reply to message #1800973] Thu, 10 January 2019 09:04 Go to previous messageGo to next message
Eclipse UserFriend
did you analyse why entry point is null? and how do you test?
Re: Content Assist Problem in the second Grammar [message #1800980 is a reply to message #1800975] Thu, 10 January 2019 10:04 Go to previous messageGo to next message
Eclipse UserFriend
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 11:41 Go to previous messageGo to next message
Eclipse UserFriend
@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 11:43] by Moderator

Re: Content Assist Problem in the second Grammar [message #1801053 is a reply to message #1801049] Fri, 11 January 2019 12:21 Go to previous messageGo to next message
Eclipse UserFriend
i dont see any server calls for person dsl
Re: Content Assist Problem in the second Grammar [message #1801055 is a reply to message #1801053] Fri, 11 January 2019 12:33 Go to previous messageGo to next message
Eclipse UserFriend
can you please open a bug at github.com/eclipse/xtext-core.
i see the problem here BaseContentAssistParser.getFollowElements

[Updated on: Fri, 11 January 2019 12:34] by Moderator

Re: Content Assist Problem in the second Grammar [message #1801056 is a reply to message #1801055] Fri, 11 January 2019 12:42 Go to previous messageGo to next message
Eclipse UserFriend
=> imho the problem is the loading of grammars from xtextbin files, person grammar is loaded twice

[Updated on: Fri, 11 January 2019 12:56] by Moderator

Re: Content Assist Problem in the second Grammar [message #1801062 is a reply to message #1801055] Fri, 11 January 2019 14:24 Go to previous messageGo to next message
Eclipse UserFriend
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 14:44 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Content Assist Problem in the second Grammar [message #1801067 is a reply to message #1801066] Fri, 11 January 2019 15:12 Go to previous messageGo to next message
Eclipse UserFriend
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 15:15] by Moderator

Re: Content Assist Problem in the second Grammar [message #1801068 is a reply to message #1801067] Fri, 11 January 2019 15:25 Go to previous messageGo to next message
Eclipse UserFriend
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 06:34 Go to previous message
Eclipse UserFriend
https://github.com/eclipse/xtext-core/issues/993
Previous Topic:XtextRunner and Parser class issue
Next Topic:xtend-maven plugin does not work in 2.12.0 release
Goto Forum:
  


Current Time: Sat Jun 14 01:49:07 EDT 2025

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

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

Back to the top