Skip to content

feat: Improve editor detection with auto-discovery and better error messages#3155

Merged
rekram1-node merged 2 commits into
anomalyco:devfrom
affaan-m:improve-editor-detection
Oct 22, 2025
Merged

feat: Improve editor detection with auto-discovery and better error messages#3155
rekram1-node merged 2 commits into
anomalyco:devfrom
affaan-m:improve-editor-detection

Conversation

@affaan-m

@affaan-m affaan-m commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Summary

Improves the /editor command UX by automatically detecting available editors and providing helpful error messages when none are found.

Changes

  • Add GetEditor() utility function in packages/tui/internal/util/util.go:

    • Checks VISUAL environment variable first (standard for full-screen editors)
    • Falls back to EDITOR environment variable
    • Auto-detects common modern editors: VSCode (code), Cursor, Zed, Neovim (nvim), Vim, nano, vi
    • Platform-specific support (e.g., .cmd extensions and notepad.exe on Windows)
  • Update /editor command (EditorOpenCommand) to use new detection

  • Update /export command (SessionExportCommand) to use new detection

  • Provide helpful error message: "No editor found. Set EDITOR environment variable (e.g., export EDITOR=vim)"

Testing

Tested scenarios:

  • ✅ EDITOR set: uses specified editor
  • ✅ VISUAL set: prefers VISUAL over EDITOR
  • ✅ Neither set but common editor available: auto-detects (VSCode, Cursor, Neovim, Vim, Zed, etc.)
  • ✅ No editor available: shows helpful error with instructions

Related Issues

Resolves the issue where users get unhelpful "No EDITOR set" message without guidance on how to fix it.

- Add GetEditor() utility that checks VISUAL, EDITOR env vars and auto-detects common editors
- Support modern editors: VSCode (code), Cursor, Zed, and traditional editors (nvim, vim, nano, vi)
- Update /editor and /export commands to use new detection
- Provide helpful error message with instructions when no editor found
- Support platform-specific defaults (notepad, .cmd extensions on Windows)
@affaan-m
affaan-m force-pushed the improve-editor-detection branch from 62eaf50 to 4d4640d Compare October 13, 2025 23:05
@affaan-m affaan-m changed the title Improve editor detection with auto-discovery and better error messages feat: Improve editor detection with auto-discovery and better error messages Oct 13, 2025
@CarlosGtrz CarlosGtrz mentioned this pull request Oct 22, 2025
@rekram1-node

Copy link
Copy Markdown
Collaborator

/oc adjust GetEditor so there is never an error returned because it never returns an error so it doesnt need (string, error). Also for the commonEditors array lets reorder a bit, start with: vim, nvim, zed, then put everything else as is but flip the order between nano and vi (so nano should be last).

@opencode-agent

opencode-agent Bot commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Excellent! The changes have been successfully implemented. Here's a summary of what was done:

Changes Made

  1. Modified GetEditor() function in packages/tui/internal/util/util.go:

    • Changed return type from (string, error) to just string
    • Removed all nil error returns since the function never returns an error
    • Reordered the commonEditors array to start with: vim, nvim, zed, then the rest
    • Flipped the order between nano and vi so nano is last
    • Updated Windows-specific editor list with the same reordering
  2. Updated function calls in packages/tui/internal/tui/tui.go:

    • Removed error handling from both calls to GetEditor() (lines 1155 and 1401)
    • Changed from editor, err := util.GetEditor() to editor := util.GetEditor()
    • Kept the same empty string check logic since that still applies

The function now returns a simple string and never returns an error, making it cleaner to use while maintaining the same functionality for editor detection.

New%20session%20-%202025-10-22T01%3A44%3A18.489Z
opencode session  |  github run

Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
@rekram1-node

Copy link
Copy Markdown
Collaborator

thanks @affaan-m!

@rekram1-node
rekram1-node merged commit 8db5951 into anomalyco:dev Oct 22, 2025
3 checks passed
@affaan-m
affaan-m deleted the improve-editor-detection branch February 9, 2026 09:31
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
…essages (anomalyco#3155)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request May 5, 2026
…essages (anomalyco#3155)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
…essages (anomalyco#3155)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
…essages (anomalyco#3155)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
…essages (anomalyco#3155)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
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.

2 participants