-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
83 lines (66 loc) · 1.79 KB
/
main.go
File metadata and controls
83 lines (66 loc) · 1.79 KB
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
package main
import (
"context"
"flag"
"fmt"
"os"
"runtime"
"github.com/sourcegraph/jsonrpc2"
"github.com/konradmalik/flint-ls/core"
"github.com/konradmalik/flint-ls/logs"
"github.com/konradmalik/flint-ls/lsp"
)
const (
name = "flint-ls"
version = "0.0.54"
)
var revision = "HEAD"
func main() {
var logfile string
var loglevel int
var showVersion bool
var usage bool
flag.StringVar(&logfile, "logfile", "", "File to save logs into. If provided stderr won't be used anymore.")
flag.IntVar(&loglevel, "loglevel", 2, "Set the log level. Max is 3 (debug), min is 0 (error). Higher number logs less. Set <0 for no logs.")
flag.BoolVar(&showVersion, "v", false, "Print the version")
flag.BoolVar(&usage, "h", false, "Show help")
flag.Parse()
if showVersion {
fmt.Printf("%s %s (rev: %s/%s)\n", name, version, revision, runtime.Version())
return
}
if usage || flag.NArg() != 0 {
flag.Usage()
os.Exit(1)
}
config := core.NewConfig()
logs.InitializeLogger(logfile, logs.LogLevel(max(loglevel, -1)))
logs.Log.Logln(logs.Info, "reading on stdin, writing on stdout")
var f *os.File
defer func() {
if f != nil {
_ = f.Close()
}
}()
internalHandler := core.NewHandler(config)
handler := lsp.NewHandler(internalHandler)
<-jsonrpc2.NewConn(
context.Background(),
jsonrpc2.NewBufferedStream(stdrwc{}, jsonrpc2.VSCodeObjectCodec{}),
jsonrpc2.HandlerWithError(handler.Handle),
jsonrpc2.LogMessages(logs.Log)).DisconnectNotify()
logs.Log.Logln(logs.Info, "flint-ls: connections closed")
}
type stdrwc struct{}
func (stdrwc) Read(p []byte) (int, error) {
return os.Stdin.Read(p)
}
func (c stdrwc) Write(p []byte) (int, error) {
return os.Stdout.Write(p)
}
func (c stdrwc) Close() error {
if err := os.Stdin.Close(); err != nil {
return err
}
return os.Stdout.Close()
}