Skip to content

[Bug] Cursor row off-by-one — Treesitter 0-indexed vs nvim_win_get_cursor 1-indexed #37

Open

Description

@PyDevC

File: lua/model_cmp/context.lua:93-95

Introduction: scopes_inrange() compares cursor[1] (1-indexed from nvim_win_get_cursor) against Treesitter node rows (0-indexed from node:range()). The last line of a function scope may be incorrectly excluded from context.

Detailed Description: While the comparison works by accident in some cases, at scope boundaries the off-by-one causes incorrect behavior. For example, if cursor is at line 11 and the scope ends at Treesitter row 10, cursor is correctly within scope but only because the 0-indexed vs 1-indexed offset happens to match. At scope boundaries it fails.

Reproduction:

  1. Open a file with a multi-line function
  2. Place cursor on the last line of the function definition
  3. Context may include or exclude the scope depending on position

System detail: All systems, all languages.

Activity

  1. added
    bug
    on May 24, 2026
  2. changed the title [-][Bug][/-] [+][Bug] Cursor row off-by-one — Treesitter 0-indexed vs nvim_win_get_cursor 1-indexed[/+] on May 24, 2026
  3. added
    AI gen
    on May 24, 2026
  4. PyDevC commented on May 26, 2026

    @PyDevC
    OwnerAuthor

    One easy fix would be to enforce 1 based indexing in whole program before you start working on it. So you don't have to worry about 0 indexing or 1 indexing.

  5. added
    maintainer triaged
    on May 26, 2026
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

    AI genbugmaintainer triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions