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
请先登录再写评论。
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
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
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?
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
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!"
yep,that's it
thanx
joe
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
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!"
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