-
-
Notifications
You must be signed in to change notification settings - Fork 104
Description
I'm experiencing persistent issues with gp.nvim where keymaps and commands (like GPHealth) are not being loaded, despite successful plugin installation and seemingly correct configuration. I'm using Lazy.nvim as my plugin manager.
I suspect there's a caching or scope issue preventing the keymaps and commands from registering correctly. The core problem is that the gp module being required in the keymap function appears to be a different instance than the one where setup is called, leading to nil values when accessing configuration options.
Here's a simplified gp_nvim.lua configuration that reproduces the issue:
-- Require the gp module at the top of the file
local gp = require("gp")
-- Global variable to store the gp module
_G.gp_module = gp
return {
{
"robitx/gp.nvim",
cmd = { "Gp" }, -- Keep only one command for testing
event = "VeryLazy",
init = function()
require("gp") -- load the plugin
end,
opts = {
prompts = {
ExplainCode = {
prompt = "Explain this code",
agent = "NIPRGPT Sonnet 3.7",
target = "new_buffer",
},
},
},
keys = {
{
lhs = "<leader>ae",
rhs = function()
print("gp module loaded")
print(vim.inspect(_G.gp_module))
print(vim.inspect(_G.gp_module.config))
-- Access the opts table from gp._.cache.opts
local prompt_config = _G.gp_module._.cache.opts.prompts.ExplainCode
if prompt_config then
print("Prompt found: " .. prompt_config.prompt)
else
print("Prompt not found")
end
end,
mode = "v",
desc = "Explain Code (Test)",
},
},
config = function(plugin_config)
gp.setup(plugin_config) -- Use the gp module required at the top
print("config function executed")
end,
},
}
Steps to reproduce:
- Install gp.nvim using Lazy.nvim with the above gp_nvim.lua configuration.
- Open Neovim.
- Select some text in visual mode.
- Press ae.
Expected behavior:
The print statements within the keymap function should execute, and the "Prompt found" message should appear if the configuration is loaded correctly.
Actual behavior:
The ae keymap is not recognized, and the GPHealth command is also not recognized. The :messages output (if the keymap were working) would likely show that gp._ is nil within the keymap function.
Here's a summary of what I've already tried:
- Confirmed successful plugin installation: gp.nvim is installed and loaded by Lazy.nvim.
- Tried various event settings: BufReadPost, VeryLazy - none consistently load keymaps/commands.
- Called require("gp").setup(plugin_config) in config function: Passing opts to setup does populate gp.config (verified with vim.inspect(gp.config) after setup is called).
- Attempted to load commands with prepare_commands(): This command never seemed to be recognized.
- Accessed configuration options using various paths: gp.config, gp.config.opts, gp._.cache.opts - all attempts fail within the keymaps.
- Global variable approach: Storing opts in a global variable didn't resolve the issue.
- Debugging: Extensive use of vim.inspect() to track module state.
Any guidance on how to ensure the keymaps and commands are loaded correctly would be greatly appreciated. I can provide my full Neovim configuration if needed. The provided gp_nvim.lua should be sufficient to reproduce the core problem.