all repos

clerk @ ecdc664

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
perf: lsp: index-driven rename edits..., 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
	// AliasDirectives holds every top-level "alias A = B" directive in entry order.
25
	AliasDirectives []*ast.AliasDirective
26
27
	AccountNames     []string            // sorted for binary search
28
	PayeeNames       []string            // sorted, all payee names from directives + usage
29
	AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"]
30
31
	// PayeeTemplates holds the last transaction's postings per payee name.
32
	PayeeTemplates map[string][]PostingTemplate
33
34
	Tags      map[string]*TagInfo
35
	TagNames  []string // unique tag names, sorted
36
	TagValues []string // unique non-empty tag values across all tags, sorted
37
38
	Dates       []ast.Date // unique transaction dats in sorted order
39
	DateStrings []string   // same order as Dates, "YYYY-MM-DD"
40
41
	TransactionsCountByDate map[string]int                // counts transactions per date, keyed by [formatDate]
42
	TransactionsByKey       map[string][]*ast.Transaction // groups transactions by [TxDuplicateKey] signature
43
}
44
45
type AccountInfo struct {
46
	Directives []*ast.AccountDirective
47
	Usages     []AccountUsage
48
	UsedCount  int
49
	LastUsed   ast.Date
50
}
51
52
type AccountUsage struct {
53
	FileIndex int
54
	Posting   *ast.Posting
55
}
56
57
type CommodityInfo struct {
58
	Directives []*ast.CommodityDirective
59
	Usages     []CommodityUsage
60
	UsedCount  int
61
	LastUsed   ast.Date
62
}
63
64
type CommodityUsage struct {
65
	FileIndex int
66
	Amount    *ast.Amount
67
}
68
69
type PayeeInfo struct {
70
	Directives []*ast.PayeeDirective
71
	Usage      []PayeeUsage
72
	UsedCount  int
73
	LastUsed   ast.Date
74
}
75
76
type PayeeUsage struct {
77
	FileIndex int
78
	Payee     *ast.Payee
79
}
80
81
type TagInfo struct {
82
	Directives []*ast.TagDirective
83
	Usage      []TagUsage
84
	UsedCount  int
85
	LastUsed   ast.Date
86
	Values     []string // unique non-empty values from comment usages, sorted
87
}
88
89
type TagUsage struct {
90
	FileIndex int
91
	Tag       *ast.Tag
92
}
93
94
type PostingTemplate struct {
95
	Account    string
96
	Amount     string
97
	Commodity  string
98
	IsInferred bool // true if the amount was inferred (auto-balanced)
99
}