Hey Nuzy.
Thank you for the feedback! We recently had a discussion in the community (discord) about this very subject.
It is unlikely that something like this would end up in Oxide because Oxide can't be unit tested and we can't guarantee any major feature changes will remain stable (Oxide changes are immediately pushed to production).
However, I think something along these lines would be a great addition for uMod, which has a considerably more advanced compiler than Oxide.
Firstly, let me explain how this works in uMod because this system is fairly complex. We have 2 different types of dependencies (Optional and Requires) and each type of dependency has two implementations (Implicit and Explicit). As a result, we have 4 different dependency implementations: Implicit Optional (default), Explicit Optional (+duck typing), Implicit Requires, and Explicit Requires (like //Requires but more stable). More information can be found here.
Since your experience is with PHP, I'll explain some of the differences from that perspective. In PHP, any class that's autoloaded is loaded globally and can reference any other part of the system regardless of the order the class was loaded. This is not true in C#, every time a class is loaded, all of it's dependencies must be compiled with the class.
For example, if PluginA depends on PluginB and PluginB is loaded later (after the first load), then PluginA must be unloaded and recompiled with PluginB. This is a implementation detail specific to C# and how it handles assemblies. It is also what makes the compiler an "incremental compiler." Yes, technically there are some shortcuts around this in some cases, but generally this cannot be avoided.
At any rate, the current uMod compiler already does something similar to auto-loading in a limited capacity. Namely, type promises will keep track of missing types not found when a plugin compiles. If any subsequent compilations fulfill the type promise, then both plugins are re-compiled together. The limitation is that this functionality only works on plugins in the plugins directory (not sub-directories).
The uMod compiler adds a couple of new dependency options (as previously mentioned) which are unavailable in Oxide, making plugin integrations more flexible and performant in general. As of right now, we have explored several options to improve plugin organization with dependencies beyond what we've already done.
Some options being considered...
PHP PSR-4
Autoloading similar to PSR-4 (PHP) which creates a convention where there is a one-to-one match between namespaces and the directory structure. For example uMod.Plugins.Calytic.MyClass would be in umod/plugins/Calytic/MyClass.cs.
PROS:
- Code remains easily accessible via .cs files
- Code can be split up into multiple files fairly simply (with matching namespace/directory convention)
CONS:
- Having plugins strewn about multiple files in the umod/plugins directory may lead to confusion, where users move files around where they aren't supposed to be. The plugins directory isn't 100% comparable with the /vendor directory that composer uses because vendor files are never supposed to be modified, whereas users routinely find themselves modifying/moving files in the plugins directory.
- C# does not allow a class and a namespace to have the same name in the same namespace. For example, you can't have "uMod.Plugins.MyPlugin" (MyPlugin.cs) and "uMod.Plugins.MyPlugin.OtherClass" (MyPlugin/OtherClass.cs)
JAVA .jar
PROS:
- Plugins are self-contained packages, like ZIP files, where all of the files related to the plugin are in a single place (like MyPlugin.umod)
CONS:
- Code no longer easily accessible via .cs files (users must understand that ".umod" files are an archive and extract them to view contents)
- Code in ".umod" cannot easily be modified, it would require developers to extract, modify, and recompress the umod file every change.
There may be more options, and if anyone has a suggestions please feel free to chime in. Implementing either thing will require sweeping changes to a wide variety of systems, both in uMod and other related systems (like this website). As such it's not something that's likely to happen quickly but it's good to get the ball rolling..