Skip to main content



      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 00:33 Go to next message
Eclipse UserFriend
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 01:12 Go to previous messageGo to next message
Eclipse UserFriend
Hi have a look at http://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist
Re: Custom Content Assist in Xtext [message #1724043 is a reply to message #1724037] Sat, 20 February 2016 02:41 Go to previous messageGo to next message
Eclipse UserFriend
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 02:48 Go to previous messageGo to next message
Eclipse UserFriend
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)
		}
	}
	
}

Re: Custom Content Assist in Xtext [message #1724110 is a reply to message #1724045] Sat, 20 February 2016 21:22 Go to previous message
Eclipse UserFriend
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: Tue Jul 15 04:53:33 EDT 2025

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

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

Back to the top