Skip to content

fix(tsinjector): pass lnum to line_parser - #2633

Merged
phanen merged 1 commit into
mainfrom
ts-lnum
Aug 5, 2026
Merged

fix(tsinjector): pass lnum to line_parser#2633
phanen merged 1 commit into
mainfrom
ts-lnum

Conversation

@phanen

@phanen phanen commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

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 optional line number information, enabling custom parsers to perform more contextual text processing.
    • Existing parsing behavior remains unchanged for current configurations.

@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cfd49b84-90a6-43e8-a472-06d09160556e

📥 Commits

Reviewing files that changed from the base of the PR and between 28440c7 and 71f00dd.

📒 Files selected for processing (3)
  • lua/fzf-lua/defaults.lua
  • lua/fzf-lua/types.lua
  • lua/fzf-lua/win/tsinjector.lua
🚧 Files skipped from review as they are similar to previous changes (2)
  • lua/fzf-lua/types.lua
  • lua/fzf-lua/win/tsinjector.lua

📝 Walkthrough

Walkthrough

The shared Tree-sitter parser callback type now accepts an optional line number. M.attach passes the current line index to custom parsers, and the tags picker callback accepts the new argument.

Changes

Tree-sitter line parser

Layer / File(s) Summary
Add line number to parser callback
lua/fzf-lua/types.lua, lua/fzf-lua/win/tsinjector.lua, lua/fzf-lua/defaults.lua
The shared lineParser alias accepts an optional integer line number. _treesitter and M.attach use this alias. M.attach passes the current line index to custom parsers. The tags picker callback accepts the additional argument.

Estimated code review effort: 2 (Simple) | ~8 minutes

Possibly related PRs

Suggested reviewers: ibhagwan

🚥 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 clearly describes the main change: passing the line number to the line parser.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 thread lua/fzf-lua/win/tsinjector.lua
Comment thread lua/fzf-lua/win/tsinjector.lua Outdated
@phanen

phanen commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator Author

-> Fix 2633-1 -> #2632

This is a hack but not sure if there better idea
Related: #1731 (comment)

@shyun3

shyun3 commented Aug 4, 2026

Copy link
Copy Markdown

Just following up on this since I'm interested in fixing #2632. Are the lint failures the only blockers preventing this from being merged?

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@phanen

phanen commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

I just wonder is there any better way to do it. But should be no problem to change it. This is still a internal opts with few users. I'll resolve the lint when available.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@phanen
phanen requested a review from ibhagwan August 5, 2026 01:42
@phanen

phanen commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

When query is at the first line:

          _treesitter = function(line, lnum)
            if lnum == 1 then return end
            return 'foo.vim', nil, line
          end,

cc @ibhagwan for review, not sure why but I could not merge it without review

@ibhagwan

ibhagwan commented Aug 5, 2026

Copy link
Copy Markdown
Owner

cc @ibhagwan for review, not sure why but I could not merge it without review

I disabled direct push to master enabled only via PRs - not sure why it wants my review, I’ll take a look at the ruleset.

@ibhagwan

ibhagwan commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Changed it to required reviewers 0 - can you see if you can merge again?

@ibhagwan

ibhagwan commented Aug 5, 2026

Copy link
Copy Markdown
Owner

I approved this, not sure why it still needed my review after setting required reviewers to 0, maybe in a new PR or resubmitted commit it will work (since I was already required to review).

@ibhagwan

ibhagwan commented Aug 5, 2026

Copy link
Copy Markdown
Owner

I think I fixed it now, no reviews should be required

@phanen
phanen merged commit c46b51a into main Aug 5, 2026
16 of 17 checks passed
@phanen
phanen deleted the ts-lnum branch August 5, 2026 09:11
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.

3 participants