Completion proposal with multiple selected regions [message #1384706] |
Fri, 30 May 2014 11:05  |
Eclipse User |
|
|
|
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 01:56  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03086 seconds