generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
54 lines (46 loc) 路 1.1 KB
/
server.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 lsp
import (
"context"
"io"
"github.com/dogmatiq/dogmacli/internal/lsp/proto"
"github.com/dogmatiq/dogmacli/internal/lsp/transport"
"github.com/dogmatiq/harpy"
"golang.org/x/exp/slog"
)
// Server is a JSON-RPC server that handles LSP requests.
type Server struct {
In io.ReadCloser
Out io.Writer
Version string
Logger *slog.Logger
ExchangeLogger harpy.ExchangeLogger
}
// Run starts the JSON-RPC server.
func (s *Server) Run(ctx context.Context) error {
h := &handler{
Version: s.Version,
Logger: s.Logger,
}
r := harpy.NewRouter(
proto.InitializeRoute(h),
proto.TextDocumentDiagnosticRoute(h),
proto.WorkspaceDidChangeWorkspaceFoldersRoute(h),
proto.TextDocumentDidOpenRoute(h),
proto.TextDocumentDidChangeRoute(h),
proto.TextDocumentDidCloseRoute(h),
)
return transport.Run(
ctx,
r,
s.In,
s.Out,
s.ExchangeLogger,
)
}
// handler implements various generated LSP handler interfaces.
type handler struct {
Version string
Logger *slog.Logger
overlay map[string][]byte
workspaceFolders map[proto.URI]*workspaceFolder
}