I've researched this as far as I know how and am stuck wondering if it is even possible. What I would like to do is propose a template that has two cross-referenced variables taking on the familiar form:
Where ref1 points to the container which declares objects that ref2 may point to.
My problem is that I cannot figure out if it is possible to create a variable resolver that resolves template variables on the fly, i.e. while the template is being edited. I want the available candidates to ref2 to be able to refresh after a candidate for ref1 has been chosen from the drop-down. Right now, ref2 contains all possible candidates for ref2, for all possible candidates for ref1 (in other words, everything). I want ref2 to only contain possible candidates for the currently selected candidate for ref1.
Does anyone know if template variable resolvers are capable of this dynamic behavior?
See e.g. this blog entry. It is for Xtext1, but the general infrastructure should not have changed (much).
Note that regular code completion works within variables for arbitrary names, so if your scoping is according to the "container-declaration" semantics you want to capture, the minimal effort variant would be using no template variable resolution in the second case at all. The user has to invoke code completion to see the possibilities, though.
is only called once, when the template is created. I couldn't get it to resolve my variable again while I was editing the template. Also, I would have posted the link to that blog, but the last time I tried to post an outside link, the forum wouldn't let me due to my account privileges.
I like your solution for the time being, except it initially leaves my model file in an invalid state because it inserts a "dummy" variable that still needs to be resolved by code completion. I will continue to investigate and I'll post a cleaner solution if I am able to come up with one.