-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (52 loc) · 1.36 KB
/
main.go
File metadata and controls
63 lines (52 loc) · 1.36 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
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"taskfile-language-server/extension"
"taskfile-language-server/jsonrpc"
"taskfile-language-server/lsp"
)
// These variables are provided at build time using ldflags
var (
BuildVersion string = "dev"
BuildHash string = "dev"
)
func main() {
version := flag.Bool("version", false, "display the Language Server version")
logfile := flag.String("logfile", "", "log to this file")
traceEnabled := flag.Bool("trace", false, "print all requests and responses")
flag.Parse()
// Display version if asked for it
if *version {
fmt.Printf("Taskfile Language Server version %s-%s", BuildVersion, BuildHash)
return
}
var output io.Writer = os.Stderr
// Output to a file if a path is provided
if *logfile != "" {
f, err := os.OpenFile(*logfile, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
panic(err)
}
defer f.Close()
output = f
}
logger := log.New(output, "", log.Ldate|log.Ltime)
reader := os.Stdin
writer := os.Stdout
// Create the taskfile implementation of the LSP
impl := extension.New()
// Create the jsonrpc server
s := jsonrpc.NewServer(reader, writer)
// Override the Discard output and provide the same output as the logger
if *traceEnabled {
s.Logger.SetOutput(output)
impl.Logger.SetOutput(output)
}
// Create the LSP Server
_ = lsp.NewServer(s, impl, logger)
s.Listen()
}