-
Notifications
You must be signed in to change notification settings - Fork 6
/
initialize.go
50 lines (42 loc) · 1.15 KB
/
initialize.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
package langserver
import (
"context"
"encoding/json"
"github.com/kitagry/regols/langserver/internal/lsp"
"github.com/kitagry/regols/langserver/internal/source"
"github.com/sourcegraph/jsonrpc2"
)
func (h *handler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Params == nil {
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
}
h.conn = conn
var params lsp.InitializeParams
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
return nil, err
}
h.initializeParams = params
p, err := source.NewProject(params.RootPath)
if err != nil {
return nil, err
}
h.project = p
return lsp.InitializeResult{
Capabilities: lsp.ServerCapabilities{
TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{
Kind: toPtr(lsp.TDSKFull),
},
DocumentFormattingProvider: true,
DefinitionProvider: true,
HoverProvider: true,
ReferencesProvider: true,
CompletionProvider: &lsp.CompletionOptions{
TriggerCharacters: []string{"*", "."},
ResolveProvider: true,
},
},
}, nil
}
func toPtr[T any](t T) *T {
return &t
}