navigator.lua
navigator.lua copied to clipboard
[bug] Renaming rhs: expected string|function
Everytime I run rename I get this error message:
Error executing vim.schedule lua callback: vim/keymap.lua:0: rhs: expected string|function, got nil
stack traceback:
[C]: in function 'error'
vim/shared.lua: in function 'validate'
vim/keymap.lua: in function 'set'
[string ":lua"]:53: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
FWIW ignoring the error and continuing seems to work just fine.
Here's my config that I think is relevant:
local lspconfig = require('lspconfig')
local lsp_defaults = lspconfig.util.default_config
local lsp_capabilities = vim.tbl_deep_extend('force', lsp_defaults.capabilities, require('cmp_nvim_lsp').default_capabilities())
local lsp_attach = function(client, bufnr)
local opts = { buffer = bufnr }
require("navigator.dochighlight").documentHighlight(bufnr)
require("navigator.lspclient.highlight").add_highlight()
require("navigator.lspclient.highlight").diagnositc_config_sign() -- [sic]
require('navigator.lspclient.lspkind').init()
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Setup navigator for lsp client
require("navigator.lspclient.mapping").setup({
client = client,
bufnr = bufnr,
})
-- call to show code actions as floating text and gutter icon
local prompt_code_action = function()
require('navigator.codeAction').code_action_prompt(bufnr)
end
-- ray-x/navigator
-- ref: https://github.com/ray-x/navigator.lua/tree/master#default-keymaps
-- ref: https://github.com/ray-x/navigator.lua/blob/master/lua/navigator/lspclient/mapping.lua
-- must override all default mappings for any of them to work
local keymaps = {
{ mode = 'n', key = 'gr', func = require('navigator.reference').async_ref }, -- show references and context (async)
{ mode = 'n', key = '<c-]>', func = require('navigator.definition').definition }, -- goto definition
{ mode = 'n', key = 'gd', func = require('navigator.definition').definition }, -- goto definition
{ mode = 'n', key = 'gD', func = vim.lsp.buf.declaration }, -- goto declaration
{ mode = 'n', key = '<leader>/', func = require('navigator.workspace').workspace_symbol_live }, -- workspace fzf
{ mode = 'n', key = '<C-S-F>', func = require('navigator.workspace').workspace_symbol_live }, -- workspace fzf
{ mode = 'n', key = 'g0', func = require('navigator.symbols').document_symbols }, -- document's symbols
{ mode = 'n', key = '<leader>d', func = vim.lsp.buf.hover }, -- hover window
{ mode = 'n', key = 'K', func = vim.lsp.buf.hover }, -- hover window
{ mode = 'n', key = 'gi', func = vim.lsp.buf.implementation }, -- goto implementation (doesn't always work?)
{ mode = 'n', key = '<Leader>gi', func = vim.lsp.buf.incoming_calls }, -- incoming calls
{ mode = 'n', key = '<Leader>go', func = vim.lsp.buf.outgoing_calls }, -- outgoing calls
{ mode = 'n', key = 'gt', func = vim.lsp.buf.type_definition }, -- goto type definition
{ mode = 'n', key = 'gp', func = require('navigator.definition').definition_preview }, -- hover definition preview
{ mode = 'n', key = 'gP', func = require('navigator.definition').type_definition_preview }, -- hover type definition preview
-- messes up ctrl-hjkl for moving windows
-- { mode = 'n', key = '<c-k>', func = vim.lsp.buf.signature_help }, -- sig help
-- { mode = 'n', key = '<C-S-K>', func = toggle_lsp_signature }, -- sig help
-- { mode = 'i', key = '<C-S-K>', func = toggle_lsp_signature }, -- sig help
{ mode = 'n', key = '<leader>ca', func = vim.lsp.buf.code_action }, -- code action
{ mode = 'n', key = '<leader>cl', func = require('navigator.codelens').run_action }, -- codelens action
{ mode = 'n', key = '<leader>la', func = require('navigator.codelens').run_action }, -- codelens action
{ mode = 'n', key = '<leader>rn', func = require('navigator.rename').rename }, -- rename
{ mode = 'n', key = '<leader>gt', func = require('navigator.treesitter').buf_ts }, -- fzf treesitter symbols
{ mode = 'n', key = '<leader>ts', func = require('navigator.treesitter').buf_ts }, -- fzf treesitter symbols
{ mode = 'n', key = '<leader>ct', func = require('navigator.ctags').ctags }, -- fzf ctags
{ mode = 'n', key = '<leader>ca', func = require('navigator.codeAction').code_action }, -- code action
{ mode = 'v', key = '<leader>ca', func = require('navigator.codeAction').range_code_action }, -- code action
{ mode = 'n', key = '<C-S-C>', func = prompt_code_action }, -- prompt for possible code actions
{ mode = 'v', key = '<C-S-C>', func = prompt_code_action }, -- prompt for possible code actions
{ mode = 'n', key = 'gG', func = require('navigator.diagnostics').show_buf_diagnostics }, -- diagnostics
{ mode = 'n', key = '<leader>G', func = require('navigator.diagnostics').show_buf_diagnostics }, -- diagnostics
{ mode = 'n', key = 'gL', func = require('navigator.diagnostics').show_diagnostics }, -- diagnostics
{ mode = 'n', key = '<leader>L', func = require('navigator.diagnostics').show_diagnostics }, -- diagnostics
-- doesn't work yet in 0.10 nightly, and I don't use these anyways
-- { mode = 'n', key = '<leader>cf', func = vim.lsp.buf.format }, -- format code
-- { mode = 'v', key = '<leader>cf', func = vim.lsp.buf.range_formatting }, -- format code (visual range)
-- { mode = 'n', key = '<leader>fc', func = vim.lsp.buf.format }, -- format code
-- { mode = 'v', key = '<leader>fc', func = vim.lsp.buf.range_formatting }, -- format code (visual range)
}
for _, km in pairs(keymaps) do
vim.keymap.set(km.mode, km.key, km.func, opts)
end
end
Failed to reproduce with the following init.lua
Do other keymaps have similar issues? I feel might be related to lazyloading.
vim.cmd([[set runtimepath=$VIMRUNTIME]])
local uv = vim.uv or vim.loop
local os_name = uv.os_uname().sysname
local is_windows = os_name == 'Windows' or os_name == 'Windows_NT'
local package_root = '/tmp/nvim/lazy'
local sep = '/'
if is_windows then
local tmp = os.getenv('TEMP')
vim.cmd('set packpath=' .. tmp .. '\\nvim\\lazy')
package_root = tmp .. '\\nvim\\lazy'
sep = '\\'
else
vim.cmd([[set packpath=/tmp/nvim/lazy]])
end
local plugin_folder = function()
local host = os.getenv('HOST_NAME')
if host and (host:find('Ray') or host:find('ray')) then
return [[~/github/ray-x]] -- vim.fn.expand("$HOME") .. '/github/'
else
return ''
end
end
local lazypath = package_root .. sep .. 'lazy.nvim'
if not uv.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'https://github.com/folke/lazy.nvim.git',
'--branch=stable', -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local function load_plugins()
return {
{
'nvim-treesitter/nvim-treesitter',
config = function()
require('nvim-treesitter.configs').setup({
ensure_installed = { 'go' },
highlight = { enable = true },
})
end,
build = ':TSUpdate',
},
{ 'neovim/nvim-lspconfig' },
{ 'ray-x/lsp_signature.nvim', dev = (plugin_folder() ~= '') },
{
'ray-x/navigator.lua',
dev = (plugin_folder() ~= ''),
-- '~/github/ray-x/navigator.lua',
dependencies = { 'ray-x/guihua.lua', build = 'cd lua/fzy && make' },
config = function()
require('navigator').setup({
keymaps = {
{
key = '<Leader>rn',
func = require('navigator.rename').rename,
desc = 'rename',
},
},
lsp = {
-- disable_lsp = { 'rust_analyzer', 'clangd' },
},
})
end,
},
{
'hrsh7th/nvim-cmp',
dependencies = {
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
},
config = function()
-- Add additional capabilities supported by nvim-cmp
local cmp = require('cmp')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
}),
sources = {
{ name = 'nvim_lsp' },
},
})
end,
},
}
end
local opts = {
root = package_root, -- directory where plugins will be installed
default = { lazy = true },
dev = {
-- directory where you store your local plugin projects
path = plugin_folder(),
},
}
require('lazy').setup(load_plugins(), opts)
vim.cmd('colorscheme murphy')
I'm not sure there are other keymaps with issues. I tried removing the lazy loading using on_attach a while back, but I didn't notice a change.
I've seen this for quite a while and have assumed that it's something in my config. I'm mainly reporting here because I'm looking for help/ideas debugging this.
Could you help point me to the code that looks up the keymaps?
I think one of the function you trying to set keybinding is nil (maybe because of lazy loading etc) You can simply modify your config and do this
for _, km in pairs(keymaps) do
print('loading ' .. km.key, km.func)
vim.keymap.set(km.mode, km.key, km.func, opts)
end
and check which key failed to load.