From e7b85502d679efce465c090f9c91c646bafefcc0 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sat, 18 Jun 2022 21:15:19 +0200 Subject: [PATCH 1/3] Auto-detect any `clangd` and `arduino-cli` in `$PATH` --- main.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index e3622f4..4724db3 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" _ "net/http/pprof" "os" + "os/exec" "os/signal" "github.com/arduino/arduino-language-server/ls" @@ -68,15 +69,32 @@ func main() { log.SetOutput(os.Stderr) } - if *cliPath != "" { + if *cliDaemonAddress != "" || *cliDaemonInstanceNumber != -1 { + // if one is set, both must be set + if *cliDaemonAddress == "" || *cliDaemonInstanceNumber == -1 { + log.Fatal("ArduinoCLI daemon address and instance number must be set.") + } + } else { if *cliConfigPath == "" { log.Fatal("Path to ArduinoCLI config file must be set.") } - } else if *cliDaemonAddress == "" || *cliDaemonInstanceNumber == -1 { - log.Fatal("ArduinoCLI daemon address and instance number must be set.") + if *cliPath == "" { + bin, _ := exec.LookPath("arduino-cli") + if bin == "" { + log.Fatal("Path to ArduinoCLI must be set.") + } + log.Printf("arduino-cli found at %s\n", bin) + *cliPath = bin + } } + if *clangdPath == "" { - log.Fatal("Path to Clangd must be set.") + bin, _ := exec.LookPath("clangd") + if bin == "" { + log.Fatal("Path to Clangd must be set.") + } + log.Printf("clangd found at %s\n", bin) + *clangdPath = bin } config := &ls.Config{ From 9d859f47995aedc1aac69ca81d2f5f1b2d1604c2 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sat, 18 Jun 2022 21:16:26 +0200 Subject: [PATCH 2/3] Auto-detect `arduino-cli.yaml` in `~/.arduino15` --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index 4724db3..140efc2 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,8 @@ import ( "os" "os/exec" "os/signal" + "os/user" + "path" "github.com/arduino/arduino-language-server/ls" "github.com/arduino/arduino-language-server/streams" @@ -75,6 +77,15 @@ func main() { log.Fatal("ArduinoCLI daemon address and instance number must be set.") } } else { + if *cliConfigPath == "" { + if user, _ := user.Current(); user != nil { + candidate := path.Join(user.HomeDir, ".arduino15/arduino-cli.yaml") + if _, err := os.Stat(candidate); err == nil { + *cliConfigPath = candidate + log.Printf("ArduinoCLI config file found at %s\n", candidate) + } + } + } if *cliConfigPath == "" { log.Fatal("Path to ArduinoCLI config file must be set.") } From 6fa5799f459fdb8839c35ce967c8d1118791dafd Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sat, 18 Jun 2022 21:49:19 +0200 Subject: [PATCH 3/3] Update README to indicate these are no longer required --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5f80f5..a217f19 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ The prerequisites to run the Arduino Language Server are: - [Arduino CLI](https://github.com/arduino/arduino-cli) - [clangd](https://github.com/clangd/clangd/releases) -To start the language server the IDE must provide the path to Arduino CLI and clangd with the following flags in addition to the target board FQBN: +To start the language server the IDE may provide the path to Arduino CLI and clangd with the following flags in addition to the target board FQBN: ``` ./arduino-language-server \