Skip to content

Commit

Permalink
acme-lsp: add Restart verb to /LSP/Diagnostics
Browse files Browse the repository at this point in the history
When working on acme-lsp, it is convenient to be able
to go install a new acme-lsp and then have a way to restart it.

This change adds a new Restart action in /LSP/Diagnostics
to re-exec the current acme-lsp.
  • Loading branch information
rsc committed Apr 5, 2024
1 parent e6e6b7c commit b7279d8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/lsp/acmelsp/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package acmelsp

import (
"fmt"
"log"
"os"
"sync"
"syscall"
"time"

"github.com/fhs/acme-lsp/internal/acmeutil"
Expand Down Expand Up @@ -72,6 +75,9 @@ func (dw *diagWin) restart() error {
case "Reload":
dw.updateChan <- struct{}{}
continue

case "Restart":
restart()
}
}
dw.WriteEvent(ev)
Expand Down Expand Up @@ -136,3 +142,12 @@ func NewDiagnosticsWriter() DiagnosticsWriter {
}()
return dw
}

func restart() {
exe, err := os.Executable()
if err != nil {
exe = os.Args[0]
}
err = syscall.Exec(exe, os.Args, os.Environ())
log.Fatalf("exec: %v", err)
}

0 comments on commit b7279d8

Please sign in to comment.