Pycharm code insight: add custom key to __builtins__
Answered
My project add some const variables to __builtins__ dict. I want pycharm to recognize these symbols: provide code completion and reference. Right now I can add those variables one by one by implementing PyReferenceResolveProvider and hardcode every symbol with where they are defined. But there are a lot of declarations across different files. I think it is possible to scan the project finding all apperance of __builtins__ and store them in a cache, so when resolving such symbols, the plugin can easily find the source without searching across the whole project.
Is there a proper way to implement such feature?
class InfoHandler(object):
def __init__(self, _a):
self.a = _a
__builtins__["INFO"] = InfoHandler(1)
print INFO.a # 1
Please sign in to leave a comment.
Please see com.jetbrains.python.psi.resolve.PythonBuiltinReferenceResolveProvider and com.jetbrains.python.psi.impl.PyBuiltinCache as reference code