Skip to content

Conversation

@affaan-m
Copy link
Contributor

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

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
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
Copy link
Contributor

opencode-agent bot commented Oct 22, 2025

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

@rekram1-node
Copy link
Collaborator

thanks @affaan-m!

@rekram1-node rekram1-node merged commit 8db5951 into sst:dev Oct 22, 2025
3 checks passed
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