Plugin development improvements #2703
joaquimrocha
started this conversation in
Ideas
Replies: 2 comments
-
Thanks for the clear explanation and description of possible solutions @joaquimrocha. I don't think you'll have to worry too much about the differences between using classes or objects for plugin developers as long as there are clear instructions. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The class approach is a good improvement. It makes the contract between plugins and headlamp core better to understand and validate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Right now, the way plugins are coded is: they call
register*
methods to register functionality they want to add/override.There are two ways of calling these methods: either they are called after defining a Plugin class, or they are called directly in the module/file of the plugin. Since the latter is simpler, it is the only one we have been advertising for a while.
Headlamp thus loads the plugins by eval'ing their code. Moreover, the registered functions are kept in Redux, for a quick access.
This approach has a couple of issues:
register*
methods "loose" in the file, it runs all register functions right away; there is no way to plan calling certain of those register functions at a later point; or to easily get the plugin to have initialization/destruction methods.register*
without any context about the plugin, it is not possible for Headlamp to understand which plugin is calling that method; of course we could require a plugin name to be added to the method, but this would make it trivial for a plugin to "pretend" to be another one. This impedes e.g. understanding what parts of the UI the plugin may attempt to change, so we could e.g. wrap a plugin's added header action in a div that tells which plugin has added that action, when in dev mode.So I would like to kickstart a discussion about how we could make this more controllable from Headlamp's side.
Proposals:
Classes
If we define a plugin as a class, we can require the registered functionality to be declared as instance variables instead, e.g.:
Pros:
We are thus able to solve the problems above in the following way:
Cons:
Object
This would be similar to a class definition, but we'd define an object instead:
Pros
Cons
Code Interception
I noticed that VSCode does some module intercept so even when plugins call methods (not defining, calling) VSCode knows who is calling them.
AFAIU, if we did this, then we could maintain the current
register*
methods while basically providing different versions of methods for each plugin. So we'd fix issue 2. Issue 3 could also be solved, but we'd still have to deprecate the previous functionality since runningregister
methods would rather mean defining methods to be run later.So let's discuss some of these or any new ideas you may have for making the plugin system even more powerful!
Beta Was this translation helpful? Give feedback.
All reactions