In a previous blog post I wrote about testing Lua scripts in Neovim using the busted test framework. Today I want to look at how to debug Lua scripts in Neovim using the Debug Adapter Protocol (DAP). Just as before with busted, our problem is that we need to use Neovim as our Lua interpreter because we want to use Neovim's Lua API. At the same time, the debug adapter expects the Lua interpreter to conform to Lua's command-line interface. That's right: we need another command-line interface adapter.
Yo dawg, I heard you like Neovim, so I put a Neovim inside your Neovim, so you can edit while you edit! Ahem... anyway, in my previous post I proposed a plugin which would make it easier to control an embedded Neovim from within Neovim. So I went ahead and wrote yo-dawg.nvim (GitHub mirror), named after the “Yo dawg” internet meme.
The most annoying part about writing plugins for Neovim has been the lack of a good test framework. There are a couple of frameworks, and Vader has been my favourite so far, but they all have their downsides. This made me wonder: why limit myself to Vim/Neovim test frameworks? We have a full Lua runtime, and other people already have solved the testing problem for Lua. Busted does 90% of what we need, so let's fill in the remaining 10%. The following is based on my experience with adding tests to rainbow-delimiters.nvim.
I have recently been getting into Elixir, and one nice feature it has is the pipe operator. It allows us to express a pipeline of function through which an object will be dragged. This got me thinking: with how flexible Lua is, would it be possible to add something similar to Lua as well?
LuaRocks is a community-driven package manager for the Lua programming language. LuaRocks packages can be installed globally or in the user's home directory, but sadly LuaRocks does not follow the XDG Base Directory specification. However, with a few lines of Lua code we can fix this shortcoming partially at least.