PsiReference provided by ReferenceProvider ignored during completion if it has same text range as existing reference in XML file?

I have PsiReference that I inject into XML file. In this:

<call:OtherTemplate/>

The "OtherTemplate" is a reference. (I return a TextRange of inside
the XmlToken for the name.) IDEA highlights OtherTemplate as red when resolve()
returns null, but its getVariants() is never called when I invoke ctrl+space in
there.

I was very confused about this, then I found that if I return a TextRange of
, it works (but the : is highlighted as well so this isn't a good
solution). It looks like IDEA only allows one PsiReference with the same
TextRange to complete.

Is this desired behavior? Is there something I do wrong? Should I file JIRA issue?

0
24 comments

I'm also currently struggling with not-so-open-OpenAPI for ReferenceProvider and friends.. well, I got some stuff working, but the best I found is this ;)

getReferencesByElement called for psiElement = "IntellijIdeaRulezzz "

what am I doing wrong?!

0

Is it possible to get the current VirtualFile within PsiReference.getVariants() ?

I'm attaching it to XmlAttributeValue, getting element.getContainingFile() returns a valid PsiFile, but calling getVirtualFile() on this returns null (on a sidenote, calling isPhysical() return false - is this some kind of intermediate PsiFile?!).

Any other way? (I need to find out the current Module, in the end ..)

Thanks,

Yann

0

Answering myself:

0
Avatar
Permanently deleted user

There's nothing wrong with that. I believe IDEA inserts IntellijIdeaRulezzz into
the file temporarily when you complete, so it can call getVariants() and things
like that on the produced PsiReference.

Yann Cebron wrote:

I'm also currently struggling with not-so-open-OpenAPI for ReferenceProvider
and friends.. well, I got some stuff working, but the best I found is this
;)

getReferencesByElement called for psiElement = "IntellijIdeaRulezzz "

what am I doing wrong?!

0
Avatar
Permanently deleted user

I ran across this problem yesterday. As I said in my last post before reading
this post, IDEA seems to create a temporary file which has no VirtualFile, but
is a copy of a real file, and inserts IntellijIdeaRulezzz into it. I haven't
found a solution yet (and getOriginalElement() returns this).

Yann Cebron wrote:

Is it possible to get the current VirtualFile within PsiReference.getVariants() ?

I'm attaching it to XmlAttributeValue, getting element.getContainingFile() returns a valid PsiFile, but calling getVirtualFile() on this returns null (on a sidenote, calling isPhysical() return false - is this some kind of intermediate PsiFile?!).

Any other way? (I need to find out the current Module, in the end ..)

Thanks,

Yann

0
Avatar
Permanently deleted user

Hello Keith,

KL> I ran across this problem yesterday. As I said in my last post
KL> before reading this post, IDEA seems to create a temporary file
KL> which has no VirtualFile, but is a copy of a real file, and inserts
KL> IntellijIdeaRulezzz into it. I haven't found a solution yet (and
KL> getOriginalElement() returns this).

Yes, that's indeed what IDEA does. What is the problem for which you need
the solution?

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Avatar
Permanently deleted user

This isn't my problem. I was responding to the post. My problem is described in
the first message: "It looks like IDEA only allows one PsiReference with the
same TextRange to complete. Is this desired behavior? Is there something I do
wrong? Should I file JIRA issue? "

Dmitry Jemerov (JetBrains) wrote:

Hello Keith,

KL> I ran across this problem yesterday. As I said in my last post
KL> before reading this post, IDEA seems to create a temporary file
KL> which has no VirtualFile, but is a copy of a real file, and inserts
KL> IntellijIdeaRulezzz into it. I haven't found a solution yet (and
KL> getOriginalElement() returns this).

Yes, that's indeed what IDEA does. What is the problem for which you
need the solution?

0

Dmitry,

can we expect ReferenceProvider-API will be included in OpenAPI soon? I think it's a very important part for plugins, e.g. all plugins supporting specialized XML-configuration files for frameworks (Spring, Hibernate, ..) would benefit.

Greetings,

Yann

0
Avatar
Permanently deleted user

Hello Yann,

YC> can we expect ReferenceProvider-API will be included in OpenAPI
YC> soon? I think it's a very important part for plugins, e.g. all
YC> plugins supporting specialized XML-configuration files for
YC> frameworks (Spring, Hibernate, ..) would benefit.

Depending on what you mean by "soon". It will not be included in the 5.0
bugfix updates, but it's likely to be included in the next version of IDEA.

Note that it's likely that the OpenAPI for references and completion will
be significantly different from the API of the internal IDEA classes you're
using now.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Thanks for your answer.

Btw, if I register 2 or more Providers with registerXmlAttributeValueReferenceProvider() the last one wins and overwrites all previous providers. Is this by design?! Is there a better way to extend IDEA's standard providers with custom providers?

Thanks,
Yann

0

Now I've found a way to combine IDEA's internal Providers with my custom one, so that both results are being combined - but now the same problem as Keith: only one provider is considered for getVariants(), highlighting/navigation works fine for both types combined.

Can we please have some enlightement from JB?

0

Dmitry - any news? This is a major drawback and the main reason for holding back a new release of Struts Plugin for me right now. Or will I have to implement web resource reference provider by myself instead of reusing it :(

Thanks,

Yann

0
Avatar
Permanently deleted user

Hello Yann,

YC> Dmitry - any news? This is a major drawback and the main reason for
YC> holding back a new release of Struts Plugin for me right now. Or
YC> will I have to implement web resource reference provider by myself
YC> instead of reusing it :(

There is indeed a shortcoming of the IDEA code, but fortunately it's easy
to fix, and we'll include the fix in the upcoming 5.0.2 bugfix update.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Wow - that's a fast AND pleasing answer ;)

Thanks,

Yann

0

bump I hope #3506 is not 5.0.2 since it's still not working. Just a friendly reminder ;)

cheers,
Yann

0
Avatar
Permanently deleted user

Question to Keith Lea:
Do you implement XML language from scratch for injecting your PsiReferences to the language?

Does injection of PsiReference require own element types (that possible only if use own ParserDefinition)?

0
Avatar
Permanently deleted user

Alexei wrote:

Question to Keith Lea:
Do you implement XML language from scratch for injecting your PsiReferences to the language?


No, you can do this without huge amount of hacking.

Does injection of PsiReference require own element types (that possible only if use own ParserDefinition)?


No, PsiReference is a simple interface. What kinds of references do you
plan to inject?

0
Avatar
Permanently deleted user

It will be good to inject PsiReferences into XML attribute values (XML attribute value is Java expression that specifies some Java bean property) for these purposes:
1. Go to declaration (opens method in the Java bean).
2. Error highlighting (mark the attribute value as error if its Java expression has errors).

Can I use the ReferenceProvidersRegistry.registerXmlAttributeValueReferenceProvider() for these purposes? What object should I pass as first parameter of this method?

0
Avatar
Permanently deleted user


Result of resolve() is used for goto declaration
If it is null and reference is not soft then the reference in highlighted.


Alexei wrote:

String[] of attribute names
ElementFilter that by XmlAttributeValue will tell if the provider could
give some references (you may not bother with it, pass null and return
refs when appropriate).

--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Avatar
Permanently deleted user

I can't list all possible attributes names for the registerXmlAttributeValueReferenceProvider() call. Can I pass null or empty array as the 1st parameter to inject references to all attribute values?

0
Avatar
Permanently deleted user

Yes, this is just a hint.

Alexei wrote:

I can't list all possible attributes names for the registerXmlAttributeValueReferenceProvider() call. Can I pass null or empty array as the 1st parameter to inject references to all attribute values?



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Avatar
Permanently deleted user

I have registered the PsiReferenceProvider for XML attribute values, and now "Go to declaration" feature works correctly on custom HTML attribute values (using the PsiReference.resolve() method in the MyReference class).

I'm trying to implement error highlighting for custom HTML attribute values. Does Idea calls the PsiReference.resolve() method to check attribute value (if the method returns null and reference isn't soft then the attribute value is highlighted as error)?

Also I see a strange thing: the PsiReference.resolve() method isn't called for CUSTOM HTML attribute values except Go to declaration action but the method is called for onclick attribute value on attribute value change (and isn't called for background attribute value).

Please advise me how to enable error checking of custom HTML attribute values.

0
Avatar
Permanently deleted user

Alexei wrote:

I'm trying to implement error highlighting for custom HTML attribute values. Does Idea calls the PsiReference.resolve() method to check attribute value (if the method returns null and reference isn't soft then the attribute value is highlighted as error)?

Yes.

Also I see a strange thing: the PsiReference.resolve() method isn't called for CUSTOM HTML attribute values except Go to declaration action but the method is called for onclick attribute value on attribute value change (and isn't called for background attribute value).

Please advise me how to enable error checking of custom HTML attribute values.


There could be other references, IDEA does not currently combine them all.

--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Avatar
Permanently deleted user

I extended HTML editor that "Go to declaration" feature works for the HTML attribute values (through registering XML attribute value provider and my implementation of the PsiReference.resolve() method). But the error highlighting feature doesn't work! The PsiReference.resolve() method isn't called for these purposes!

Where is the problem? Is the problem specific to HTLM grammar (for example, conflicts with javascript)?

Is there other way to highlight errors in HTML attribute values except through the PsiReference.resolve() call (error checking by button press is acceptable)?

0

Please sign in to leave a comment.