Pycharm PyReferenceExpression doesn't allowed adding custom reference


I have a project using global symbols which are injected into builtin during runtime. These symbols don't need to be imported in each python file. However I can't figure out a way to let pycharm relate these symbols to certain modules(files). I come up with an idea of writing a plugin.

public class MyPsiReferenceContributor extends PsiReferenceContributor {
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
final PsiElementPattern.Capture<PyReferenceExpression> pattern = psiElement(PyReferenceExpression.class);
registrar.registerReferenceProvider(pattern, ...);

This is the pattern I use to find every symbol. But later debugging through the source code, I found out that PyReferenceExpression DO NOT get reference from ReferenceProvidersRegistry, which handles all self-implemented PsiReferenceContributor.

Am I missing something here? Can someone please help.

1 comment
Comment actions Permalink

Please take a look at com.jetbrains.python.psi.resolve.PyReferenceResolveProvider extension with com.jetbrains.python.psi.resolve.PythonBuiltinReferenceResolveProvider as sample implementation.


Please sign in to leave a comment.