Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pack): Adding ansible pack #346

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lua/astrocommunity/pack/ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ansible Language Pack

This plugin pack does the following:

- Adds `yaml` Treesitter parsers
- Adds `ansiblels` language server
- 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
48 changes: 48 additions & 0 deletions lua/astrocommunity/pack/ansible/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local utils = require "astronvim.utils"

return {
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
if opts.ensure_installed ~= "all" then
opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "yaml")
end
end,
},
{
"jay-babu/mason-null-ls.nvim",
opts = function(_, opts) opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "ansiblelint") end,
},
{
"williamboman/mason-lspconfig.nvim",
opts = function(_, opts) opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "ansiblels") end,
},
{
"pearofducks/ansible-vim",
init = function()
local function yaml_ft(path, bufnr)
-- get content of buffer as string
local content = vim.filetype.getlines(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)/"
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

-- return yaml if nothing else
return "yaml"
end

vim.filetype.add {
extension = {
yml = yaml_ft,
yaml = yaml_ft,
},
}
end,
ft = "yaml.ansible",
},
}