Search code examples
eclipse-rcpeclipse-jdtcontent-assist

Eclipse RCP: How to Format a Content Assist Proposal while it's being applied


I've implemented content assist in my RCP app, but I can't figure out how to make the completion proposal work like the JDT content assist capability when it's applied in the document. Specifically, when you select a Java completion proposal and apply it, it has appearance and focus behavior that lets you edit it before accepting it. There are thin borders drawn around each parameter, and you can tab through the method arguments and the text of the next argument is automatically selected when you do so. There is lots of information on implementing content assist on the web, but I can't find anything that addresses how to do this.


Solution

  • Thanks to greg-449 for pointing me to JFace templates. I reviewed the API for the classes in org.eclipse.jface.text.templates per his comment. Seemed like a good approach, though certainly not trivial, as he alluded.

    However, I found a simpler solution in the PyDev code (which my app is extending). PyLinkedModeCompletionProposal does something similar to what I want, so I copied that class and modified it as needed. (I just have a different template pattern.)

    The implementation in PyLinkedModeCompletionProposal#goToLinkedMode uses the JFace classes LinkedModeModel, EditorLinkedModeUI, and ProposalPosition to place completion proposals in the editor as an editable template.