Skip to content

Commit e7b8550

Browse files
committed
Auto-detect any clangd and arduino-cli in $PATH
1 parent 2554452 commit e7b8550

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

main.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
_ "net/http/pprof"
99
"os"
10+
"os/exec"
1011
"os/signal"
1112

1213
"github.com/arduino/arduino-language-server/ls"
@@ -68,15 +69,32 @@ func main() {
6869
log.SetOutput(os.Stderr)
6970
}
7071

71-
if *cliPath != "" {
72+
if *cliDaemonAddress != "" || *cliDaemonInstanceNumber != -1 {
73+
// if one is set, both must be set
74+
if *cliDaemonAddress == "" || *cliDaemonInstanceNumber == -1 {
75+
log.Fatal("ArduinoCLI daemon address and instance number must be set.")
76+
}
77+
} else {
7278
if *cliConfigPath == "" {
7379
log.Fatal("Path to ArduinoCLI config file must be set.")
7480
}
75-
} else if *cliDaemonAddress == "" || *cliDaemonInstanceNumber == -1 {
76-
log.Fatal("ArduinoCLI daemon address and instance number must be set.")
81+
if *cliPath == "" {
82+
bin, _ := exec.LookPath("arduino-cli")
83+
if bin == "" {
84+
log.Fatal("Path to ArduinoCLI must be set.")
85+
}
86+
log.Printf("arduino-cli found at %s\n", bin)
87+
*cliPath = bin
88+
}
7789
}
90+
7891
if *clangdPath == "" {
79-
log.Fatal("Path to Clangd must be set.")
92+
bin, _ := exec.LookPath("clangd")
93+
if bin == "" {
94+
log.Fatal("Path to Clangd must be set.")
95+
}
96+
log.Printf("clangd found at %s\n", bin)
97+
*clangdPath = bin
8098
}
8199

82100
config := &ls.Config{

0 commit comments

Comments
 (0)