Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Code assist for DataType rules
Code assist for DataType rules [message #1779847] Sun, 14 January 2018 16:07 Go to next message
Pent Down is currently offline Pent DownFriend
Messages: 4
Registered: January 2018
Junior Member
Hello,
I would like to get some help regarding this problem:

I have a data type rule like this (unit of measure) with a Value converter etc..
A valid value would be ex: 200 mm

UomLength returns UomLength:
INT STRING
;

I need to get the code assist popup after I type the integer value. The code assist has to show the units available.

I can only get the popup for the whole thing only, not the integer.
Still is reasonable, I can suggest "0 mm" and jump the cursor but I am asking if it's possible

Thanks and Regards,
PD
Re: Code assist for DataType rules [message #1779849 is a reply to message #1779847] Sun, 14 January 2018 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11743
Registered: July 2009
Senior Member
i am not sure if a datatype rule is very good here cause error recovery / context calculation might be bad.

you may try to play around with

UomLength returns UomLength:
INT ID
;


class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override complete_UomLength(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.complete_UomLength(model, ruleCall, context, acceptor)
		if (context.prefix.isEmpty) {
			acceptor.accept(createCompletionProposal("1", context))
		} else if (context.prefix.endsWith(" ")) {
			acceptor.accept(createCompletionProposal(context.prefix+"mm", context))
		} else {
			acceptor.accept(createCompletionProposal(context.prefix+" mm", context))
		}  
	}
	
	@Inject MyDslGrammarAccess ga
	
	override complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		if (ruleCall === ga.uomLengthAccess.IDTerminalRuleCall_1) {
			acceptor.accept(createCompletionProposal("mm", context))
		}
		super.complete_ID(model, ruleCall, context, acceptor)
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Code assist for DataType rules [message #1779866 is a reply to message #1779849] Mon, 15 January 2018 05:34 Go to previous message
Pent Down is currently offline Pent DownFriend
Messages: 4
Registered: January 2018
Junior Member
Great is works !
Thanks you very much (again)
Previous Topic:cross-project references not resolved in standalone mode
Next Topic:Build fails after upgrading to xtext 2.13.0
Goto Forum:
  


Current Time: Sat Feb 24 16:51:41 GMT 2018

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

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