Skip to content

v2: spurious 'No action found for keymap' warning for function-valued window keymaps on re-registration #506

Closed

Description

@wzj-zz

Bug

Function-valued window keymaps (e.g. a custom callback in keymap.output_window) emit a spurious warning every time window keymaps are re-processed for a buffer that already has the mapping:

No action found for keymap: <M-n> -> function: 0x...

This happens on every panel toggle (the output buffer survives, the window is recreated, setup_panel_keymaps re-runs setup_window_keymaps(..., preserve_existing=true) on the same buffer), so the warning fires repeatedly during normal use.

Repro

require('opencode').setup({
  keymap = {
    output_window = {
      ['<M-n>'] = { function() end, mode = 'n', desc = 'custom' },
    },
  },
})

Then open the opencode panel, close it, and open it again — the warning appears on the second open. Equivalently, calling require('opencode.keymap').setup_window_keymaps(cfg, buf, true) twice with the same buffer reproduces it: first call is silent, second warns.

Root cause

In lua/opencode/keymap.lua, process_keymap_entry (lines 86-93):

if callback and #modes > 0 then
  ...
  vim.keymap.set(modes, key_binding, callback, opts)
elseif type(func_name) ~= 'string' then
  vim.notify(string.format('No action found for keymap: %s -> %s', key_binding, func_name), vim.log.levels.WARN)
end

With preserve_existing, modes for which the buffer already has the mapping are filtered out, leaving modes = {} on re-processing. For function-valued entries resolve_callback always returns the function, so callback is non-nil and the elseif is reached purely because #modes == 0 — i.e. "already registered, nothing to do", not "no action found". String actions are spared only because of the type(func_name) ~= 'string' check.

In fact the branch is only reachable for function values with empty modes (string actions either resolve or warn earlier in resolve_callback), so it only ever produces false positives.

Suggested fix

Skip silently when nothing is left to do — only warn when the callback could not be resolved:

if callback and #modes > 0 then
  ...
  vim.keymap.set(modes, key_binding, callback, opts)
elseif not callback and type(func_name) ~= 'string' then
  vim.notify(...)
end

Environment

  • opencode.nvim v2 branch @ e4ec704
  • Neovim v0.12.5, Windows 11

Activity

  1. sudo-tee commented on Sep 29, 2026

    @sudo-tee
    Owner

    @wzj-zz

    The issue should be fixed now I rebased main branch which had fixed the issue

    see related MR #500

    Let me know if it works for you

  2. wzj-zz commented on Sep 30, 2026

    @wzj-zz
    ContributorAuthor

    Confirmed fixed on latest v2 (55c994d). Calling setup_window_keymaps twice with a function-valued keymap no longer produces the spurious warning — the mapping registers once and re-registration is silent. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions