Skip to content

fix: handle line codes with an empty line number - #593

Draft
Enceradeira wants to merge 1 commit into
harrisoncramer:developfrom
Enceradeira:fix/nil-line-code-in-range
Draft

Enceradeira wants to merge 1 commit into
harrisoncramer:developfrom
Enceradeira:fix/nil-line-code-in-range

Conversation

@Enceradeira

Copy link
Copy Markdown

Opening a file in the reviewer that has a multi-line discussion fails in the DiffviewDiffBufWinEnter hook:

gitlab.nvim: Error setting diagnostics: .../gitlab/actions/common.lua:268: attempt to perform arithmetic on local 'new_end_line' (a nil value)

parse_line_code matches %w+_(%d+)_(%d+) and returns nil, nil when either number of the line code is empty (e.g. <sha>__44, as GitLab produces when a line has no counterpart on the other side). get_line_numbers_for_range then does arithmetic on the nil values; the old-SHA branch (line 265) has the same problem.

Changes

  • parse_line_code accepts empty numbers (%d*) and returns nil for them; a nil line code no longer throws.
  • get_line_numbers_for_range falls back to a single-line range when either end of the range has no number (old-SHA and new-SHA branches).
  • Adds tests/spec/line_code_spec.lua, which reproduces the error without the fix.

🤖 Generated with Claude Code

GitLab leaves the old or new number of a line code empty when the line has
no counterpart on the other side (e.g. "<sha>__44"). parse_line_code
returned nil for both numbers in that case and get_line_numbers_for_range
crashed with "attempt to perform arithmetic on local 'new_end_line' (a nil
value)" while setting diagnostics in the reviewer. Parse empty numbers as
nil and fall back to a single-line range.
@jakubbortlik

Copy link
Copy Markdown
Collaborator

Hi @Enceradeira, are these empty line numbers created by gitlab.nvim or by Gitlab in the browser? I'm asking because maybe this is not the right place to fix this. If the missing line numbers are caused by gitlab.nvim, then we should fix the line code creation.

@jakubbortlik

Copy link
Copy Markdown
Collaborator

By the way there is #587 - is it solving the same problem? The author of that other PR never replied to my question, so I didn't bother to merge it :)

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.

2 participants