-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
111 lines (100 loc) · 2.94 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"flag"
"io"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"github.com/arduino/arduino-language-server/ls"
"github.com/arduino/arduino-language-server/streams"
"github.com/arduino/go-paths-helper"
)
func main() {
clangdPath := flag.String(
"clangd", "",
"Path to clangd executable")
cliPath := flag.String(
"cli", "",
"Path to arduino-cli executable")
cliConfigPath := flag.String(
"cli-config", "",
"Path to arduino-cli config file")
fqbn := flag.String(
"fqbn", "",
"Fully qualified board name to use initially (can be changed via JSON-RPC)")
/* unused */ _ = flag.String(
"board-name", "",
"User-friendly board name to use initially (can be changed via JSON-RPC)")
enableLogging := flag.Bool(
"log", false,
"Enable logging to files")
loggingBasePath := flag.String(
"logpath", ".",
"Location where to write logging files to when logging is enabled")
formatFilePath := flag.String(
"format-conf-path", "",
"Path to global clang-format configuration file")
cliDaemonAddress := flag.String(
"cli-daemon-addr", "",
"TCP address and port of the Arduino CLI daemon (for example: localhost:50051)")
cliDaemonInstanceNumber := flag.Int(
"cli-daemon-instance", -1,
"Instance number of the Arduino CLI daemon")
flag.Parse()
if *loggingBasePath != "" {
streams.GlobalLogDirectory = paths.New(*loggingBasePath)
} else if *enableLogging {
log.Fatalf("Please specify logpath")
}
if *enableLogging {
logfile := streams.OpenLogFileAs("inols-err.log")
log.SetOutput(io.MultiWriter(logfile, os.Stderr))
defer streams.CatchAndLogPanic()
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
log.Println("Language server launched with arguments:")
for i, arg := range os.Args {
log.Printf(" arg[%d] = %s", i, arg)
}
} else {
log.SetOutput(os.Stderr)
}
if *cliPath != "" {
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 *clangdPath == "" {
log.Fatal("Path to Clangd must be set.")
}
config := &ls.Config{
Fqbn: *fqbn,
ClangdPath: paths.New(*clangdPath),
EnableLogging: *enableLogging,
CliPath: paths.New(*cliPath),
CliConfigPath: paths.New(*cliConfigPath),
FormatterConf: paths.New(*formatFilePath),
CliDaemonAddress: *cliDaemonAddress,
CliInstanceNumber: *cliDaemonInstanceNumber,
}
stdio := streams.NewReadWriteCloser(os.Stdin, os.Stdout)
if *enableLogging {
stdio = streams.LogReadWriteCloserAs(stdio, "inols.log")
}
inoHandler := ls.NewINOLanguageServer(stdio, stdio, config)
// Intercept kill signal
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, os.Kill)
select {
case <-inoHandler.CloseNotify():
case <-c:
log.Println("INTERRUPTED")
}
inoHandler.CleanUp()
inoHandler.Close()
}