all repos

clerk @ 225a2d3

missing tooling for ledger/hledger

clerk/internal/lsp/server.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
lsp: diagnostics, 20 days ago
1
package lsp
2
3
import (
4
	"context"
5
	"log/slog"
6
	"sync"
7
	"time"
8
9
	"go.lsp.dev/protocol"
10
	"go.lsp.dev/uri"
11
12
	"olexsmir.xyz/clerk/internal/linter"
13
	"olexsmir.xyz/clerk/journal"
14
	"olexsmir.xyz/clerk/journal/printer"
15
	"olexsmir.xyz/clerk/journal/semantic"
16
)
17
18
const name = "clerk"
19
20
type docState struct {
21
	text       string
22
	version    int32
23
	languageID protocol.LanguageKind
24
}
25
26
type server struct {
27
	protocol.UnimplementedServer
28
29
	client protocol.Client
30
31
	version string
32
33
	printerCfg *printer.Config
34
	logger     *slog.Logger
35
36
	loader    *journal.Loader
37
	sema      *semantic.Context
38
	linter    *linter.Linter
39
	debouncer *time.Timer
40
41
	mu       sync.Mutex
42
	openDocs map[uri.URI]docState
43
}
44
45
func (s *server) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) {
46
	return &protocol.InitializeResult{
47
		ServerInfo: protocol.ServerInfo{
48
			Name:    name,
49
			Version: protocol.NewOptional(s.version),
50
		},
51
		Capabilities: protocol.ServerCapabilities{
52
			TextDocumentSync: &protocol.TextDocumentSyncOptions{
53
				OpenClose: new(true),
54
				Change:    new(protocol.TextDocumentSyncKindFull),
55
			},
56
			DocumentFormattingProvider: &protocol.DocumentFormattingOptions{},
57
			// CompletionProvider: &protocol.CompletionOptions{
58
			// 	TriggerCharacters: []string{" ", ":", "/"},
59
			// },
60
		},
61
	}, nil
62
}
63
64
func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error {
65
	s.scheduleWorkspaceRebuild(ctx)
66
	return nil
67
}
68
69
func (s *server) Shutdown(ctx context.Context) error {
70
	s.cancelWorkspaceRebuild()
71
	return nil
72
}
73
74
func (s *server) Exit(ctx context.Context) error {
75
	return nil
76
}