Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cross Referenced Objects not initialized in ProposalProvider
Cross Referenced Objects not initialized in ProposalProvider [message #1839429] Sun, 21 March 2021 05:07 Go to next message
Eclipse UserFriend
I have been trying to restrict content assist as described in:

http://xtextcasts.org/episodes/17-restricting-scope?autoplay=true

It works perfectly fine, if I am in the same file. As soon as I start to place the "byes" into another file the greetings have no properties set (name = null and honest = false).

Grammar
Model:
	greetings+=Greeting*
	byes+=Bye*;
	
Greeting:
	'Hello' name=ID honest?='!'?;
	
Bye:
	'Bye' greeting=[Greeting]
;


ProposalProvider
	public void completeBye_Greeting(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		lookupCrossReference(model, FooDslPackage.Literals.BYE__GREETING, acceptor, e -> {
			Greeting greeting = (Greeting) e.getEObjectOrProxy();
			// greeting.name is also null, honest always false if placed in another file
			return greeting.isHonest();
		}, getProposalFactory("ID", context));
	}


What am I missing?!

I am using Xtext 2.24.0 and EMF 2.24.
Re: Cross Referenced Objects not initialized in ProposalProvider [message #1839430 is a reply to message #1839429] Sun, 21 March 2021 05:14 Go to previous messageGo to next message
Eclipse UserFriend
For the other files you just have the index entries there and thus Proxies
So you have two options
Add more information to the userdata map of the index entries (adapting IDefaultResourceDescriptionStrategy) And then us the userdata to filter in the proposal provider
Or resolve the Proxies in the context of the given context eobjects resource(set) (see ECoreUtil.resolve methods) but this will become terribly slow with bigger models
Re: Cross Referenced Objects not initialized in ProposalProvider [message #1839434 is a reply to message #1839430] Sun, 21 March 2021 07:15 Go to previous message
Eclipse UserFriend
I see. It does not really make sense to access properties of EObjectOrProxy for any real world DSL. There should be a big warning in the Javadoc regarding this point.

Adding the "honest" flag to the user data in the index solved my issue.

Wouldn't this topic (liberal scoping, using proposalprovider + validator and user data map in the index) deserve a place in the Xtext documentation? I find a single reference to "user data" in the documentation without pointing out why one would want to add additional information to the index.
Previous Topic:Grammar ambiguity
Next Topic:Index User Data
Goto Forum:
  


Current Time: Wed Jul 23 16:35:29 EDT 2025

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

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

Back to the top