Add completion contributor on Xml language

Answered

Hello,

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 ?

6 comments
Comment actions Permalink
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.

Comment actions Permalink

Thanks a lot.

but then I have a another question.

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

0
Comment actions Permalink

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.

1
Comment actions Permalink

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>

 

0
Comment actions Permalink

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)

0
Comment actions Permalink

Thank you very much !!!

May be soon on another topic :-)

0

Please sign in to leave a comment.