Skip to main content



      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 01:00 Go to next message
Eclipse UserFriend
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 01:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi did you consider to set custom load options to the resource set or marker adapters to the resourceset or resource?
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791619 is a reply to message #1791618] Tue, 03 July 2018 01:26 Go to previous messageGo to next message
Eclipse UserFriend
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 01:30 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Creating multiple embedded editors with (slightly) specific content assist [message #1791621 is a reply to message #1791620] Tue, 03 July 2018 01:35 Go to previous message
Eclipse UserFriend
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: Thu Jun 19 06:06:11 EDT 2025

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

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

Back to the top