-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (47 loc) · 1.26 KB
/
main.go
File metadata and controls
58 lines (47 loc) · 1.26 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
package main
import (
"context"
"log/slog"
"os"
"path/filepath"
"sylmark/lspserver"
"github.com/sourcegraph/jsonrpc2"
)
func main() {
logFile := setLogger()
defer logFile.Close()
slog.Info("Hey, We're up!--------------------------------------------------")
ctx := context.Background()
stream := jsonrpc2.NewBufferedStream(stdwrc{}, jsonrpc2.VSCodeObjectCodec{})
handler := lspserver.NewHandler()
handler.SetupGrammars()
defer handler.Parser.Close()
jsonHandler := jsonrpc2.HandlerWithError(handler.Handle)
conn := jsonrpc2.NewConn(ctx, stream, jsonHandler)
handler.Connection = conn
<-conn.DisconnectNotify()
slog.Info("Closing the lsp.")
}
func setLogger() *os.File {
logFilePath := filepath.Join("/tmp", "sylmark.log")
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
panic("Failed to open log file: " + err.Error())
}
logger := slog.New(slog.NewTextHandler(logFile, nil))
slog.SetDefault(logger)
return logFile
}
type stdwrc struct{}
func (stdwrc) Read(p []byte) (int, error) {
return os.Stdin.Read(p)
}
func (stdwrc) Write(p []byte) (int, error) {
return os.Stdout.Write(p)
}
func (stdwrc) Close() error {
if err := os.Stdin.Close(); err != nil {
return err
}
return os.Stdout.Close()
}