Skip to content

Commit

Permalink
pkg/terminal: support zed editor and allow args in DELVE_EDITOR (#3899)
Browse files Browse the repository at this point in the history
Enhance editor support for the DELVE_EDITOR environment variable

1. Add support for the Zed editor by recognizing the 'zed' command and setting
   the appropriate line number syntax

2. Allow users to specify editor-specific arguments in DELVE_EDITOR by parsing
   the env var value into command and args parts

3. Modify runEditor() to pass through any user-specified args before appending
   the file/line args

This change allows more configuration flexibility through DELVE_EDITOR while
maintaining backwards compatibility. The Zed editor is now supported alongside
VSCode, Helix and Vim variants.

Fixes #3627
  • Loading branch information
derekparker authored Jan 12, 2025
1 parent c4ab92e commit 0b1ef9b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/terminal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1960,22 +1960,32 @@ func tracepoint(t *Term, ctx callContext, args string) error {
return err
}

func getEditorName() (string, error) {
func getEditorName() (string, []string, error) {
var editor string
if editor = os.Getenv("DELVE_EDITOR"); editor == "" {
if editor = os.Getenv("EDITOR"); editor == "" {
return "", errors.New("Neither DELVE_EDITOR or EDITOR is set")
return "", nil, errors.New("Neither DELVE_EDITOR or EDITOR is set")
}
}
return editor, nil

editorParts := strings.Fields(editor)
editor = editorParts[0]

var userArgs []string
if len(editorParts) > 1 {
userArgs = editorParts[1:]
}

return editor, userArgs, nil
}

func runEditor(args ...string) error {
editor, err := getEditorName()
editor, userArgs, err := getEditorName()
if err != nil {
return err
}
cmd := exec.Command(editor, args...)
allArgs := append(userArgs, args...)
cmd := exec.Command(editor, allArgs...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand All @@ -1987,13 +1997,15 @@ func edit(t *Term, ctx callContext, args string) error {
if err != nil {
return err
}
editor, err := getEditorName()
editor, _, err := getEditorName()
if err != nil {
return err
}
switch editor {
case "code":
return runEditor("--goto", fmt.Sprintf("%s:%d", file, lineno))
case "zed":
return runEditor(fmt.Sprintf("%s:%d:0", file, lineno))
case "hx":
return runEditor(fmt.Sprintf("%s:%d", file, lineno))
case "vi", "vim", "nvim":
Expand Down

0 comments on commit 0b1ef9b

Please sign in to comment.