pkg/terminal: support more editors with edit command (#3506)
The current implementation assumes a specific command line interface for opening an editor at a specific location within the source file. This patch updates for different formats, namely the one used by the editor 'hx'.
This commit is contained in:
parent
db7e60aef3
commit
4d30cd461b
@ -1914,14 +1914,21 @@ func tracepoint(t *Term, ctx callContext, args string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func runEditor(args ...string) error {
|
func getEditorName() (string, error) {
|
||||||
var editor string
|
var editor string
|
||||||
if editor = os.Getenv("DELVE_EDITOR"); editor == "" {
|
if editor = os.Getenv("DELVE_EDITOR"); editor == "" {
|
||||||
if editor = os.Getenv("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 := exec.Command(editor, args...)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@ -1934,7 +1941,18 @@ func edit(t *Term, ctx callContext, args string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
func watchpoint(t *Term, ctx callContext, args string) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user