Skip to content

Commit 70fc599

Browse files
authored
refactor(ansible): clean up ansible filetype detection (#1648)
1 parent 05ecb92 commit 70fc599

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

lua/astrocommunity/pack/ansible/init.lua

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
local function yaml_ft(path, bufnr)
2-
-- get content of buffer as string
3-
local content = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
4-
if type(content) == "table" then content = table.concat(content, "\n") end
5-
6-
-- check if file is in roles, tasks, or handlers folder
7-
local path_regex = vim.regex "(ansible\\|group_vars\\|handlers\\|host_vars\\|playbooks\\|roles\\|vars\\|tasks)/"
8-
if path_regex and path_regex:match_str(path) then return "yaml.ansible" end
9-
10-
-- check for known ansible playbook text and if found, return yaml.ansible
11-
local regex = vim.regex "^(hosts\\|tasks):"
12-
if regex and regex:match_str(content) then return "yaml.ansible" end
13-
14-
-- return yaml if nothing else
15-
return "yaml"
16-
end
17-
181
return {
192
{
203
"AstroNvim/astrocore",
214
opts = function(_, opts)
22-
local utils = require "astrocommunity"
235
return require("astrocore").extend_tbl(opts, {
246
filetypes = {
25-
extension = {
26-
yml = utils.merge_filetype("yaml", vim.tbl_get(opts, "filetypes", "extension", "yml"), yaml_ft),
27-
yaml = utils.merge_filetype("yaml", vim.tbl_get(opts, "filetypes", "extension", "yaml"), yaml_ft),
7+
pattern = {
8+
[".*/defaults/.*%.ya?ml"] = "yaml.ansible",
9+
[".*/host_vars/.*%.ya?ml"] = "yaml.ansible",
10+
[".*/group_vars/.*%.ya?ml"] = "yaml.ansible",
11+
[".*/group_vars/.*/.*%.ya?ml"] = "yaml.ansible",
12+
[".*/playbook.*%.ya?ml"] = "yaml.ansible",
13+
[".*/playbooks/.*%.ya?ml"] = "yaml.ansible",
14+
[".*/roles/.*/tasks/.*%.ya?ml"] = "yaml.ansible",
15+
[".*/roles/.*/handlers/.*%.ya?ml"] = "yaml.ansible",
16+
[".*/tasks/.*%.ya?ml"] = "yaml.ansible",
17+
[".*/molecule/.*%.ya?ml"] = "yaml.ansible",
2818
},
2919
},
3020
})

0 commit comments

Comments
 (0)