LSP-server-example
46 строк · 1.1 Кб
1package handlers
2
3import (
4"encoding/json"
5"log/slog"
6
7"lsp-server/internal/protocol"
8)
9
10const CompletionRequestMethod = "textDocument/completion"
11
12type Completion struct {
13fileURIToContents *map[string][]string
14}
15
16func NewCompletion(fileURIToContents *map[string][]string) *Completion {
17return &Completion{fileURIToContents: fileURIToContents}
18}
19
20func (c Completion) Call(params json.RawMessage) (any, error) {
21slog.Info("received completion method")
22completionParams, err := c.parseParams(params)
23if err != nil {
24slog.Error("Error to parse completion params")
25return nil, err
26}
27slog.Debug("completion params", slog.Any("params", *completionParams))
28
29suggestions := []protocol.CompletionItem{
30{
31Label: "some completion",
32Kind: protocol.ValueCompletion,
33},
34}
35
36return suggestions, err
37}
38
39func (c Completion) parseParams(params json.RawMessage) (*protocol.CompletionParams, error) {
40var completionParams protocol.CompletionParams
41if err := json.Unmarshal(params, &completionParams); err != nil {
42return nil, err
43}
44
45return &completionParams, nil
46}
47