Skip to content

fix(tsinjector): pass lnum to line_parser#2633

Open
phanen wants to merge 1 commit intomainfrom
ts-lnum
Open

fix(tsinjector): pass lnum to line_parser#2633
phanen wants to merge 1 commit intomainfrom
ts-lnum

Conversation

@phanen
Copy link
Copy Markdown
Collaborator

@phanen phanen commented Mar 27, 2026

It's non trivial to determine where the "prompt" line is.
When we have reverse/default layout, info/header/footer border

This is a workaround for user find the prompt hl annoying:

opts.command_history._treesitter = function(line, lnum)
  if lnum == 1 then return end
  return line:match("(.-):?(%d+)[: ](.+)$")
end

Summary by CodeRabbit

  • Enhancements
    • Treesitter callbacks now receive line number information as an additional parameter, enabling custom parsers to perform more contextual text processing.

It's non trivial to determine where the "prompt" line is.
When we have reverse/default layout, info/header/footer border

This is a workaround for user find the prompt hl annoying:

opts.command_history._treesitter = function(line, lnum)
  if lnum == 1 then return end
  return line:match("(.-):?(%d+)[: ](.+)$")
end
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The changes extend the _treesitter callback function signature to accept an additional line number argument. The type annotation in types.lua is updated to reflect this new parameter, and the corresponding implementation in tsinjector.lua is modified to pass the current line index when invoking the parser.

Changes

Cohort / File(s) Summary
Type annotation update
lua/fzf-lua/types.lua
Updated _treesitter callback type to include lnum: integer parameter: (fun(line: string, lnum: integer): ...) instead of (fun(line: string): ...)
Parser invocation
lua/fzf-lua/win/tsinjector.lua
Modified default parser signature to accept the line number argument and updated the invocation to pass the current line index i when calling line_parser(line:sub(min_col), i)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A line number hops into view,
The parser now knows what to do!
Each line gets its place,
In the treesitter's embrace—
Row by row, making syntax shine through! 🌳✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: passing the line number parameter to the line_parser function in the tsinjector.

✏️ 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 ts-lnum

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lua/fzf-lua/win/tsinjector.lua (1)

130-131: ⚠️ Potential issue | 🟡 Minor

Update parameter type annotation for line_parser.

The line_parser parameter type annotation at line 130 also needs updating to include the lnum parameter. This will resolve the remaining [redundant-parameter] warning at line 174.

🔧 Proposed fix
----@param line_parser (fun(line: string):string?,string?,string?,string?)|boolean?
+---@param line_parser (fun(line: string, lnum: integer):string?,string?,string?,string?)|boolean?
 ---@return function detach
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/win/tsinjector.lua` around lines 130 - 131, Update the type
annotation for the parameter named line_parser in tsinjector.lua to include the
lnum argument (e.g., change (fun(line:
string):string?,string?,string?,string?)|boolean? to a signature that accepts
(line: string, lnum: number) and returns the four optional strings or nil);
locate the annotation above the function that declares/detects line_parser and
add the lnum parameter to match the runtime usage (this will remove the
[redundant-parameter] warning at the call site around line 174).
🤖 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/win/tsinjector.lua`:
- Around line 135-136: The type annotation for default_line_parser is out of
sync with its implementation and types.lua: update the local annotation for
default_line_parser to include the second parameter (lnum) so the signature
matches the actual function (e.g., fun(line: string, lnum: number):
string?,string?,string?,string?) and remove the redundant-parameter warning;
target the annotation immediately above the default_line_parser function to
correct the mismatch.
- Line 174: Update the _treesitter parser functions to accept the second ignored
parameter by changing their signatures from function(line) to function(line, _);
specifically modify the _treesitter implementations named git_log,
command_history, and search_history (the functions currently declared with a
single parameter) so they match the default tsinjector.lua signature
function(line, _) and thereby explicitly accept the lnum/second argument passed
by line_parser(line:sub(min_col), i).

---

Outside diff comments:
In `@lua/fzf-lua/win/tsinjector.lua`:
- Around line 130-131: Update the type annotation for the parameter named
line_parser in tsinjector.lua to include the lnum argument (e.g., change
(fun(line: string):string?,string?,string?,string?)|boolean? to a signature that
accepts (line: string, lnum: number) and returns the four optional strings or
nil); locate the annotation above the function that declares/detects line_parser
and add the lnum parameter to match the runtime usage (this will remove the
[redundant-parameter] warning at the call site around line 174).
🪄 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: 36a25265-8532-4dd9-bb2f-538977ff4db4

📥 Commits

Reviewing files that changed from the base of the PR and between bde73a6 and f70e87f.

📒 Files selected for processing (2)
  • lua/fzf-lua/types.lua
  • lua/fzf-lua/win/tsinjector.lua

Comment on lines 135 to +136
---@type fun(line: string):string?,string?,string?,string?
local default_line_parser = function(line) return line:match("(.-):?(%d+)[: ](.+)$") end
local default_line_parser = function(line, _) return line:match("(.-):?(%d+)[: ](.+)$") end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Type annotation mismatch causes pipeline warnings.

The local type annotation at line 135 still declares the old signature without lnum, while the actual function at line 136 now accepts two parameters. This is the root cause of the Lua-language-server [redundant-parameter] warnings in the pipeline.

Update the type annotation to match the new signature defined in types.lua:

🔧 Proposed fix
-  ---@type fun(line: string):string?,string?,string?,string?
+  ---@type fun(line: string, lnum: integer):string?,string?,string?,string?
   local default_line_parser = function(line, _) return line:match("(.-):?(%d+)[: ](.+)$") end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
---@type fun(line: string):string?,string?,string?,string?
local default_line_parser = function(line) return line:match("(.-):?(%d+)[: ](.+)$") end
local default_line_parser = function(line, _) return line:match("(.-):?(%d+)[: ](.+)$") end
---@type fun(line: string, lnum: integer):string?,string?,string?,string?
local default_line_parser = function(line, _) return line:match("(.-):?(%d+)[: ](.+)$") end
🧰 Tools
🪛 GitHub Actions: Lint

[warning] 136-136: Lua-language-server: [redundant-parameter] function expects maximum of 1 argument(s) but receives 2 in function(line, _) return line:match(...).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/win/tsinjector.lua` around lines 135 - 136, The type annotation
for default_line_parser is out of sync with its implementation and types.lua:
update the local annotation for default_line_parser to include the second
parameter (lnum) so the signature matches the actual function (e.g., fun(line:
string, lnum: number): string?,string?,string?,string?) and remove the
redundant-parameter warning; target the annotation immediately above the
default_line_parser function to correct the mismatch.

-- line:col:text (grep_curbuf)
-- line<U+00A0>text (lines|blines)
local filepath, _lnum, text, _ft = line_parser(line:sub(min_col))
local filepath, _lnum, text, _ft = line_parser(line:sub(min_col), i)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all _treesitter function definitions to verify they handle the new signature
rg -n '_treesitter\s*=' --type=lua -A2

Repository: ibhagwan/fzf-lua

Length of output: 2898


🏁 Script executed:

# Check the context around line 174 in tsinjector.lua
sed -n '160,185p' lua/fzf-lua/win/tsinjector.lua

Repository: ibhagwan/fzf-lua

Length of output: 1270


🏁 Script executed:

# Find where line_parser is defined/assigned
rg -n 'line_parser\s*=' --type=lua -B3 -A3 lua/fzf-lua/win/tsinjector.lua

Repository: ibhagwan/fzf-lua

Length of output: 541


🏁 Script executed:

# Find all _treesitter function definitions with their return values
rg -n 'treesitter\s*=\s*function' --type=lua -A3

Repository: ibhagwan/fzf-lua

Length of output: 1262


Update existing _treesitter implementations to explicitly accept the second parameter.

The call site now passes lnum as the second argument to line_parser: line_parser(line:sub(min_col), i). The default implementation in tsinjector.lua already accepts this with function(line, _). However, existing _treesitter implementations in defaults.lua (e.g., git_log at line 812, command_history at line 1909, search_history at line 1928) only declare a single line parameter.

While Lua silently ignores extra arguments and these will continue to work, update them to function(line, _) for consistency with the API contract and the default implementation.

🧰 Tools
🪛 GitHub Actions: Lint

[warning] 174-174: Lua-language-server: [redundant-parameter] function expects maximum of 1 argument(s) but receives 2 in line_parser(line:sub(min_col), i).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/fzf-lua/win/tsinjector.lua` at line 174, Update the _treesitter parser
functions to accept the second ignored parameter by changing their signatures
from function(line) to function(line, _); specifically modify the _treesitter
implementations named git_log, command_history, and search_history (the
functions currently declared with a single parameter) so they match the default
tsinjector.lua signature function(line, _) and thereby explicitly accept the
lnum/second argument passed by line_parser(line:sub(min_col), i).

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.

1 participant