Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext web content proposal(How to create custom proposals?)
Xtext web content proposal [message #1745739] Sun, 16 October 2016 20:40 Go to next message
Daniel B. is currently offline Daniel B.Friend
Messages: 4
Registered: September 2016
Junior Member
Hi,

I have some trouble understanding how I can create custom content proposals.

Let's assume I have an array with some strings I want to propose as content within a specific grammar rule.
I would think that I need to write a new method that handles the proposals for that specific rule.
A subclass of IdeContentProposalProvider with the createProposals method for my rule would be needed and I would bind it in my web module. (As stated in this thread )

To get a better understanding I also had a look at the example linked. (https://github.com/eclipse/xtext/blob/v2.9.0/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/contentassist/IdeContentProposalProvider.xtend )

The first thing I have noticed is that the parameters of the method mentioned in the thread is totally different from those in the example. Therefore I am very unsure how I can access the rules within the createProposals method.


To sum my question up:
Could someone please give me a full example of the subclass of IdeContentProposalProvider for a grammar:
Model:
    elements+=Element;

Element:
    (foo=Foo | bar=Bar);

Bar:
    '-->'text=ID'<--';

If I want to propose one of the following Strings within the arrows of the rule Bar.
["FooBar", "Test", "Example"]


An example would surely help me understanding the process of providing the proposals.

Thank you.
Re: Xtext web content proposal [message #1745743 is a reply to message #1745739] Mon, 17 October 2016 03:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
hi, i cannot really follow you. here is one of 10000 possible impls

package org.xtext.example.mydsl.ide

import java.util.Collection
import javax.inject.Inject
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.xtext.example.mydsl.services.MyDslGrammarAccess

class MyDslIdeProposalProvider extends IdeContentProposalProvider {
	
	@Inject
	MyDslGrammarAccess ga
	
	override createProposals(Collection<ContentAssistContext> contexts, IIdeContentProposalAcceptor acceptor) {
		super.createProposals(contexts, acceptor)
		for (context : contexts) {
			for (ge : context.firstSetGrammarElements) {
				if (ga.barAccess.textAssignment_1 == ge) {
					for (element : #["FooBar", "Test", "Example"].filter[startsWith(context.prefix)]) {
						val entry = proposalCreator.createProposal(element, context)
						val prio = proposalPriorities.getDefaultPriority(entry)
						acceptor.accept(entry, prio)
					}
				}
			}
		}
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext web content proposal [message #1745744 is a reply to message #1745743] Mon, 17 October 2016 03:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
p.s. and yes you could override

org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider.createProposals(AbstractElement, ContentAssistContext, IIdeContentProposalAcceptor)

or

_createProposals(Assignment assignment, ContentAssistContext context, IIdeContentProposalAcceptor acceptor)

or



org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider._createProposals(RuleCall, ContentAssistContext, IIdeContentProposalAcceptor)


or one of the other _createProposals methods
as well


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 17 October 2016 03:51]

Report message to a moderator

Re: Xtext web content proposal [message #1745876 is a reply to message #1745744] Tue, 18 October 2016 16:54 Go to previous messageGo to next message
Daniel B. is currently offline Daniel B.Friend
Messages: 4
Registered: September 2016
Junior Member
Maybe I understood the concept totally wrong.

If I try to use your example I get errors compiling the files. I can't either import the GrammarAccess nor is the proposalCreator defined.

If I search within the project for my GrammarAccess I can find it imported in other files using the same URI without any problems. Somehow the problem just occurs within the ProposalProvider subclass.

Where should I find the proposalCreator or the method createProposal? No hits within my project. Just createProposals is found and even that just in my MyDslIdeProposalProvider.
Re: Xtext web content proposal [message #1745877 is a reply to message #1745876] Tue, 18 October 2016 17:26 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
Can you please share the / a reproducing project

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:One file extension for different plug-ins?
Next Topic:How to generate code from Xbase expressions
Goto Forum:
  


Current Time: Mon Apr 12 16:33:46 GMT 2021

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

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

Back to the top