Skip to content

fix(vscode): push active editor selection to TUI via lock file#27662

Open
Restodecoca wants to merge 5 commits into
anomalyco:devfrom
Restodecoca:feat/vscode-editor-context
Open

fix(vscode): push active editor selection to TUI via lock file#27662
Restodecoca wants to merge 5 commits into
anomalyco:devfrom
Restodecoca:feat/vscode-editor-context

Conversation

@Restodecoca
Copy link
Copy Markdown

@Restodecoca Restodecoca commented May 15, 2026

Issue for this PR

Closes #22235
Related: #3095, #3096, #27420, #3472, #7275

Type of change

  • Bug fix
  • New feature

What does this PR do?

The VS Code extension's documented context awareness feature never worked because
the extension had no mechanism to push the active editor file and text selection
to the opencode TUI. This adds a WebSocket server that writes a lock file to
~/.claude/ide/.lock — the same protocol used by Claude Code and Cursor —
allowing the TUI to discover and receive real-time selection_changed events.

  • Starts a WebSocket server on a random port when the extension activates
  • Writes a lock file with workspaceFolders so the TUI scopes context correctly
  • Pushes selection_changed notifications on active editor or text selection change
  • Cleans up lock file and closes server on deactivation
  • Prevents cross-project context pollution (each workspace gets its own lock file)

How did you verify your code works?

  • bun run check-types passes
  • bun run lint passes
  • Built and packaged with npx vsce package
  • Installed VSIX locally, confirmed lock file created in ~/.claude/ide/
  • Connected via WebSocket client, confirmed selection_changed events when
    selecting text
  • Verified no cross-workspace context bleeding

Screenshots / recordings

image
opencode.-.arquitetura-etapa-1.3-modelagem-inicial-api-poc-86agd9a2m.-.Visual.Studio.Code.2026-05-15.00-58-02.mp4

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potential related PR:

PR #18649: "feat: live IDE context awareness"
#18649

This PR appears related as it addresses IDE context awareness, which aligns with the goal of pushing active editor selection to the TUI. It may be addressing similar or overlapping functionality for automatically including currently open file and selected lines as context.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Restodecoca Restodecoca mentioned this pull request May 15, 2026
@Restodecoca
Copy link
Copy Markdown
Author

Also relates to #27420 — opencode's own VS Code extension not showing file/selection context while the Claude Code extension does.

@Restodecoca
Copy link
Copy Markdown
Author

Also related to #3472 and #7275 — these are earlier reports of the same VS Code context awareness gap (files/selection not flowing to the TUI automatically).

@Restodecoca Restodecoca force-pushed the feat/vscode-editor-context branch from d2f23ce to 37692b1 Compare May 16, 2026 21:42
@Restodecoca
Copy link
Copy Markdown
Author

Also worth noting: this PR prevents cross-project context pollution. Each WebSocket server writes its own lock file with the correct workspaceFolders for that VS Code window. The TUI's resolveEditorLockFile already scores lock files by workspace path match — so opencode running in project A won't pick up selections from a VS Code window opened on unrelated project B, unlike the current situation where users with only the Claude Code extension installed can see context bleeding across unrelated sessions.

Related: #26852 (stale CLAUDE_CODE_SSE_PORT can also cause cross-session contamination — our extension provides a clean, workspace-scoped lock file alternative).

@Restodecoca Restodecoca changed the title feat(vscode): push active editor selection to TUI via lock file fix(vscode): push active editor selection to TUI via lock file May 16, 2026
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.

IDE (VSCode): Context Awareness function didn’t take effect.

1 participant