tomaciazek / vscode-ansible

Ansible VS Code Extension
MIT License
28 stars 3 forks source link

Incomplete syntax highlighting unless python path command fails #18

Closed kimbernator closed 3 years ago

kimbernator commented 3 years ago

Summary

I noticed that recently my syntax highlighting for ansible files is pretty much just YAML with jinja expression highlighting without any of the especially useful features of this extension.

For example, here's what I would expect to see: image

But here is what I actually see: image

Hovering on reboot will no longer provide information about that resource and keywords are no longer highlighted.

I went back and kept installing older versions of the extension until I got to 1.0.1, which is where the highlighting started working again. I can see that the only functional change from 1.0.1->1.0.2 was in https://github.com/tomaciazek/vscode-ansible/pull/7, where the python command to get the PATH was modified to use python3 instead because of a syntax error. For kicks, I opened the minified server.js from the installed 1.0.4 and found the "python3" string, modified it to "python" again, then reloaded the workspace and found that full syntax highlighting had returned in addition to the error it was intended to solve: image

Extension version

>=1.0.2

VS Code version

1.58.2

Ansible Version

ansible [core 2.11.1]
  config file = None
  configured module search path = ['/Users/kimbernator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/kimbernator/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Jun 29 2021, 05:25:02) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 2.11.3
  libyaml = True

OS / Environment

MacOS 11.5.1

Relevant log output

No response

tomaciazek commented 3 years ago

The thing is that you have both Python 2 and Python 3 installed on your OS. The reason python has been replaced with python3 was precisely for the extension to work correctly in such environments. In those environments python is resolved to Python 2, hence the error.

For some reason python3 is not resolved to Python 3 in your environment - this is what you should try to fix. You may either add python3 to your PATH; or provide full path to your Python 3 interpreter in the extension options (the folder containing the interpreter should contain python3 - which it always does in case of Python 3 installations).

kimbernator commented 3 years ago

The issue ended up being a little different; the directory that contained my collections/roles/etc wasn't actually in python3's sys.path. I don't know if I had just set a custom path for ansible-galaxy to store that stuff and never accounted for it or something, but I fixed this by adding a new ".pth" file (arbitrarily named ansible.pth) to my site-packages directory that contained the path to my ansible directory.

With that done, everything works perfectly (including autocomplete, which never worked in any state for me)