Skip to content

Automatically detect the path of clangd, arduino-cli, and its configuration #115

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

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
37 changes: 33 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/exec"
"os/signal"
"os/user"
"path"

"github.com/arduino/arduino-language-server/ls"
"github.com/arduino/arduino-language-server/streams"
Expand Down Expand Up @@ -68,15 +71,41 @@ 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 == "" {
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.")
}
} 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{
Expand Down