Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom Content Assist in Xtext(Help in customizing own content assist)
Custom Content Assist in Xtext [message #1724033] Sat, 20 February 2016 05:33 Go to next message
Han Li Koay is currently offline Han Li KoayFriend
Messages: 25
Registered: February 2016
Junior Member
Hi,

I wanted to customize the content assist for argType where it can give different options depending on the command. (For example, if command "create" is typed, only "file, folder, ..." is shown for argType in the content assist)

Below is my grammar:
Model:
command+=Commands;

Commands:
	command= ('create'|'close'|'open'|'copy');
	name = ID
        "{"
	argtlist+=Arg*			
        "}"	
;
	
Arg:
        argType = ID
	argName = STRING
;

The outcome i wanted will look something like this:
create testing {
        file "File1"  //only argType file and folder is shown in content assist       
        folder "Folder"    //only argType file and folder is shown in content assist       
}

Is it possible to achieve something like that in content assist?
Thanks in advanced for any guidance!
Re: Custom Content Assist in Xtext [message #1724037 is a reply to message #1724033] Sat, 20 February 2016 06:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi have a look at http://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist


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: Custom Content Assist in Xtext [message #1724043 is a reply to message #1724037] Sat, 20 February 2016 07:41 Go to previous messageGo to next message
Han Li Koay is currently offline Han Li KoayFriend
Messages: 25
Registered: February 2016
Junior Member
Hi Christian,

Thanks for replying.
I did looked into that and i know how to implement code completion for argType. But what i do not know is how to get the current command value from Commands Type so i could provide different groups of proposal for different commands value.
Re: Custom Content Assist in Xtext [message #1724045 is a reply to message #1724043] Sat, 20 February 2016 07:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
the parameters give you access to the "model" / ast. use that to navigate and investigate

class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override completeArg_ArgType(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		val commands = EcoreUtil2.getContainerOfType(model, Commands)
		if (commands != null) {
			println(commands.command)
		}
	}
	
}



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: Custom Content Assist in Xtext [message #1724110 is a reply to message #1724045] Sun, 21 February 2016 02:22 Go to previous message
Han Li Koay is currently offline Han Li KoayFriend
Messages: 25
Registered: February 2016
Junior Member
Thanks Christian!
Your code works perfectly!! Smile
Previous Topic:Multiple icons for single entry in outline view
Next Topic:Disable language support for project
Goto Forum:
  


Current Time: Mon Sep 20 00:07:05 GMT 2021

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

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

Back to the top