echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

Expected string|function, got nil #965

Closed daUnknownCoder closed 3 weeks ago

daUnknownCoder commented 3 weeks ago

Contributing guidelines

Module(s)

mini.files

Description

Error detected while processing User Autocommands for "MiniFilesBufferCreate":
Error executing 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'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:30: in function 'map_buf'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37: in function <.../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:28>
    [C]: in function 'nvim_exec_autocmds'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:2619: in function 'trigger_event'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1890: in function 'buffer_create'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1756: in function 'view_ensure_proper'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1529: in function 'explorer_refresh_depth_window'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1321: in function 'explorer_refresh'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1836: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
Error executing 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'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:30: in function 'map_buf'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37: in function <.../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:28>
    [C]: in function 'nvim_exec_autocmds'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:2619: in function 'trigger_event'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1890: in function 'buffer_create'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1756: in function 'view_ensure_proper'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1529: in function 'explorer_refresh_depth_window'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1321: in function 'explorer_refresh'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:714: in function 'open'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:49: in function <.../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:47>
Error executing 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'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:30: in function 'map_buf'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37: in function <.../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:28>
    [C]: in function 'nvim_exec_autocmds'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:2619: in function 'trigger_event'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1890: in function 'buffer_create'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1756: in function 'view_ensure_proper'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1529: in function 'explorer_refresh_depth_window'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:1321: in function 'explorer_refresh'
    ...ocal/share/NeutronVim/lazy/mini.files/lua/mini/files.lua:714: in function 'open'
    .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:49: in function <.../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:47>

Neovim version

0.10.0

Steps to reproduce

minimal config:

return {
  "echasnovski/mini.files",
  version = false,
  config = true,
}

the issue stays the same no matter which config i use

my current config (click) ```lua return { "echasnovski/mini.files", version = false, config = function() local files_ok, files = pcall(require, "mini.files") if not files_ok then print("mini.files not found!") end files.setup({ mappings = { go_in = "", go_in_plus = "L", go_out = "H", go_out_plus = "", reset = "", show_help = "g?", }, windows = { preview = true, width_preview = 40 }, }) local go_in_plus = function() for _ = 1, vim.v.count1 do files.go_in({ close_on_file = true }) end end vim.api.nvim_create_autocmd("User", { pattern = "MiniFilesBufferCreate", callback = function(args) local map_buf = function(lhs, rhs) vim.keymap.set("n", lhs, rhs, { buffer = args.data.buf_id }) end map_buf("", go_in_plus) map_buf("", go_in_plus) map_buf("", files.go_out) map_buf("", files.go_out_plus) map_buf("", files.close) map_buf("q", files.close) end, }) end, keys = { { "", function() if not require("mini.files").close() then require("mini.files").open() end end, desc = "File Manipulator", mode = "n", }, }, } ```

Expected behavior

with my current config, <esc> doesnt work like it doesnt do anything

Actual behavior

image

image

echasnovski commented 3 weeks ago

The problem is in line map_buf("<Left>", files.go_out_plus) (which is what .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37 should point to). There is no function go_out_plus exported from 'mini.files', you'd have to write a custom wrapper similar to go_in_plus.

daUnknownCoder commented 3 weeks ago

The problem is in line map_buf("<Left>", files.go_out_plus) (which is what .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37 should point to). There is no function go_out_plus exported from 'mini.files', you'd have to write a custom wrapper similar to go_in_plus.

i also stated that the issue remains even if i use config = true and yeah switching back to go_out didnt solve it either

echasnovski commented 3 weeks ago

The problem is in line map_buf("<Left>", files.go_out_plus) (which is what .../NeutronVim/lua/NeutronVim/plugins/Editor/mini-files.lua:37 should point to). There is no function go_out_plus exported from 'mini.files', you'd have to write a custom wrapper similar to go_in_plus.

i also stated that the issue remains even if i use config = true and yeah switching back to go_out didnt solve it either

The following config (which is essentially the config entry but commented out go_out_plus usage) works without an error:

Working config ```lua -- Clone 'mini.nvim' manually in a way that it gets managed by 'mini.deps' local path_package = vim.fn.stdpath("data") .. "/site/" local mini_path = path_package .. "pack/deps/start/mini.nvim" if not vim.loop.fs_stat(mini_path) then vim.cmd('echo "Installing `mini.nvim`" | redraw') local clone_cmd = { "git", "clone", "--filter=blob:none", "https://github.com/echasnovski/mini.nvim", mini_path } vim.fn.system(clone_cmd) vim.cmd("packadd mini.nvim | helptags ALL") vim.cmd('echo "Installed `mini.nvim`" | redraw') end local files_ok, files = pcall(require, "mini.files") if not files_ok then print("mini.files not found!") end files.setup({ mappings = { go_in = "", go_in_plus = "L", go_out = "H", go_out_plus = "", reset = "", show_help = "g?", }, windows = { preview = true, width_preview = 40 }, }) local go_in_plus = function() for _ = 1, vim.v.count1 do files.go_in({ close_on_file = true }) end end vim.api.nvim_create_autocmd("User", { pattern = "MiniFilesBufferCreate", callback = function(args) local map_buf = function(lhs, rhs) vim.keymap.set("n", lhs, rhs, { buffer = args.data.buf_id }) end map_buf("", go_in_plus) map_buf("", go_in_plus) map_buf("", files.go_out) -- map_buf("", files.go_out_plus) map_buf("", files.close) map_buf("q", files.close) end, }) ```
daUnknownCoder commented 3 weeks ago

map_buf("<Left>", files.go_out_plus)

i changed it to mappings = { go_out_plus = "<Left>"}, and did a Lazy reload mini.files which didnt work and i had to do a full neovim restart which solved it...