LSP-server-example
47 строк · 1.1 Кб
1package handlers2
3import (4"encoding/json"5"log/slog"6"lsp-server/internal/protocol"7)
8
9const (10TextDocumentSyncKindNone protocol.TextDocumentSyncKind = iota11TextDocumentSyncKindFull
12TextDocumentSyncKindIncremental
13)
14
15const InitializeMethod = "initialize"16
17type Initialize struct {18}
19
20func (i Initialize) Call(params json.RawMessage) (any, error) {21slog.Info("received initialize method")22iParams, err := i.parseParams(params)23if err != nil {24slog.Error("Error to parse initialized params")25return nil, err26}27slog.Debug("initialized params", slog.Any("params", *iParams))28
29result := protocol.InitializeResult{30Capabilities: protocol.ServerCapabilities{31TextDocumentSync: TextDocumentSyncKindFull,32HoverProvider: &protocol.Or_ServerCapabilities_hoverProvider{},33CompletionProvider: &protocol.CompletionOptions{},34},35}36
37return result, nil38}
39
40func (i Initialize) parseParams(params json.RawMessage) (*protocol.InitializedParams, error) {41var initializeParams protocol.InitializedParams42if err := json.Unmarshal(params, &initializeParams); err != nil {43return nil, err44}45
46return &initializeParams, nil47}
48