-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (43 loc) · 1.3 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
package main
import (
"bufio"
"flag"
"log"
"os"
"plantuml_lsp/analysis"
"plantuml_lsp/handler"
"plantuml_lsp/lsp"
"plantuml_lsp/rpc"
)
func main() {
// TODO: pass in plantuml_lsp.rc file to use for config stuff
// - include log level https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_logMessage
logPath := flag.String("log-path", "", "LSP log path")
stdlibPath := flag.String("stdlib-path", "", "PlantUML stdlib path")
flag.Parse()
logger := getLogger(*logPath)
logger.Println("Started plantuml-lsp")
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(rpc.Split)
state := analysis.NewState()
writer := os.Stdout
for scanner.Scan() {
msg := scanner.Bytes()
method, contents, err := rpc.DecodeMessage(msg)
if err != nil {
handler.SendLogMessage(writer, "Error decoding message: "+err.Error(), lsp.Error)
continue
}
handler.HandleMessage(writer, state, method, contents, *stdlibPath)
}
}
func getLogger(filename string) *log.Logger {
if filename == "" {
return log.New(os.Stdout, "[plantuml-lsp]", log.Ldate|log.Ltime|log.Lshortfile)
}
logfile, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
return log.New(logfile, "[plantuml-lsp]", log.Ldate|log.Ltime|log.Lshortfile)
}