1
0
Fork 0

add ansible filetype detection

This commit is contained in:
Luca Bilke 2022-12-05 18:23:48 +01:00
parent 14e1b3f391
commit ac654d5cc7
5 changed files with 46 additions and 18 deletions

View File

@ -5,7 +5,8 @@ end, 0)
require('config.options')
require('funcs').bootstrap()
require('plugins')
require('funcs').autocmd(require('config.autocmdlist'))
require('config.autocmdlist')
require('config.filetypelist')
require('funcs').map('general')
local icons = require('config.iconlist').diagnostics

View File

@ -1,4 +1,4 @@
return {
local cmds = {
{ -- Handles the automatic line numeration changes
{ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" },
{
@ -104,3 +104,17 @@ return {
}
}
}
vim.api.nvim_create_augroup('packer_user_config', { clear = true })
for _, entry in ipairs(cmds) do
local event = entry[1]
local opts = entry[2]
if type(opts.group) == "string" and opts.group ~= "" then
local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = opts.group })
if not exists then
vim.api.nvim_create_augroup(opts.group, {})
end
end
vim.api.nvim_create_autocmd(event, opts)
end

View File

@ -0,0 +1,28 @@
local filetypes = {
{
extension = {
yml = function(path, bufnr)
if vim.fs.find({ 'tasks', 'roles', 'handlers', 'group_vars', 'host_vars' },
{ type = 'directory', upward = true }) and
vim.fs.find({ 'ansible.cfg', '.ansible-lint' }, { upward = true }) then
return 'yaml.ansible'
else
return 'yaml'
end
end,
yaml = function(path, bufnr)
if vim.fs.find({ 'tasks', 'roles', 'handlers', 'group_vars', 'host_vars' },
{ type = 'directory', upward = true }) and
vim.fs.find({ 'ansible.cfg', '.ansible-lint' }, { upward = true }) then
return 'yaml.ansible'
else
return 'yaml'
end
end
}
}
}
for _, entry in pairs(filetypes) do
vim.filetype.add(entry)
end

View File

@ -1,20 +1,4 @@
local M = {}
function M.autocmd(list)
vim.api.nvim_create_augroup('packer_user_config', {clear = true})
for _, entry in ipairs(list) do
local event = entry[1]
local opts = entry[2]
if type(opts.group) == "string" and opts.group ~= "" then
local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = opts.group })
if not exists then
vim.api.nvim_create_augroup(opts.group, {})
end
end
vim.api.nvim_create_autocmd(event, opts)
end
end
function M.lazy_load(tb)
vim.api.nvim_create_autocmd(tb.events, {
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),

View File

@ -1 +1,2 @@
TODO: Function to decide between LS and null-ls for formatting
TODO: Learn fennel and rewrite this config in it!