Getting ansible-language-server to work with eglot #1292
dcunited001
started this conversation in
General
Replies: 1 comment
-
These issues are similar to discussion #1134, but it is closed. |
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
-
So for me, there's many problems and it's not easy to get
ansible-language-server
to indicate what's going on. I've spent 3+ days on this, unfortunately. This includes configuring VSCode and perhaps Doom Emacs with LSP. I've considered starting up ansible-language-server with strace to see what it's doing.I may be able to provide log output, but it's very confusing. Sorry if this post is hard to follow. I have a bunch of other notes on things I've tried if it's useful. Ansible (and any YAML dialect) is one place where you definitely need completion and navigate-to-definition.
TL;DR;
Ansible-language-server is going to be a bit fragile. If anything goes wrong with
ansible-lint
, then the server seems to stop responding. I currently have it working, but with ansible-lint turned off. That works in arch, but not on Guix.I'm not sure whether
lsp-mode
has issues, but the VSCode extension interacts with the language server in a fundamentally different way. It compiles the language-server and interacts with it vianode
on hooks. See the tasks from package.json in ansible/vscode-ansibleHow the different components of the VSCode extension interact and contribute to the features is confusing. The images in this article clear that up. Deep Dive on Ansible VSCode Extension
Maybe try
yaml-language-server
with yaml schemas. If you don't know where to find them, look in the VSCode source or in its extension repos .... it downloads a giant list of all the schemas. Just grab them there.Another option is to use snippets. See this for a description of how to generate snippets from
ansible-doc
via an old Sublime project.. I ended up with too many, but they are basically de facto documentation -- and condensed which is sorely needed for Ansible.Environment
Emacs
I could partially get the
ansible-language-server
working on my arch machine with an emacs config based around a Guix profile. It mixes Guix and Straight emacs packages, but hints to straight to avoid loading dependencies when they are pulled in from both sources (wierd config, I know).The same Emacs config is set up on my laptop, which is running Guix System
Projects
I tested on arch with geerlingguy/ansible-role-gitlab.
The ansible dependencies are provided by
direnv
, which loads a python.venv
. I also have an ansible ee image for some things, but I have that disabled in Ansible LSP for now.Eglot and .dir-locals.el
You need to create a major mode for ansible. Like this:
Then in your
.dir-locals.el
, setauto-mode-alist
locally only. I will eventually needhelm
and other yaml dialects to be supported as well.Main issues:
A lot of things go wrong
Can't get stdout
But I can't figure out how to get error output from Ansible LSP server when invoking it from emacs.
There is no
ansible-language-server --help
. I tried reading through the source, but the option parsing behavior is inherited from the microsoft/vscode-languageserver-node server, so it's defined in two places. AFAIK neither can be run withx-language-server --help
to determine options.socat and strace are possibilities but seem overkill.
Ansible Deps
Keep them up to date. I had 8.0.0 and other earlier versions of ansible on my Guix machine. I'm not sure if this was causing problems.
Ansible Lint
Any kind of ansible-lint issues and the LSP server is not going to cooperate. Definitely test with
ansible-lint
. I just assumed a default.ansible-lint
config would work, which was a mistake.Kinds not configured (or paths don't match
ansible-lint
expectations)if your playbooks are not in
playbooks/**/*.yml
, ansible-lint will give you something like this: Why does my tasks file (under tasks/do_sth/do_sth.yaml) say "block is a required property"? #3304. this means you need to configure the kinds foransible-lint
Ansible Lint needs access to vault
I'm using a script/etc to provide the ansible-vault password. So I need to figure out how to disable any functionality where
ansible-lint
would need to connect to remote machines to validate YAML.LSP Docker
Using the
lsp-docker
containers as a model, I tried running the process there, but this was a mistake. eglot doesn't handle path translation the same way. Running in a docker container without docker-tramp may work, but only if your project and dependency paths match exactly... this seems difficult to configure except for projects with self-contained environments like with.node-modules
or.venv
.Misc Warnings
LSP
I'm getting a warning on startup about workspace/didChangeConfiguration. Here's the implementation in Ansible LSP.
GLib
This likely relates to my guix system configuration. It doesn't appear in my logs when the server is functioning normally. There are also python segfaults nearby.
Beta Was this translation helpful? Give feedback.
All reactions