You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Single-line file selection doesn't expand to enclosing symbol (off-by-one) #42887
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
Attach a file with a single-line selection placed on a function/class definition.
The agent reads only that one line instead of the enclosing symbol.
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.
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.
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.
Activity
kaeldrin-gh commentedon Sep 5, 2026
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.
opencodejr commentedon Oct 28, 2026
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 (theopencode-aipackage, 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, theopencodecommand). v2 is a separate implementation, and that file and itsdocumentSymbolexpansion 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 --versionand the steps, and we'll take another look.opencodejr commentedon Oct 29, 2026
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 --versionand the steps to reproduce it.