From 736a2699b903ea885625308404f1d1f7d1a1c8c3 Mon Sep 17 00:00:00 2001 From: Ducky SSH User Date: Sun, 7 Dec 2025 22:59:28 +0000 Subject: [PATCH] Add ansible filetype so that LSP works correctly --- init.lua | 16 ++++++++++------ lua/custom/plugins/ansible.lua | 21 +++++++++++++++++++++ lua/custom/plugins/init.lua | 4 +++- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 lua/custom/plugins/ansible.lua diff --git a/init.lua b/init.lua index 41638a6..4f53a1d 100644 --- a/init.lua +++ b/init.lua @@ -643,6 +643,9 @@ require('lazy').setup({ }, }, }, + ansiblels = { + filetypes = { 'yaml.ansible', 'ansible' }, + }, } -- Ensure the servers and tools above are installed @@ -653,12 +656,13 @@ require('lazy').setup({ -- You can press `g?` for help in this menu. require('mason').setup() - -- You can add other tools here that you want Mason to install - -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - }) + -- You can add other tools here that you want Mason to install + -- for you, so that they are available from within Neovim. + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'stylua', -- Used to format Lua code + 'ansible-language-server', -- Ansible LSP for YAML Ansible files + }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { diff --git a/lua/custom/plugins/ansible.lua b/lua/custom/plugins/ansible.lua new file mode 100644 index 0000000..4f119ab --- /dev/null +++ b/lua/custom/plugins/ansible.lua @@ -0,0 +1,21 @@ +-- Ansible configuration for detecting .yml files in roles and playbooks directories +return { + { + 'neovim/nvim-lspconfig', + optional = true, + -- This table sets up file type detection for Ansible files + init = function() + -- Set up autocommand to detect Ansible files and set their filetype + local ansible_augroup = vim.api.nvim_create_augroup('ansible-detection', { clear = true }) + + vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { + group = ansible_augroup, + pattern = { '*/roles/**/*.yml', '*/roles/**/*.yaml', '*/playbooks/**/*.yml', '*/playbooks/**/*.yaml', '*/hosts/**/*.yml', '*/hosts/**/*.yaml' }, + callback = function() + vim.bo.filetype = 'yaml.ansible' + end, + desc = 'Set filetype to yaml.ansible for Ansible files', + }) + end, + }, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d..436ad64 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,6 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + require 'custom.plugins.ansible', +}