PsiReference and completion

hi
i am working on a plugin that deal with xml config file,and now i am investigating how to implement completion
as Dmitry adviced me ,i used a custom PsiReference for my element and registered it through a PsiReferenceProvider with a ReferenceProviderRegistry
and all works fine ,the referenceProvider registered and get called But the problem is my custom reference.getVarient which return the completion array NEVER called and i donot know why,so please help

some questions:
what does PsiReference.getCanonicalText do ?
second if i have the following
andi registered three PsiReference implementations For XmlTag, XmlAttribute, XmlAttributeValue ,which one's getVarient will be called upon Ctrl-Space in the following locations a- after the < b- after i type

9 comments


hi

getCanonicalText()
Returns the name of the reference target element which does not depend on import statements and other context (for example, the full-qualified
name of the class if the reference targets a Java class).

What do you return from the getRangeInElement() method in your reference?
Because you HAVE to return something valid in order to have resolve and i think getVariants too working

hi
i am working on a plugin that deal with xml config file,and now i am investigating how to implement completion
as Dmitry adviced me ,i used a custom PsiReference for my element and registered it through a PsiReferenceProvider with a ReferenceProviderRegistry
and all works fine ,the referenceProvider registered and get called But the problem is my custom reference.getVarient which return the completion array NEVER called and i donot know why,so please help

some questions:
what does PsiReference.getCanonicalText do ?
second if i have the following
<tag attr="value">
andi registered three PsiReference implementations For XmlTag, XmlAttribute, XmlAttributeValue ,which one's getVarient will be called upon Ctrl-Space in the following locations
a- after the <
b- afterr i type <t
c- after typing <tag
d- after typing <tag a
e- after typing <tag attr
f- after typing <tag attr=
g- after typing <tag attr="

ok i know that this is a lenthy question but it will be a very helpfull resource to developers in the future
thanx
joe

0

in getRangeInElement i return element.getRange
and i get element (PsiElement) passed from the ReferenceProvider and it is for sure not null and it is of type XML_ATTRIBUTE_VALUE

actually i registered AttributeValueReference with some attribute names and it work correctly(my reference used only if i type these attributes) but getVarients never called

0


well, as far as i know, idea inserts some identifier at the current cursor position in file
then parsers this fragment thus obtaining a psielement that corresponds to this dummy identifier.
then it calls this element's getReference().getVariants() method and gets rid of the dummy.

so here
<
and here
<t
getVariants would be called at a reference from xmlTag

after you type a whitespace getVariants would come from xmlAttribute
and after the quote - xmlAttributeValue


Could it be that your reference is registered only for some particular attribute, so it works when it is typed
but when you are typing it does not?


in getRangeInElement i return element.getRange
and i get element (PsiElement) passed from the ReferenceProvider and it is for sure not null and it is of type XML_ATTRIBUTE_VALUE

actually i registered AttributeValueReference with some attribute names and it work correctly(my reference used only if i type these attributes) but getVarients never called

0

hi
ok,as u suggest ,the error was with getRangeInElement and when i properly implement it completion works BUT there is another problem
the whole attribute value is highlighted in red as it is an error WHY
what make idea think that this is inappropriate value

0

Hello joe,

j> ok,as u suggest ,the error was with getRangeInElement and when i
j> properly implement it completion works BUT there is another problem
j>
j> the whole attribute value is highlighted in red as it is an error WHY
j>
j> what make idea think that this is inappropriate value

Most likely you return null from PsiReference.resolve(), and IDEA highlights
the unresolved reference as an error. You should return true from isSoft().

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

completion is working for attribute value which is registered with
registry.registerXmlAttributeValueReferenceProvider
BUT the Attribute provider which is registered as
registry.registerReferenceProvider(XmlAttribute.class,new XmlAttributeRefProvider());
NEVER CALLED or even constructed
nothing happen when i press Ctrl_Space after <tag
WHY?
joe

0

Hello joe,

j> completion is working for attribute value which is registered with
j> registry.registerXmlAttributeValueReferenceProvider
j> BUT the Attribute provider which is registered as
j> registry.registerReferenceProvider(XmlAttribute.class,new
j> XmlAttributeRefProvider());
j> NEVER CALLED or even constructed
j> nothing happen when i press Ctrl_Space after <tag

Not all PSI element types query references from PsiReferenceProvider.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

so what to do to provide suggestion of the tag names and attribute names supported in the xml file
actually your documentation recommend this method for providing entries for code completion

is there a way around?
is the solution through CompletionData and CompletionUtil
or what?
thanks a lot
joe

0

Please sign in to leave a comment.