Using XText, is there a way to have text added with a content proposal to match the formatting (current indentation) where it is being inserted?
What I do now:
1) Create a model that will be used for content proposal
2) I get the content proposal string with:
EObject myelement
is generated code that can be inserted into my Xtext document.
class MyContentProposalProvider extends AbstractContentProposalProvider
{
private void acceptProposal(
ContentAssistContext context,
ICompletionProposalAcceptor acceptor,
ElementContentProposal contentProposal,
EObject myElement) {
final String proposalString = context.getResource().getSerializer().serialize(myElement);
final String proposalDisplayCode = proposalString.replaceAll("(\\r|\\n)", "");
final ICompletionProposal completionProposal = createCompletionProposal(proposalString,
String.format("%s : %s", proposalDisplayCode, p.getDescription()), null,
context);
acceptor.accept(completionProposal);
}
}
3) Select a proposal in the Xtext Editor.
4) The indentation is way off. Everything goes to the left.
5) So far, the only way I see to solve this is to format the entire document after a proposal; however, this may have unwanted side effects.
Is there any way to keep the proposal string generated above to have indentation consistent with the context in which it is proposed? (this means, keeping indentation settings from preferences, such as spaces instead of tabs).