pearofducks / ansible-vim

A vim plugin for syntax highlighting Ansible's common filetypes
MIT License
796 stars 98 forks source link

neovim, how to keep ft=ansible instead of ft=yaml.ansible (mising jinjaVarBlock) #135

Open nbari opened 12 months ago

nbari commented 12 months ago

I just upgraded to neovim, and using these options:

vim.api.nvim_create_autocmd({
    "BufRead",
    "BufNewFile"
}, {
    pattern = {
        "*/ansible/*.yml",
        "*/tasks/*.yml",
    },
    callback = function()
        vim.bo.filetype = "ansible"
    end
})

-- ansible hosts
vim.api.nvim_create_autocmd({
    "BufRead",
    "BufNewFile"
}, {
    pattern = {
        "*/ansible/inventory/*",
        "*/ansible/hosts-*"
    },
    callback = function()
        local filepath = vim.fn.expand("%:p")
        if filepath:match("%.yml$") then
            vim.bo.filetype = "yaml.ansible_hosts"
        else
            vim.bo.filetype = "ansible_hosts"
        end
    end
})

For the LSP using ansiblels I use this:

    ["ansiblels"] = function()
                lspconfig.ansiblels.setup({
                    filetypes = {
                        "ansible",
                        "yaml.ansible",
                        "yaml.ansible_hosts"
                    },
                    settings = {
                        ansible = {
                            validation = {
                                lint = {
                                    arguments = "-c ~/.config/ansible-lint.yml"
                                }
                            }
                        }
                    }
                })

But the plugin is always overwriting the setting filetype to yaml.ansible, I would like to use only filetype ansible for "*/tasks/*.yml", any idea how to do this?

How could this maybe be overwriting using the after dir?

If I add this to every file: # vim: set ft=ansible: works but I would like to prevent don't it.

The main problem that I have is that if I use yaml.ansible for an unknown reason I don't see the jinjaVarBlock

This is how I see it with ft=yaml.ansible Screenshot from 2023-09-24 17-26-24

And I I use ft=ansible: Screenshot from 2023-09-24 17-26-57

I notice that when using ft=yaml.ansible the :syn list is empty but when using only ft=ansible I get all the syntax groups