Skip to content

fix(keymaps): resume precompile module path is possible#2676

Merged
phanen merged 1 commit intomainfrom
precompile-module-path
Apr 20, 2026
Merged

fix(keymaps): resume precompile module path is possible#2676
phanen merged 1 commit intomainfrom
precompile-module-path

Conversation

@phanen
Copy link
Copy Markdown
Collaborator

@phanen phanen commented Apr 17, 2026

Fix #2674

https://github.com/neovim/neovim/blob/64d55b74d83d566975e269bed0810d9008119ddf/src/nvim/lua/executor.c#L671-L680

Summary by CodeRabbit

  • Bug Fixes
    • Refined keymapping source detection with enhanced validation for more reliable results.
    • Improved resolution of Neovim's internal Lua module sources to correctly map them to their runtime file paths, providing better source file tracking for keymaps.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

The M.keymap_to_entry function in path.lua now properly handles Neovim-internal keymaps by detecting vim/... Lua sources and resolving them to their actual runtime paths, while adding validation checks for debug information before returning file paths.

Changes

Cohort / File(s) Summary
Path Resolution for Keymaps
lua/fzf-lua/path.lua
Enhanced M.keymap_to_entry to use debug.getinfo(vmap.callback, "Sl") for targeted debug info retrieval. Added validation gating on info.source and info.linedefined > 0. Implemented special resolution logic for Neovim-internal vim/... Lua sources via package.preload mapping to absolute VIMRUNTIME paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #2667: Also modifies M.keymap_to_entry and its handling of vmap.callback debug information and source/line resolution logic.

Poem

🐰 A hop through the keymaps so dear,
Where Neovim's secrets appear—
No more missing files in sight,
Internal paths now resolved right,
The picker hops with glee and cheer! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title partially describes the change - it mentions handling 'precompile module path' but lacks specificity about what the actual fix does (improving debug info extraction for keymaps).
Linked Issues check ✅ Passed The changes directly address issue #2674 by improving debug.getinfo handling to correctly extract and resolve precompiled module paths, enabling the keymaps picker to resume without missing file errors.
Out of Scope Changes check ✅ Passed All changes to lua/fzf-lua/path.lua focus on fixing the keymap entry extraction logic to handle precompiled modules, which is directly scoped to resolving the missing file error in issue #2674.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch precompile-module-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/fzf-lua/path.lua`:
- Around line 688-693: The returned entry lacks the required "stripped" field,
breaking file actions that expect "entry.stripped" (see actions.lua:656 and
entry_to_file). In the function that builds the entry (the code returning { path
= source, line = info.linedefined } in path.lua), add a stripped field formatted
as "path:line" (e.g., source .. ":" .. tostring(info.linedefined)) and ensure
any other branches that set path also set stripped the same way so consumers
like keymap_to_entry / entry_to_file receive a proper "stripped" string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6f5a04e-97be-4404-b654-189d680a0192

📥 Commits

Reviewing files that changed from the base of the PR and between 83f7195 and e442bb2.

📒 Files selected for processing (1)
  • lua/fzf-lua/path.lua

Comment thread lua/fzf-lua/path.lua
@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Apr 17, 2026

luajit -b -s a.lua b.lua
loadstring(io.open('b.lua'):read('*a'), '@a.lua')()

linedefined is still missing

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
lua/fzf-lua/path.lua (2)

688-693: ⚠️ Potential issue | 🟠 Major

Populate stripped when returning a keymap file target.

This branch still returns path without stripped, but lua/fzf-lua/actions.lua:650-660 passes entry.stripped into file_edit/file_split/file_vsplit/file_tabedit. Build a path:line string here so callback-backed keymaps remain actionable.

Proposed fix
       if source:match("vim/") and package.preload[source:gsub("%.lua$", ""):gsub("/", ".")] then
         source = vim.env.VIMRUNTIME .. "/lua/" .. source
       end
-      return { path = source, line = info.linedefined }
+      local line = info.linedefined > 0 and info.linedefined or 1
+      return {
+        path = source,
+        line = line,
+        stripped = ("%s:%d"):format(source, line),
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/path.lua` around lines 688 - 693, The returned table from this
branch sets only path and line but not stripped, so callback-backed keymaps
break when actions.lua expects entry.stripped; update the return to include
stripped built from the resolved source and info.linedefined (e.g., source ..
":" .. info.linedefined) so that entry.stripped is populated for downstream uses
in file_edit/file_split/file_vsplit/file_tabedit.

688-693: ⚠️ Potential issue | 🟠 Major

Populate stripped when returning a keymap file target.

This branch still returns path without stripped, but lua/fzf-lua/actions.lua:650-660 passes entry.stripped into file_edit/file_split/file_vsplit/file_tabedit. Build a path:line string here so callback-backed keymaps remain actionable.

Proposed fix
       if source:match("vim/") and package.preload[source:gsub("%.lua$", ""):gsub("/", ".")] then
         source = vim.env.VIMRUNTIME .. "/lua/" .. source
       end
-      return { path = source, line = info.linedefined }
+      local line = info.linedefined > 0 and info.linedefined or 1
+      return {
+        path = source,
+        line = line,
+        stripped = ("%s:%d"):format(source, line),
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/path.lua` around lines 688 - 693, The branch that handles runtime
vim lua files currently returns { path = source, line = info.linedefined } but
does not set the stripped field used by callbacks; update the return value in
that branch (the block using source:match("vim/") and package.preload) to
include stripped constructed as a "path:line" string (e.g., source .. ":" ..
info.linedefined) so that downstream callers like
file_edit/file_split/file_vsplit/file_tabedit (which use entry.stripped) receive
the actionable target.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@lua/fzf-lua/path.lua`:
- Around line 688-693: The returned table from this branch sets only path and
line but not stripped, so callback-backed keymaps break when actions.lua expects
entry.stripped; update the return to include stripped built from the resolved
source and info.linedefined (e.g., source .. ":" .. info.linedefined) so that
entry.stripped is populated for downstream uses in
file_edit/file_split/file_vsplit/file_tabedit.
- Around line 688-693: The branch that handles runtime vim lua files currently
returns { path = source, line = info.linedefined } but does not set the stripped
field used by callbacks; update the return value in that branch (the block using
source:match("vim/") and package.preload) to include stripped constructed as a
"path:line" string (e.g., source .. ":" .. info.linedefined) so that downstream
callers like file_edit/file_split/file_vsplit/file_tabedit (which use
entry.stripped) receive the actionable target.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6235fef-f900-412d-8878-ebfbdca54b97

📥 Commits

Reviewing files that changed from the base of the PR and between e442bb2 and 0807c43.

📒 Files selected for processing (3)
  • lua/fzf-lua/path.lua
  • lua/fzf-lua/profiles/hide.lua
  • lua/fzf-lua/providers/nvim.lua
✅ Files skipped from review due to trivial changes (1)
  • lua/fzf-lua/profiles/hide.lua

@phanen phanen marked this pull request as draft April 18, 2026 08:20
@phanen phanen force-pushed the precompile-module-path branch from 0807c43 to 376d760 Compare April 20, 2026 11:59
@phanen phanen force-pushed the precompile-module-path branch from 376d760 to 36ff649 Compare April 20, 2026 12:01
@phanen phanen marked this pull request as ready for review April 20, 2026 12:01
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
lua/fzf-lua/path.lua (1)

686-694: ⚠️ Potential issue | 🟠 Major

Missing stripped field will still break keymap_{edit,split,vsplit,tabedit} actions; also anchor the vim/ match.

  1. actions.lua:654-660 passes entry.stripped into file_<fname>; since this return path (and the verb map fallback at line 699) only sets path/line, consumers receive { nil } and the action silently no-ops. This was raised on the previous revision and is unresolved.
  2. source:match("vim/") on line 690 is unanchored — any path containing vim/ anywhere (e.g., a user plugin at ~/.config/nvim/pack/.../vim/foo.lua) will hit the VIMRUNTIME rewrite if a same-named key happens to exist in package.preload. Per the linked executor.c behavior, these chunknames start with vim/, so anchor it.
Proposed fix
   if vmap.callback then
     local info = debug.getinfo(vmap.callback, "Sl")
     if info and info.source and info.linedefined and info.linedefined > 0 then
       local source = info.source:gsub("^@", "")
       -- https://github.com/neovim/neovim/blob/64d55b74d83d566975e269bed0810d9008119ddf/src/nvim/lua/executor.c#L671-L680
-      if source:match("vim/") and package.preload[source:gsub("%.lua$", ""):gsub("/", ".")] then
+      if source:match("^vim/") and package.preload[source:gsub("%.lua$", ""):gsub("/", ".")] then
         source = vim.env.VIMRUNTIME .. "/lua/" .. source .. ".lua"
       end
-      return { path = source, line = info.linedefined }
+      return {
+        path = source,
+        line = info.linedefined,
+        stripped = ("%s:%d"):format(source, info.linedefined),
+      }
     end
   end
   local cmd = ("verb %smap %s"):format(mode, keymap)
   local output = vim.split(vim.api.nvim_exec2(cmd, { output = true }).output, "\n")
   local file, lnum = (output[`#output`] or ""):match("Last set from (.-) line (%d+)")
-  if file and lnum then return { path = vim.fs.normalize(file), line = utils.tointeger(lnum) or 1 } end
+  if file and lnum then
+    file = vim.fs.normalize(file)
+    lnum = utils.tointeger(lnum) or 1
+    return { path = file, line = lnum, stripped = ("%s:%d"):format(file, lnum) }
+  end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/path.lua` around lines 686 - 694, The returned table from the
debug-info branch in path.lua currently only sets path and line which causes
consumers like the file_<fname> actions in actions.lua (which expect
entry.stripped) to no-op; update the return to include a stripped field (the
basename or the appropriate stripped value used elsewhere) so callers receive
entry.stripped, and also tighten the runtime rewrite match by anchoring the
pattern to "^vim/" (i.e., change source:match("vim/") to source:match("^vim/"))
so only chunknames that start with "vim/" are rewritten to VIMRUNTIME.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@lua/fzf-lua/path.lua`:
- Around line 686-694: The returned table from the debug-info branch in path.lua
currently only sets path and line which causes consumers like the file_<fname>
actions in actions.lua (which expect entry.stripped) to no-op; update the return
to include a stripped field (the basename or the appropriate stripped value used
elsewhere) so callers receive entry.stripped, and also tighten the runtime
rewrite match by anchoring the pattern to "^vim/" (i.e., change
source:match("vim/") to source:match("^vim/")) so only chunknames that start
with "vim/" are rewritten to VIMRUNTIME.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 54e1e3fd-37a2-403f-9882-95cd2596fb38

📥 Commits

Reviewing files that changed from the base of the PR and between 0807c43 and 36ff649.

📒 Files selected for processing (1)
  • lua/fzf-lua/path.lua

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Apr 20, 2026

This will automatically be fixed (hopefully when my upstream bytecode fix PR merged).
It won't change current behavior and we can do nothing else we can do without upstream change so let me to merge it.

@phanen phanen merged commit 423533d into main Apr 20, 2026
10 of 11 checks passed
@phanen phanen deleted the precompile-module-path branch April 20, 2026 12:11
@ibhagwan
Copy link
Copy Markdown
Owner

Tysm @phanen!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Missing file error when looking at keymaps picker

2 participants