Skip to content

Commit

Permalink
Add lua dap/osv configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 1, 2022
1 parent 26c22af commit 1bdc9d5
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions vim/.config/nvim/ftplugin/lua.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
local dap = require('dap')
local api = vim.api
dap.adapters.nlua = function(callback, conf)
local adapter = {
type = 'server',
host = '127.0.0.1',
port = conf.port
}
if conf.start_neovim then
local start_opts = conf.start_neovim
conf.start_neovim = nil
local handle
local pid_or_err
local opts = {
args = {
'-e',
'v',
'-c',
string.format("lua require('osv').launch({ port = %s })", conf.port),
start_opts.fname or api.nvim_buf_get_name(0),
},
cwd = start_opts.cwd or vim.fn.getcwd(),
detached = true,
}
handle, pid_or_err = vim.loop.spawn('/usr/bin/alacritty', opts, function(code)
handle:close()
assert(code == 0, "Exit code must be 0, not " .. tostring(code))
end)
if not handle then
error(pid_or_err)
end
local timer = vim.loop.new_timer()
timer:start(1000, 0, function()
timer:stop()
timer:close()
vim.schedule(function()
callback(adapter)
end)
end)
else
callback(adapter)
end
end


local function free_port()
local tcp = vim.loop.new_tcp()
tcp:bind('127.0.0.1', 0)
local port = tcp:getsockname().port
tcp:shutdown()
tcp:close()
return port
end


dap.configurations.lua = {
{
type = 'nlua',
request = 'attach',
name = 'Attach',
port = function()
return assert(tonumber(vim.fn.input('Port: ')), 'Port is required')
end
},
{
type = "nlua",
request = "attach",
name = "New instance (current file)",
port = free_port,
start_neovim = {}
},
{
type = "nlua",
request = "attach",
name = "New instance (crate/crate)",
port = free_port,
start_neovim = {
cwd = os.getenv('HOME') .. '/dev/crate/crate',
fname = 'server/src/test/java/io/crate/planner/PlannerTest.java',
}
}
}

local lsp = require('me.lsp.conf')
local config = lsp.mk_config()

Expand Down

0 comments on commit 1bdc9d5

Please sign in to comment.