--- name: neovim-implementation description: Implement Neovim plugins and configs using TDD — Lua plugin architecture, vim.api, keymaps, autocommands, LSP integration, testing with plenary.nvim. license: MIT allowed-tools: [read, write, edit, bash, glob, grep] --- # Neovim Implementation Skill Implement Neovim configuration and Lua plugins with test-driven development. ## TDD Workflow ``` 1. Identify target functionality 2. Write failing test first (busted/plenary) 3. Implement minimal code to pass 4. Run test to verify pass 5. Refactor while tests pass 6. Repeat for each feature ``` ### TDD Rules 1. **Write test first** - Never implement without a failing test 2. **Minimal implementation** - Only write code to make the test pass 3. **Refactor under green** - Only refactor when all tests pass 4. **One feature at a time** - Focus on single functionality per cycle --- ## Testing Commands ### Run All Tests ```bash # Run all tests with plenary nvim --headless -c "PlenaryBustedDirectory tests/" # With minimal init nvim --headless -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal_init.lua'}" ``` ### Run Specific Tests ```bash # Single test file nvim --headless -c "PlenaryBustedFile tests/path/to/spec.lua" # Lint Lua luacheck lua/ --codes ``` --- ## Test File Structure ```lua -- tests/module_name_spec.lua describe("ModuleName", function() local module before_each(function() package.loaded["bugabinga.module_name"] = nil module = require("bugabinga.module_name") end) describe("function_name", function() it("should do expected behavior", function() local result = module.function_name(input) assert.equals(expected, result) end) it("should handle edge case", function() local result = module.function_name(edge_input) assert.is_nil(result) end) end) end) ``` ### Assertions ```lua -- Use is_nil/is_not_nil assert.is_not_nil(str:match("pattern")) assert.is_nil(str:match("pattern")) -- Equality assert.equals(expected, actual) assert.same(expected_table, actual_table) -- Errors assert.has_error(function() error_func() end) ``` --- ## Module Structure ### Standard Module Template ```lua -- lua/bugabinga/category/module-name.lua local M = {} --- Function description --- @param input string Input parameter --- @return string|nil result Result or nil on failure function M.function_name(input) if not input then return nil end return result end --- Setup function for configuration --- @param opts table? Optional configuration function M.setup(opts) opts = opts or {} end return M ``` ### Plugin Definition Pattern ```lua -- lua/bugabinga/plugins/category/plugin-name.lua return { "author/plugin-name", event = "VeryLazy", dependencies = { "dep/plugin" }, opts = { option_key = "value" }, config = function(_, opts) require("plugin-name").setup(opts) end, } ``` ### Plugin with Keymaps ```lua return { "author/plugin-name", event = "VeryLazy", keys = { { "xx", "PluginCommand", desc = "Plugin: Description" }, }, opts = {}, config = function(_, opts) require("plugin-name").setup(opts) end, } ``` --- ## Error Handling ### Safe Require ```lua local function safe_require(module_name) local ok, module = pcall(require, module_name) if not ok then vim.notify("Failed to load " .. module_name, vim.log.levels.WARN) return nil end return module end ``` ### User Notifications ```lua vim.notify("Operation completed", vim.log.levels.INFO) vim.notify("Warning: " .. msg, vim.log.levels.WARN) vim.notify("Error: " .. err, vim.log.levels.ERROR) ``` --- ## Quality Standards - **Indentation**: 2 spaces, expandtab - **Line length**: ~100 characters - **Naming**: lowercase_with_underscores - **Comments**: LuaDoc style for public APIs - **Error handling**: pcall for external dependencies - **Testing**: All public APIs must have tests