Add completion contributor on Xml language



I want to create a project to integrate some Odoo framework specificity to pyCharm.

My first Step is to add some autocompletion in Xml File.

For that I read the tutoriel and I create a SimpleCompletionContributor

the code below :


But when I try this I see my Completion contributor but when I press <ENTER> That Only display id and not id="value"

see below

So my question is :

What I am doing wrong ?

Official comment

You're doing nothing wrong, you're just calling LookupElementBuilder.create(PsiNamedElement) which adds element.getName() ("id") as the presentable lookup text. You can override that by adding a ookupElementBuilder#withPresentableTex call.

Because it also inserts the result of getName(). You can use LookupElementBuilder.create("id=\"value\""), then both presentable and inserted texts will be as you wish.


Thanks a lot.

but then I have a another question.

why when I press <ENTRER> the completion just had 'id' and not 'id="value" ?


Ok, thanks a lot, but I have one last question.

How can I put my cursor between " ?

sample : id="<cursor here>"

and not : id=""<cursor here>



You can call LookupElementBuilder.withInsertHandler and pass a class there that does just any modifications to the document or editor as you like. In this case, you'd need editor.getCaretModel().moveToOffset(context.getTailOffset() - 1)


Thank you very much !!!

May be soon on another topic :-)


Please sign in to leave a comment.