Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/terminal: support more editors with edit command #3506

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions pkg/terminal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1914,14 +1914,21 @@ func tracepoint(t *Term, ctx callContext, args string) error {
return err
}

func runEditor(args ...string) error {
func getEditorName() (string, error) {
var editor string
if editor = os.Getenv("DELVE_EDITOR"); editor == "" {
if editor = os.Getenv("EDITOR"); editor == "" {
return fmt.Errorf("Neither DELVE_EDITOR or EDITOR is set")
return "", fmt.Errorf("Neither DELVE_EDITOR or EDITOR is set")
}
}
return editor, nil
}

func runEditor(args ...string) error {
editor, err := getEditorName()
if err != nil {
return err
}
cmd := exec.Command(editor, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand All @@ -1934,7 +1941,18 @@ func edit(t *Term, ctx callContext, args string) error {
if err != nil {
return err
}
return runEditor(fmt.Sprintf("+%d", lineno), file)
editor, err := getEditorName()
if err != nil {
return err
}
switch editor {
case "hx":
return runEditor(fmt.Sprintf("%s:%d", file, lineno))
case "vi", "vim", "nvim":
return runEditor(fmt.Sprintf("+%d", lineno), file)
default:
return runEditor(fmt.Sprintf("+%d", lineno), file)
}
}

func watchpoint(t *Term, ctx callContext, args string) error {
Expand Down