all repos

clerk @ c2e8832

missing tooling for ledger/hledger

clerk/internal/analyzer/analyzer.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
perf: lsp: index transactions by date for the date hover..., 1 month ago
1
package analyzer
2
3
import (
4
	"olexsmir.xyz/clerk/journal"
5
	"olexsmir.xyz/clerk/journal/ast"
6
)
7
8
type Analysis struct {
9
	Files []*journal.ParsedFile
10
11
	Transactions          []*ast.Transaction
12
	PeriodicTransactions  []*ast.PeriodicTransaction
13
	AutomatedTransactions []*ast.AutomatedTransaction
14
	Directives            []ast.Entry // account, commodity, payee, etc
15
16
	Accounts    map[string]*AccountInfo
17
	Commodities map[string]*CommodityInfo
18
	Payees      map[string]*PayeeInfo
19
20
	// AccountAliases maps alias names to the account they resolve to, from
21
	// account "alias" subdirectives and top-level "alias A = B" directives.
22
	AccountAliases map[string]string
23
24
	AccountNames     []string            // sorted for binary search
25
	PayeeNames       []string            // sorted, all payee names from directives + usage
26
	AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"]
27
28
	// PayeeTemplates holds the last transaction's postings per payee name.
29
	PayeeTemplates map[string][]PostingTemplate
30
31
	Tags      map[string]*TagInfo
32
	TagNames  []string // unique tag names, sorted
33
	TagValues []string // unique non-empty tag values across all tags, sorted
34
35
	Dates       []ast.Date // unique transaction dats in sorted order
36
	DateStrings []string   // same order as Dates, "YYYY-MM-DD"
37
38
	TransactionsCountByDate map[string]int                // counts transactions per date, keyed by [formatDate]
39
	TransactionsByKey       map[string][]*ast.Transaction // groups transactions by [TxDuplicateKey] signature
40
}
41
42
type AccountInfo struct {
43
	Directives []*ast.AccountDirective
44
	Usages     []AccountUsage
45
	UsedCount  int
46
	LastUsed   ast.Date
47
}
48
49
type AccountUsage struct {
50
	FileIndex int
51
	Posting   *ast.Posting
52
}
53
54
type CommodityInfo struct {
55
	Directives []*ast.CommodityDirective
56
	Usages     []CommodityUsage
57
	UsedCount  int
58
	LastUsed   ast.Date
59
}
60
61
type CommodityUsage struct {
62
	FileIndex int
63
	Amount    *ast.Amount
64
}
65
66
type PayeeInfo struct {
67
	Directives []*ast.PayeeDirective
68
	Usage      []PayeeUsage
69
	UsedCount  int
70
	LastUsed   ast.Date
71
}
72
73
type PayeeUsage struct {
74
	FileIndex int
75
	Payee     *ast.Payee
76
}
77
78
type TagInfo struct {
79
	Directives []*ast.TagDirective
80
	Usage      []TagUsage
81
	UsedCount  int
82
	LastUsed   ast.Date
83
	Values     []string // unique non-empty values from comment usages, sorted
84
}
85
86
type TagUsage struct {
87
	FileIndex int
88
	Tag       *ast.Tag
89
}
90
91
type PostingTemplate struct {
92
	Account    string
93
	Amount     string
94
	Commodity  string
95
	IsInferred bool // true if the amount was inferred (auto-balanced)
96
}