66 lines
2.3 KiB
Lua
66 lines
2.3 KiB
Lua
-- update this configuration of nvim-surround
|
|
-- to handle {{ }} structure in ansible
|
|
-- I want to be able to add and delete those braces
|
|
local surround = require('nvim-surround')
|
|
|
|
surround.buffer_setup({
|
|
surrounds = {
|
|
['v'] = {
|
|
add = { '{{ ', ' }}' },
|
|
find = '{{[^}]-}}',
|
|
delete = '({{%s+)().+(%s+}})()$',
|
|
}
|
|
}
|
|
})
|
|
|
|
local ansible_paths = {}
|
|
local fname = vim.api.nvim_buf_get_name(0)
|
|
if fname:find('tasks/') then
|
|
ansible_paths = {
|
|
vim.fs.dirname(fname:gsub('tasks', 'files')),
|
|
vim.fs.dirname(fname:gsub('tasks', 'templates'))
|
|
}
|
|
end
|
|
vim.bo.path = table.concat(ansible_paths, ',')
|
|
|
|
-- TODO: ansible role navigation
|
|
-- When gd is pressed on a role name (e.g., "caddy", "geerlingguy.docker"),
|
|
-- open that role's directory in oil.
|
|
--
|
|
-- Implementation approach:
|
|
-- 1. Find ansible root by searching upward for ansible.cfg (bounded by getcwd)
|
|
-- - If not found, fallback to searching for .git directory
|
|
-- - If neither found, show warning and do nothing
|
|
-- 2. Parse roles_path from ansible.cfg
|
|
-- - Split by ':' to get multiple directories
|
|
-- - Resolve relative paths against ansible root
|
|
-- 3. Check if word under cursor matches any role directory
|
|
-- - Search each role directory for matching subdirectory
|
|
-- 4. If match found: :Oil <role_path>
|
|
-- - Else: fallback to vim.lsp.buf.definition()
|
|
--
|
|
-- Key functions to implement:
|
|
-- - find_file_ascending(start_dir, filename, boundary_dir)
|
|
-- Search upward for a file (e.g., ansible.cfg), stopping at boundary_dir
|
|
--
|
|
-- - find_directory_ascending(start_dir, dirname, boundary_dir)
|
|
-- Search upward for a directory (e.g., .git), stopping at boundary_dir
|
|
--
|
|
-- - get_ansible_root(buf_path)
|
|
-- Return the ansible project root directory by searching for ansible.cfg
|
|
-- or .git directory
|
|
--
|
|
-- - parse_roles_path(ansible_root)
|
|
-- Parse ansible.cfg to extract roles_path configuration
|
|
-- Return list of absolute role directories
|
|
-- Fallback to ansible_root .. "/roles" if roles_path not in config
|
|
--
|
|
-- - find_role_path(role_name, role_dirs)
|
|
-- Search each role directory for a matching subdirectory
|
|
-- Return full path if found, nil otherwise
|
|
--
|
|
-- - ansible_gd()
|
|
-- Main function bound to gd keymap
|
|
-- Get word under cursor, find role path, open in oil or fallback to LSP
|
|
|