Skip to content

Single-line file selection doesn't expand to enclosing symbol (off-by-one) #42887

Closed as not planned

Description

@icyaaaww

Description

Referencing a file with a single-line selection (startLine === endLine) should expand the read range to the enclosing symbol via documentSymbol. The check in packages/opencode/src/session/prompt.ts compares
.start.line (LSP 0-based) against start (1-based selection), so it never matches. The agent reads only the single selected line instead of the whole symbol.

Plugins

None

OpenCode version

dev

Steps to reproduce

  1. Attach a file with a single-line selection placed on a function/class definition.
  2. The agent reads only that one line instead of the enclosing symbol.

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. kaeldrin-gh commented on Sep 5, 2026

    @kaeldrin-gh

    A fix for this is up in PR #47503 (Fixes #42887): the symbol lookup now compares 1-based lines against the LSP 0-based range (
    .start.line + 1), and also fixes symbols starting on line 1 that previously never matched due to a truthiness check.

  2. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the precise write-up, @icyaaaww, including the 0-based vs 1-based line comparison.

    The code you're pointing at (packages/opencode/src/session/prompt.ts) belongs to OpenCode v1 (the opencode-ai package, versions 0.x/1.x). v1 now only gets fixes for critical bugs such as data loss, security problems or crashes with no workaround. This one has a workaround (select the whole symbol), so it's unlikely to be fixed in v1.

    We'd encourage upgrading to v2 (@opencode/cli, the opencode command). v2 is a separate implementation, and that file and its documentSymbol expansion aren't in it, so this off-by-one doesn't apply there.

    If you think this is critical, or you see a similar problem on v2, please reply with your opencode --version and the steps, and we'll take another look.

  3. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Closing this as not planned. The single-line selection off-by-one is in v1 code (packages/opencode/src/session/prompt.ts), and v1 only gets fixes for critical bugs. v2 doesn't have that code, so the bug can't happen there. We haven't heard that it's critical or that it also shows up on v2.

    Thanks again for the clear write-up, @icyaaaww. If you see a similar problem on v2, please open a new issue with your opencode --version and the steps to reproduce it.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions