Proper Pycharm plugin architecture
Hello,
I'm working on Pycharm plugin for display additional information from sqlite files using ExternalAnnotator (and EditorLinePainter). In project (or in several opened [attached] projects in one IDE window) can be several sqlite files. I need:
1. Listen file changes of sqlite files. As understand it can be done via
VirtualFileManager.getInstance().addVirtualFileListener(object : VirtualFileListener {})
This is the right decision?
2. Plugin must cache data from sqlite files and use this in ExternalAnnotator. It seems PsiElement can store user data using
UserDataHolder.putUserData()
So on first step - on sqlite file change event plugin will get data from database and put this additional data to proper PsiElement's. And ExternalAnnotator just use this additional data to display information.
This is the right solution or is there another way?
Thank you for any help!
Best regards,
Aleksandr.
Please sign in to leave a comment.
1. Yes, it's a proper way to watch file changes
2. This is not a proper ways to cache data. Because psi elements may die and you need to think about refresh/invalidation. UserData has another use cases.
For example: you are extending some 3-d party language and need to add some property to every SomePsiMethod element. The proper way is to add a field and getter/setter to this psi element. But you can't do that, because this is not your code. In such cases, you may do the Key and put this data to psi element. Or you need to pass something between different methods and the only thing you have in the API is some PSI element. In such cases you may use it too.
In your case, as far as I get it, it seems better not to do preemptive work. You may catch file change, read data from sqlite, put it to the psi element and no one will query it before the next sqlite change. I'd made my own cache service for this with invalidation on sqlite change. Your annotator will query your cache service and it will check if sqlite files been changed and return cached data or refresh it.
Alexandr, thank you for help and this important clarifications!