Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Creating multiple embedded editors with (slightly) specific content assist
Creating multiple embedded editors with (slightly) specific content assist [message #1791617] Tue, 03 July 2018 05:00 Go to next message
Daniel Darvas is currently offline Daniel DarvasFriend
Messages: 10
Registered: July 2014
Junior Member
Hello,

I try to use Xtext-based embedded editors, created with my language's EmbeddedEditorFactory. However, I'd like to slightly specialise the content assist of the different editors, without breaking the behaviour of the non-embedded editor.

My idea was that I can add some fields that are optional to be injected:
class MyLangProposalProvider extends AbstractExprLangProposalProvider {
	@Inject(optional=true)
	public X x;
	...

Then the proposal provider could take the content of x into account if present.
I made sure that X cannot be bound implicitly (doesn't have a parameterless public constructor nor a constructor with @Inject).

Then I create different child injectors for each embedded editor creation, whose module will bind X to specific instances:
Injector parentInjector = MylangActivator.getInstance().getInjector(MylangActivator.MY_LANG_FQN);
Injector injector = parentInjector.createChildInjector(new XModule(...));
EmbeddedEditorFactory editorFactory = injector.getInstance(MylangEmbeddedEditorFactory.class);

...
public static class XModule extends AbstractModule  {
	private final X xInstance;

	public XModule(X xInstance) {
		this.xInstance = xInstance;
	}

	@Override
	public void configure() {
		bind(X.class).toInstance(xInstance);
	}
}


However, this does not work: the IContentProposalProvider is bound to MyLangProposalProvider already in the parentInjector, therefore the parent injector will be used to instantiate MyLangProposalProvider and the optional x will remain null.

Probably my whole direction is wrong and that's why I cannot make it working. Do you have any tips how to be able to provide some information to the embedded editors' content assist proposal providers, specific to each of them?

Thanks,
Daniel Darvas
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791618 is a reply to message #1791617] Tue, 03 July 2018 05:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi did you consider to set custom load options to the resource set or marker adapters to the resourceset or resource?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791619 is a reply to message #1791618] Tue, 03 July 2018 05:26 Go to previous messageGo to next message
Daniel Darvas is currently offline Daniel DarvasFriend
Messages: 10
Registered: July 2014
Junior Member
Thanks a lot, Christian! The first solution works like a charm. Special thanks for the extraordinarily fast answer.

I extended the resource provider (which I created for the embedded editor creation, following the last slides of https://www.slideshare.net/meysholdt/lightweight-xtext-editorsasswtwidgets ) with
...
resourceSet.getLoadOptions().put(X.class, xInstance);
...


Then I can access it in MyLangProposalProvider's complete_* methods via the context:
val X xInstance = context.resource.resourceSet.loadOptions.get(X) as X; // xInstance may be null
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791620 is a reply to message #1791619] Tue, 03 July 2018 05:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
that is not (exactly) what i meant.
i meant to put a flag into the load options
and read that flag from the proposal provider.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791621 is a reply to message #1791620] Tue, 03 July 2018 05:35 Go to previous message
Daniel Darvas is currently offline Daniel DarvasFriend
Messages: 10
Registered: July 2014
Junior Member
Oh, I see. My problem is that practically I want to provide a list of values to be proposed in addition to the default ones. The list is different for each embedded editor and is obtained from an external source thus not known in compilation time.

(I agree, passing data like this in the loadOptions seems like a very hacky solution.)
Previous Topic:Formatting Multiple Consecutive Keywords
Next Topic:Gradle and GeneratorFragment
Goto Forum:
  


Current Time: Fri Mar 29 06:09:26 GMT 2024

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

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

Back to the top