all repos

clerk @ de3dc94

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
lsp: semantic highlights, 2 months ago
1
package lsp
2
3
import (
4
	"context"
5
	"log/slog"
6
	"sync"
7
8
	"go.lsp.dev/protocol"
9
	"go.lsp.dev/uri"
10
11
	"olexsmir.xyz/clerk/internal/analyzer"
12
	"olexsmir.xyz/clerk/internal/linter"
13
	"olexsmir.xyz/clerk/journal"
14
	"olexsmir.xyz/clerk/journal/ast"
15
	"olexsmir.xyz/clerk/journal/printer"
16
)
17
18
type server struct {
19
	protocol.UnimplementedServer
20
21
	client protocol.Client
22
	log    *slog.Logger
23
24
	version, name string
25
26
	linter  *linter.Linter
27
	loader  *journal.Loader
28
	printer *printer.Config
29
30
	mu       sync.Mutex
31
	openDocs map[uri.URI]docState
32
	current  *analyzer.Analysis
33
34
	diagMu     sync.Mutex
35
	diagCancel context.CancelFunc
36
}
37
38
type docState struct {
39
	text       string
40
	version    int32
41
	languageID protocol.LanguageKind
42
	journal    *ast.Journal // cached parse; nil on parse failure
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:    s.name,
49
			Version: protocol.NewOptional(s.version),
50
		},
51
		Capabilities: protocol.ServerCapabilities{
52
			DocumentFormattingProvider: &protocol.DocumentFormattingOptions{},
53
			TextDocumentSync: &protocol.TextDocumentSyncOptions{
54
				OpenClose: new(true),
55
				Change:    new(protocol.TextDocumentSyncKindFull),
56
			},
57
			SemanticTokensProvider: &protocol.SemanticTokensOptions{
58
				Legend: getSemanticTokensLegend(),
59
				Range:  protocol.Boolean(true),
60
				Full:   protocol.Boolean(true),
61
			},
62
		},
63
	}, nil
64
}
65
66
func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error {
67
	s.scheduleDiagnostics(ctx)
68
	return nil
69
}
70
71
func (s *server) Shutdown(ctx context.Context) error {
72
	return nil
73
}
74
75
func (s *server) Exit(ctx context.Context) error {
76
	return nil
77
}