Closed ramboman closed 2 months ago
Thank you for opening an issue.
This is expected as launch()
will spawn a headless neovim instance, and this headless instance will by means of theinit.lua
launch itself again, resulting in an recursive launch which fails. To use launch
directly in the init.lua
, it requires a check so that that doesn't happen. This is currently in discussion in the open issue #43.
For an immediate solution, I would:
init.lua
. With -u NORC
, or -u NONE
.packpath
, runtimetimepath
, rtp
)osv
with launch()
init.lua
I'm aware this is less than ideal so a better solution is welcome, or any proposition.
I made some modifications to my debug code:
NVIM_CONFIG_DEBUG
NVIM_CONFIG_DEBUG
to something that is not "y"
before launching osv
and reset it back to its original value right after.Here is the code:
local lazydir = vim.fn.stdpath("data") .. "/lazy"
-- Debug
local osvpath = lazydir .. "/one-small-step-for-vimkind"
if (vim.uv or vim.loop).fs_stat(osvpath) then
local nvim_config_debug = vim.env.NVIM_CONFIG_DEBUG
if nvim_config_debug ~= vim.NIL and nvim_config_debug == "y" then
vim.opt.rtp:prepend(osvpath)
vim.env.NVIM_CONFIG_DEBUG = ""
require("osv").launch({ port = 8086 })
vim.env.NVIM_CONFIG_DEBUG = nvim_config_debug
vim.print("Press any key to continue")
vim.fn.getchar()
end
end
Now I can start the debugger at the beginning of the config.
I will leave this issue open since, osv
, itself, alone, cannot be started at the beginning of the configuration. This is a hack to avoid this problem.
Thank you @jbyuki!
Nice one!
Yes, this is an on-going issue that needs better thought. Leaving it open will remind me/others that it's a problem that needs solving. Glad that it worked in your case for now.
I just ran into this very same issue the other day. Thanks for the recommendation @ramboman.
A more elegant way to debug configuration files has been added. The help file goes into more details on how it is done.
I will close this for now as a more permanent solution has been now added to the plugin.
Here it is in action.
https://github.com/user-attachments/assets/ea3e5a55-f6f9-4149-a94f-c444b7e8f4e5
I would like to debug some code, in my neovim configuration, that executes at the start of
nvim
.Setup
I made and reduced this setup solely for the purpose of reproducing the problem
OS: Debian 12 NVIM version: v0.10.0 NVIM package manager: lazy.nvim
~/.config/nvim/init.lua
:~/.config/nvim/lua/do_something.lua
:The general idea
I added a debug code (
-- Debug
) at the beginning of~/.config/nvim/init.lua
. I would like this code to launchosv
ifnvim
was started with the environment variableNVIM_DEBUG
equal"y"
. Right afterosv
is launched,nvim
has to wait for a key press, so I have the time to setup the debugger on the othernvim
. After I press any key on the debuggednvim
, it has to continue its execution until it reaches a breakpoint.How to reproduce the problem
nvim
so it setups everythingnvim
add_some
functionnvim
instance to debug:Expected course of action
nvim
instance launchsosv
<F4>
in the clientnvim
to open the debug ui<F9>
so thedap
connects to the debuggednvim
nvim
nvim
stops at the break points so I can start debuggingActual course of action:
nvim
prints this error message:Questions
osv
properly at the beginning of a configuration so I can debug it?