Skip to content

Commit

Permalink
fix(pack): Add support for additional Ansible directory structures in…
Browse files Browse the repository at this point in the history
… `ansible`'s path_regex, and correct docs (#1280)

fix(pack): Add support for additional well-known Ansible directories
  • Loading branch information
lucazz authored Dec 6, 2024
1 parent e643030 commit c5e7f6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lua/astrocommunity/pack/ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

This plugin pack does the following:

- Adds a set of local functions to help with Ansible's filetype detection
- Adds `yaml` Treesitter parsers
- Adds `ansiblels` language server
- Adds `ansible-lint` and `ansible-language-server` via `mason-tool-installer.nvim`, if enabled
- Sets up `mason-lspconfig.nvim` to use `ansiblels` if enabled
- Adds the following `null-ls` sources:
- [ansible-lint](https://github.com/ansible/ansible-lint)
- Adds [ansible-vim](https://github.com/pearofducks/ansible-vim) for language specific tools
- Adds the following `nvim-lint` sources:
- [ansible-lint](https://github.com/ansible/ansible-lint)
- Adds [pearofducks/ansible-vim](https://github.com/pearofducks/ansible-vim), and sets it up to be loaded for `yaml.ansible` file types
- Configures [stevearc/conform.nvim](https://github.com/stevearc/conform.nvim) to use `prettierd` and `prettier` for `yaml.ansible` file types
3 changes: 2 additions & 1 deletion lua/astrocommunity/pack/ansible/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ local function yaml_ft(path, bufnr)
if type(content) == "table" then content = table.concat(content, "\n") end

-- check if file is in roles, tasks, or handlers folder
local path_regex = vim.regex "(tasks\\|roles\\|handlers)/"
local path_regex = vim.regex "(ansible\\|group_vars\\|handlers\\|host_vars\\|playbooks\\|roles\\|\\vars\\|tasks)/"
if path_regex and path_regex:match_str(path) then return "yaml.ansible" end

-- check for known ansible playbook text and if found, return yaml.ansible
local regex = vim.regex "hosts:\\|tasks:"
if regex and regex:match_str(content) then return "yaml.ansible" end
Expand Down

1 comment on commit c5e7f6a

@rosstang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong regex on \|\vars\|, should be just \|vars\|

Causing error like,
Image

Please sign in to comment.