@@ -7,7 +7,10 @@ import (
7
7
"net/http"
8
8
_ "net/http/pprof"
9
9
"os"
10
+ "os/exec"
10
11
"os/signal"
12
+ "os/user"
13
+ "path"
11
14
12
15
"github.com/arduino/arduino-language-server/ls"
13
16
"github.com/arduino/arduino-language-server/streams"
@@ -68,15 +71,41 @@ func main() {
68
71
log .SetOutput (os .Stderr )
69
72
}
70
73
71
- if * cliPath != "" {
74
+ if * cliDaemonAddress != "" || * cliDaemonInstanceNumber != - 1 {
75
+ // if one is set, both must be set
76
+ if * cliDaemonAddress == "" || * cliDaemonInstanceNumber == - 1 {
77
+ log .Fatal ("ArduinoCLI daemon address and instance number must be set." )
78
+ }
79
+ } else {
80
+ if * cliConfigPath == "" {
81
+ if user , _ := user .Current (); user != nil {
82
+ candidate := path .Join (user .HomeDir , ".arduino15/arduino-cli.yaml" )
83
+ if _ , err := os .Stat (candidate ); err == nil {
84
+ * cliConfigPath = candidate
85
+ log .Printf ("ArduinoCLI config file found at %s\n " , candidate )
86
+ }
87
+ }
88
+ }
72
89
if * cliConfigPath == "" {
73
90
log .Fatal ("Path to ArduinoCLI config file must be set." )
74
91
}
75
- } else if * cliDaemonAddress == "" || * cliDaemonInstanceNumber == - 1 {
76
- log .Fatal ("ArduinoCLI daemon address and instance number must be set." )
92
+ if * cliPath == "" {
93
+ bin , _ := exec .LookPath ("arduino-cli" )
94
+ if bin == "" {
95
+ log .Fatal ("Path to ArduinoCLI must be set." )
96
+ }
97
+ log .Printf ("arduino-cli found at %s\n " , bin )
98
+ * cliPath = bin
99
+ }
77
100
}
101
+
78
102
if * clangdPath == "" {
79
- log .Fatal ("Path to Clangd must be set." )
103
+ bin , _ := exec .LookPath ("clangd" )
104
+ if bin == "" {
105
+ log .Fatal ("Path to Clangd must be set." )
106
+ }
107
+ log .Printf ("clangd found at %s\n " , bin )
108
+ * clangdPath = bin
80
109
}
81
110
82
111
config := & ls.Config {
0 commit comments