summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorAffaan Mustafa <[email protected]>2025-10-21 18:49:42 -0700
committerGitHub <[email protected]>2025-10-21 20:49:42 -0500
commit8db595128754d6133de3f82c60d3adea1ef77c26 (patch)
treec3008b9f3850c00367196de788ee5ef1d4cba4cc /packages
parent97c7e941eb864fa4db2a94919a924f47ee002346 (diff)
downloadopencode-8db595128754d6133de3f82c60d3adea1ef77c26.tar.gz
opencode-8db595128754d6133de3f82c60d3adea1ef77c26.zip
feat: Improve editor detection with auto-discovery and better error messages (#3155)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <[email protected]>
Diffstat (limited to 'packages')
-rw-r--r--packages/tui/internal/tui/tui.go9
-rw-r--r--packages/tui/internal/util/util.go24
2 files changed, 28 insertions, 5 deletions
diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go
index da77b42f2..69fa7bdb8 100644
--- a/packages/tui/internal/tui/tui.go
+++ b/packages/tui/internal/tui/tui.go
@@ -1158,9 +1158,9 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
// status.Warn("Agent is working, please wait...")
return a, nil
}
- editor := os.Getenv("EDITOR")
+ editor := util.GetEditor()
if editor == "" {
- return a, toast.NewErrorToast("No EDITOR set, can't open editor")
+ return a, toast.NewErrorToast("No editor found. Set EDITOR environment variable (e.g., export EDITOR=vim)")
}
value := a.editor.Value()
@@ -1404,10 +1404,9 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
// Format to Markdown
markdownContent := formatConversationToMarkdown(messages)
- // Check if EDITOR is set
- editor := os.Getenv("EDITOR")
+ editor := util.GetEditor()
if editor == "" {
- return a, toast.NewErrorToast("No EDITOR set, can't open editor")
+ return a, toast.NewErrorToast("No editor found. Set EDITOR environment variable (e.g., export EDITOR=vim)")
}
// Create and write to temp file
diff --git a/packages/tui/internal/util/util.go b/packages/tui/internal/util/util.go
index fdefb2901..b49d2e292 100644
--- a/packages/tui/internal/util/util.go
+++ b/packages/tui/internal/util/util.go
@@ -3,6 +3,8 @@ package util
import (
"log/slog"
"os"
+ "os/exec"
+ "runtime"
"strings"
"time"
@@ -45,3 +47,25 @@ func Measure(tag string) func(...any) {
slog.Debug(tag, args...)
}
}
+
+func GetEditor() string {
+ if editor := os.Getenv("VISUAL"); editor != "" {
+ return editor
+ }
+ if editor := os.Getenv("EDITOR"); editor != "" {
+ return editor
+ }
+
+ commonEditors := []string{"vim", "nvim", "zed", "code", "cursor", "vi", "nano"}
+ if runtime.GOOS == "windows" {
+ commonEditors = []string{"vim", "nvim", "zed", "code.cmd", "cursor.cmd", "notepad.exe", "vi", "nano"}
+ }
+
+ for _, editor := range commonEditors {
+ if _, err := exec.LookPath(editor); err == nil {
+ return editor
+ }
+ }
+
+ return ""
+}