Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Completion proposal with multiple selected regions
Completion proposal with multiple selected regions [message #1384706] Fri, 30 May 2014 15:05 Go to next message
Arne Johanson is currently offline Arne JohansonFriend
Messages: 3
Registered: May 2014
Junior Member
Hi,

for content assist I would like to implement context-sensitive (this prevents using templates.xml) templates with multiple selected regions. So far, I used a ConfigurableCompletionProposal in the following way:
var proposal = (createCompletionProposal("Template content", "Title", null, context) 
                as ConfigurableCompletionProposal)
		
proposal.setSelectionStart(proposal.replacementOffset + 1);
proposal.setSelectionLength(5);
proposal.setSimpleLinkedMode(context.viewer, '\t')
acceptor.accept(proposal)


However, this approach allows only for one selected region. How can I insert multiple selected regions?

All the best
Arne
Re: Completion proposal with multiple selected regions [message #1384742 is a reply to message #1384706] Sat, 31 May 2014 05:56 Go to previous message
Arne Johanson is currently offline Arne JohansonFriend
Messages: 3
Registered: May 2014
Junior Member
I found useful JFace classes to complete the task. This is my helper function to create a template proposal object that can be passed to an Xtext CompletionProposalAcceptor:

def TemplateProposal createTemplateProposal(
	String template,
	String name,
	String description,
	String contextTypeId,
	String icon,
	ContentAssistContext context
) {
	new TemplateProposal(
		new Template(name, description, contextTypeId, template, true),
		new DocumentTemplateContext(
			new TemplateContextType(contextTypeId, name),
			context.document,
			context.offset,
			context.replaceContextLength
		),
		context.replaceRegion,
		loadImage(icon)
	)
}


However, a problem remains: if I use the ${cursor} variable to specify the location for the caret after editing, the word "cursor" is actually printed in the content proposal (but otherwise ${cursor} works as intended). Any suggestions why this is the case?

Besides this last question, I would really like to see Xtext-specific abstractions for this task (so that you don't have to fiddle around with JFace classes that -- at least to me -- don't seem to integrate well with the Xtext abstractions (why should I know something about TemplateContextTypes?)).

Cheers
Arne
Previous Topic:the formatter and modification in a unit of work
Next Topic:Cannot reference elements in other files using xtext editor in papyrus
Goto Forum:
  


Current Time: Sat Apr 20 03:55:39 GMT 2024

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

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

Back to the top