|
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 | | - |
18 | 1 | return { |
19 | 2 | { |
20 | 3 | "AstroNvim/astrocore", |
21 | 4 | opts = function(_, opts) |
22 | | - local utils = require "astrocommunity" |
23 | 5 | return require("astrocore").extend_tbl(opts, { |
24 | 6 | 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", |
28 | 18 | }, |
29 | 19 | }, |
30 | 20 | }) |
|
0 commit comments