I tried to install the ansible-language-server today but it seems that Emacs doesn’t see it.
Since there is no Nix package I tried to install directly with NPM.
However when I tried to install it in Emacs it didn’t show up as mentioned by the documentation for lsp-mode.
Does someone have achieved this?
lsp-mode is finnicky, each language server has its own client implementation in the package, and each has a different way of deciding where to get its binaries from.
lsp-ansible
does what most of the clients do, and caches the executable path when it’s first evaluated: lsp-mode/lsp-ansible.el at 7b00b676e0a5a3a0002373f87c3521e5d1f85d8e · emacs-lsp/lsp-mode · GitHub. That means you must have the server in your PATH
before the mode is evaluated, which if you’re using direnv
has a good chance of breaking. Your PATH
must also be correct.
Using the versions of language servers that lsp-mode offers to install for you will almost always break, since those are just raw binaries downloaded from god-knows-where on the internet and hence don’t come with the correct NixOS-specific interpreter/library paths. You can try to patchelf
them, I believe they’re downloaded into your ~/.emacs
by default.
So, the quick way to fix your predicament is to patchelf
the downloaded binary, and then set a static path with lsp-mode/lsp-ansible.el at 7b00b676e0a5a3a0002373f87c3521e5d1f85d8e · emacs-lsp/lsp-mode · GitHub.
Personally, I use eglot, which has a generally much saner implementation and integrates well with the direnv mode, and write my own little nix derivations for language servers that don’t already have one upstream.
+1 for eglot. Tried quite a bit, but lsp-mode will always be poor experience because its assumptions don’t always line up with NixOS reality.
Eglot mode is (slightly) more work up front, but has much less chance of breaking down because there is very little smarts involved.
Thanks I will give eglot a try.
I already got it partially working but will have to try some more.
I never had any problems using lsp-mode
, but instead have been disappointed by eglot
s lack of features.
No lenses, no doc overlay, really nothing but completion.
Honestly I don’t really care about the package I just would like to get ansible-language-server working.
It helps quite a bit work when I’m using it in VSCode.
hover-on-symbol + eldoc-doc-buffer
covers those use cases for me, as well as M-.
and M-,
if I need to see the code.
But yes, we’re off-topic. Someone should write a thorough comparison sometime, but not here