Need information regarding PsiReferenceRegistrar.registerReferenceProvider()

Hi

Can someone explain me how PsiReferenceRegister.registerReferenceProvider() works? Can I use this to provide references for PyCallExpression?

Context:
I am working on a plugin for custom language which is based on Python plugin. Syntax of the custom language is similar to python, so we are using python plugin for parsing the file etc.

sample code:

# custom language sentences can be mapped to python function calls (ie. PyCallExpression)

custom_method_one( param_name_1 = param_value_1,

                                    param_name_2 = "param_value_2",

                                    param_name_3 = ["param_list_elem_1", "param_list_elem_2"]

                                   )


I would like to provide references to custom_method_one through a custom ReferenceProvider and register that reference provider using PsiReferenceRegister.registerReferenceProvider().

I observed that (on Intellij-9), getReferencesByElement() of the reference provider is getting invoked for PyStringLiteralExpression (like: "param_value_2" of the above sample code) but not for PyCallExpression (like: custom_method_one).

Where as, the same code used to work on Intellij-7.

Can somebody explain me what might have changed between Intellij-7 and Intellij-9 as far as referenceProviders are concerned?

Thx,
Chandra

5 comments
Comment actions Permalink

Hello chandra,

The Python plugin only allows injecting references via PsiReferenceProvider
into PyStringLiteralExpression elements. Function calls already have a reference
to the function, so it doesn't make sense to inject additional references.

Can someone explain me how
PsiReferenceRegister.registerReferenceProvider() works? Can I use this
to provide references for PyCallExpression?

Context:
I am working on a plugin for custom language which is based on Python
plugin. Syntax of the custom language is similar to python, so we are
using python plugin for parsing the file etc.
sample code:

  1. custom language sentences can be mapped to python function calls

(ie. PyCallExpression)
custom_method_one( param_name_1 = param_value_1,
param_name_2 = "param_value_2",
param_name_3 =
["param_list_elem_1", "param_list_elem_2"]
)
I would like to provide references to custom_method_one through a
custom ReferenceProvider and register that reference provider using
PsiReferenceRegister.registerReferenceProvider().

I observed that (on Intellij-9), getReferencesByElement() of the
reference provider is getting invoked for PyStringLiteralExpression
(like: "param_value_2" of the above sample code) but not for
PyCallExpression (like: custom_method_one).

Where as, the same code used to work on Intellij-7.

Can somebody explain me what might have changed between Intellij-7 and
Intellij-9 as far as referenceProviders are concerned?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks for your reply.

It seems, I havent expressed my question properly.

Every statement in our custom language resembles a python method call. The custom language has set of methods, prototype/signatures for these methods is provided an external entity.
A sample file looks like this:

============ start of file ==================

custom_method_one( param_name_1 = param_value_1,

                                    param_name_2 = "param_value_2",

                                    param_name_3 = ["param_list_elem_1", "param_list_elem_2"]

)

custom_method_two( param_name_1 = param_value_11,
                                    param_name_4 = "param_value_22")

...


============ end of file ==================

This file doesnt contain definitions/declarations for custom_method_one or custom_method_two. As a result, code completion for these methods is not working and usage of these methods is displayed with warning "Unresolved reference to ...".

Can I use reference providers to provide declaration information about these methods?

From your reply it seems: PsiReference contains just reference to token and this reference contain enough information to traverse to the declaration of the token.

Thanks,
Chandra
0
Comment actions Permalink

Hello chandra,

The Python plugin does not currently contain APIs to customize the resolving
of unqualified references. If the reference is qualified (some_object.custom_method),
you can use the PyTypeProvider API to specify the type of some_object and
to allow for custom_method to be resolved.

For unqualifed references, it's likely that extensibility APIs will be provided
in a future version of the plugin.

Thanks for your reply.

It seems, I havent expressed my question properly.

Every statement in our custom language resembles a python method call.
The custom language has set of methods, prototype/signatures for these
methods is provided an external entity.

A sample file looks like this:

============ start of file ==================
custom_method_one( param_name_1 = param_value_1,
param_name_2 = "param_value_2",
param_name_3 =
["param_list_elem_1", "param_list_elem_2"]
)
custom_method_two( param_name_1 = param_value_11,
param_name_4 = "param_value_22")
..

============ end of file ==================

This file doesnt contain definitions/declarations for
custom_method_one or custom_method_two. As a result, code completion
for these methods is not working and usage of these methods is
displayed with warning "Unresolved reference to ...".

Can I use reference providers to provide declaration information about
these methods?

From your reply it seems: PsiReference contains just reference to
token and this reference contain enough information to traverse to the
declaration of the token.

Thanks,
Chandra
---
Original message URL:
http://www.jetbrains.net/devnet/message/5265185#5265185

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Dmitry,

Is there any change in the python plugin functionality between Intellij-7.0 and Intellij-9.0 (wrt reference providers resolving PyCallExpression)?

Thanks,
Chandra

0
Comment actions Permalink

Hello chandra,

I don't see any evidence of this functionality ever being present in our
code.

Is there any change in the python plugin functionality between
Intellij-7.0 and Intellij-9.0 (wrt reference providers resolving
PyCallExpression)?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.