allow for plugins not using the ElixirSense.Plugin @behaviour
#167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So the problem with the existing implementation of plugins that live outside of ElixirSense (a problem that I created 😄 ) is that, unless you want your external hex package to have an explicit dependency on
elixir_sense
, you're going to have to do something like this:And then in your code that defines the plugin, you'll need to do something like:
If you don't do that, then users who use your plugin without including
{:elixir_sense, ...}
as a dev dependency will get errors.BUT then you run into the issue that if they don't include
{:elixir_sense, ...}
as a dev dependency, then the plugin won't be compiled at all, and so elixir_sense won't know about it.This became an especially big problem when elixir_sense updated and a bunch of new ash users that were pointing at
elixir_sense
on github got that new update, but that update was not compatible with the version ofelixir_ls
that they were running. And so elixir_ls broke for all of them (and will break for any new user who follows the current getting started guide).It is an unfortunate set of circumstances, and as far as I can tell there is really only two ways it can work and still be a good experience for end users:
plugins can live in
elixir_sense
. This is great for really popular things like the ecto plugin, but personally I think it stifles creativity/velocity for other people who want to experiment with these things. Maybe thats only me, for now, but eventually I think it won't beplugin authors can do some hacky/annoying stuff to not have a dependency on ElixirSense, but to also not conditionally compile on its presence. Things like changing
ElixirSense.Plugin.foo(bar)
toapply(ElixirSense.Plugin, :foo, [bar])
. Additionally, to avoid warnings on missing@behaviour
modules, we have to make them findable without adopting the behaviour.For an example of what this looks like for Ash (well, technically for Spark), you can see the PR that would make this work:
https://github.com/ash-project/spark/pull/5/files
Its naturally not ideal for me to have to code the plugin this way, but this is very much preferrable to the alternative of requiring users to pin a specific version of elixir_sense, IMO.