Skip to content

[Bug]: Symbol references highlight ordinary words in assistant prose #558

Open

Description

@Mach1212

Description

Assistant replies in the output window highlight ordinary English words as symbol references (OpencodeSymbolReference), and gd/<CR> on those words offer jumps to unrelated locals. With only lua/opencode/ui/session_diff.lua loaded, short replies light up to, first, line, existing, current, file, apply and update (screenshots below). In a larger TypeScript project I get dozens of highlighted words per reply.

The symbol scan doesn't distinguish prose from code. _format_assistant_message tokenizes every line of a text part with symbol_tokens.find and keeps any token that symbol_snapshot.targets_for_token resolves in a candidate file (formatter.lua#L753-L884). Nothing checks for inline code or fenced blocks.

Before #489, a token was only checked against files referenced earlier in the same message (formatter.lua#L856-L868 at cdf00c5), which kept prose matches rare. #489 widened the candidates to every readable file from the conversation plus every loaded buffer (reference_facts.lua#L237-L259) while still scanning the whole reply, so any common word that is a local name somewhere in those files matches.

Expected: symbol references only inside inline code and fenced code blocks, which is where replies put identifiers. If bare identifiers in prose should stay jumpable, prose could be limited to tokens that look like code (containing _, ., :: or an inner capital): that keeps switch_to_mode and drops to and line. An option to turn symbol references off would also help; overriding the highlight group hides the colour, but the jump targets stay.

Steps to reproduce

  1. From the repo root, start the replay harness with nvim-treesitter's queries on the runtimepath (Neovim 0.12 ships no Lua locals query):
    ./tests/manual/run_replay.sh --cmd 'set rtp+=/path/to/nvim-treesitter/runtime' (the directory that contains queries/lua/locals.scm)
  2. Load a plugin file into a buffer. The focused panel window has winfixbuf, so: :call bufload(bufadd('lua/opencode/ui/session_diff.lua'))
  3. :ReplayLoad tests/data/redo-all.json
  4. :lua require('tests.helpers').restore_replay_environment(). :ReplayLoad stubs reference_facts.available_files() to return {}, which hides this in replays.
  5. :ReplayAll
  6. The replies highlight to, first, line, existing, current, file, apply and update. gd on first in "to the first line" offers three first locals from session_diff.lua.

Environment

  • Neovim version: 0.12.4
  • OpenCode version: 1.19.0 (not used by the replay)
  • opencode.nvim version or commit: 93b0536 (current main)
  • OS: macOS 27.0.1 (arm64)

Configuration

OpenCode configuration

Not involved; the replay doesn't talk to a server.

opencode.nvim configuration

Defaults from tests/manual/init_replay.lua. The screenshots are from my own config, which sets preferred_picker = 'snacks'.

Logs and screenshots

The replay above with only session_diff.lua loaded:

Ordinary words in assistant replies highlighted as symbol references

gd on "first" in "to the first line":

gd on the word first lists three locals named first in session_diff.lua

Checklist

  • I have searched existing issues.
  • I have included all relevant details.
  • I have removed sensitive information from configs and logs.

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions