hledger-lsp 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/out/features/codeActions.d.ts +11 -32
- package/out/features/codeActions.d.ts.map +1 -1
- package/out/features/codeActions.js +98 -226
- package/out/features/codeActions.js.map +1 -1
- package/out/features/codeLens.d.ts.map +1 -1
- package/out/features/findReferences.d.ts +32 -11
- package/out/features/findReferences.d.ts.map +1 -1
- package/out/features/findReferences.js +495 -30
- package/out/features/findReferences.js.map +1 -1
- package/out/features/formatter.js +1 -0
- package/out/features/formatter.js.map +1 -1
- package/out/features/hover.d.ts.map +1 -1
- package/out/features/hover.js +2 -2
- package/out/features/hover.js.map +1 -1
- package/out/features/inlayHints.d.ts +3 -0
- package/out/features/inlayHints.d.ts.map +1 -1
- package/out/features/inlayHints.js +112 -301
- package/out/features/inlayHints.js.map +1 -1
- package/out/features/selectionRange.d.ts +1 -2
- package/out/features/selectionRange.d.ts.map +1 -1
- package/out/features/selectionRange.js +7 -7
- package/out/features/selectionRange.js.map +1 -1
- package/out/features/semanticTokens.d.ts +1 -2
- package/out/features/semanticTokens.d.ts.map +1 -1
- package/out/features/semanticTokens.js +5 -5
- package/out/features/semanticTokens.js.map +1 -1
- package/out/features/symbols.d.ts +1 -16
- package/out/features/symbols.d.ts.map +1 -1
- package/out/features/symbols.js +7 -53
- package/out/features/symbols.js.map +1 -1
- package/out/features/validator.d.ts +1 -0
- package/out/features/validator.d.ts.map +1 -1
- package/out/features/validator.js +43 -38
- package/out/features/validator.js.map +1 -1
- package/out/parser/ast.d.ts +1 -1
- package/out/parser/ast.d.ts.map +1 -1
- package/out/parser/ast.js +55 -6
- package/out/parser/ast.js.map +1 -1
- package/out/parser/index.d.ts.map +1 -1
- package/out/server/workspace.d.ts +5 -0
- package/out/server/workspace.d.ts.map +1 -1
- package/out/server/workspace.js +28 -0
- package/out/server/workspace.js.map +1 -1
- package/out/server.js +32 -56
- package/out/server.js.map +1 -1
- package/out/types.d.ts +1 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/out/utils/balanceCalculator.d.ts +1 -8
- package/out/utils/balanceCalculator.d.ts.map +1 -1
- package/out/utils/balanceCalculator.js +0 -28
- package/out/utils/balanceCalculator.js.map +1 -1
- package/out/utils/index.d.ts +18 -2
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +33 -6
- package/out/utils/index.js.map +1 -1
- package/out/utils/runningBalanceCalculator.d.ts +6 -15
- package/out/utils/runningBalanceCalculator.d.ts.map +1 -1
- package/out/utils/runningBalanceCalculator.js +40 -81
- package/out/utils/runningBalanceCalculator.js.map +1 -1
- package/package.json +1 -1
- package/out/extension.d.ts +0 -1
- package/out/extension.d.ts.map +0 -1
- package/out/extension.js +0 -2
- package/out/extension.js.map +0 -1
|
@@ -4,109 +4,68 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Calculates running balances for all accounts across all transactions,
|
|
6
6
|
* taking into account:
|
|
7
|
-
* - Chronological ordering (by date)
|
|
7
|
+
* - Chronological ordering (by effective date, respecting posting dates)
|
|
8
8
|
* - Multiple commodities per account
|
|
9
9
|
* - Explicit and inferred amounts
|
|
10
10
|
* - Transactions from multiple files (via includes)
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.calculateRunningBalances = calculateRunningBalances;
|
|
14
|
-
|
|
14
|
+
const index_1 = require("./index");
|
|
15
15
|
/**
|
|
16
16
|
* Calculate running balances for all transactions in a parsed document
|
|
17
17
|
*
|
|
18
18
|
* This function:
|
|
19
|
-
* 1.
|
|
20
|
-
* 2.
|
|
21
|
-
* 3.
|
|
19
|
+
* 1. Extracts all postings with their effective dates (respecting posting dates)
|
|
20
|
+
* 2. Sorts postings chronologically by effective date
|
|
21
|
+
* 3. Processes each posting to update account balances
|
|
22
|
+
* 4. Returns a map of balances after each posting
|
|
22
23
|
*
|
|
23
24
|
* @param parsed The parsed document containing all transactions
|
|
24
25
|
* @returns A map of transaction index -> posting index -> commodity -> balance
|
|
25
26
|
*/
|
|
26
27
|
function calculateRunningBalances(parsed) {
|
|
27
28
|
const result = new Map();
|
|
28
|
-
// Track global account balances across all transactions
|
|
29
29
|
const accountBalances = new Map();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const allPostings = [];
|
|
31
|
+
parsed.transactions.forEach((tx, txIdx) => {
|
|
32
|
+
tx.postings.forEach((posting, postingIdx) => {
|
|
33
|
+
allPostings.push({
|
|
34
|
+
transaction: tx,
|
|
35
|
+
posting,
|
|
36
|
+
effectiveDate: (0, index_1.getEffectiveDate)(posting, tx),
|
|
37
|
+
txIndex: txIdx,
|
|
38
|
+
postingIndex: postingIdx
|
|
39
|
+
});
|
|
40
|
+
});
|
|
34
41
|
});
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const posting = transaction.postings[postingIndex];
|
|
47
|
-
const account = posting.account;
|
|
48
|
-
// Get amount (either explicit or inferred)
|
|
49
|
-
let amountMap;
|
|
50
|
-
if (posting.amount) {
|
|
51
|
-
// Explicit amount
|
|
52
|
-
const commodity = posting.amount.commodity || '';
|
|
53
|
-
amountMap = new Map([[commodity, posting.amount.quantity]]);
|
|
42
|
+
// Sort by effective date for chronological processing
|
|
43
|
+
allPostings.sort((a, b) => a.effectiveDate.localeCompare(b.effectiveDate));
|
|
44
|
+
// Process postings in chronological order
|
|
45
|
+
for (const { posting, txIndex, postingIndex } of allPostings) {
|
|
46
|
+
const account = posting.account;
|
|
47
|
+
// Get amount (explicit only - ignore inferred amounts)
|
|
48
|
+
if (posting.amount) {
|
|
49
|
+
const commodity = posting.amount.commodity || '';
|
|
50
|
+
// Initialize account balance map if needed
|
|
51
|
+
if (!accountBalances.has(account)) {
|
|
52
|
+
accountBalances.set(account, new Map());
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Update balance
|
|
64
|
-
const currentBalance = commodityBalances.get(commodity) || 0;
|
|
65
|
-
const newBalance = currentBalance + quantity;
|
|
66
|
-
commodityBalances.set(commodity, newBalance);
|
|
67
|
-
// Store this posting's resulting balance
|
|
68
|
-
if (!postingBalances.has(postingIndex)) {
|
|
69
|
-
postingBalances.set(postingIndex, new Map());
|
|
70
|
-
}
|
|
71
|
-
postingBalances.get(postingIndex).set(commodity, newBalance);
|
|
72
|
-
}
|
|
54
|
+
const commodityBalances = accountBalances.get(account);
|
|
55
|
+
// Update balance
|
|
56
|
+
const currentBalance = commodityBalances.get(commodity) || 0;
|
|
57
|
+
const newBalance = currentBalance + posting.amount.quantity;
|
|
58
|
+
commodityBalances.set(commodity, newBalance);
|
|
59
|
+
// Store this posting's resulting balance in result map
|
|
60
|
+
if (!result.has(txIndex)) {
|
|
61
|
+
result.set(txIndex, new Map());
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Calculate running balances for balance assertion validation
|
|
81
|
-
*
|
|
82
|
-
* This is a simplified version that only tracks account balances,
|
|
83
|
-
* suitable for validating balance assertions.
|
|
84
|
-
*
|
|
85
|
-
* @param transactions List of transactions (will be sorted by date internally)
|
|
86
|
-
* @returns A map of account name -> commodity -> balance
|
|
87
|
-
*/
|
|
88
|
-
function calculateAccountBalances(transactions) {
|
|
89
|
-
const balances = new Map();
|
|
90
|
-
// Sort transactions by date to calculate balances in chronological order
|
|
91
|
-
const sortedTransactions = [...transactions].sort((a, b) => {
|
|
92
|
-
return a.date.localeCompare(b.date);
|
|
93
|
-
});
|
|
94
|
-
for (const transaction of sortedTransactions) {
|
|
95
|
-
for (const posting of transaction.postings) {
|
|
96
|
-
// Update running balance
|
|
97
|
-
// Note: Balance assertions check the ORIGINAL commodity (amount.commodity),
|
|
98
|
-
// not the cost commodity. So we always update balance in the amount's commodity.
|
|
99
|
-
if (posting.amount) {
|
|
100
|
-
const accountBalances = balances.get(posting.account) || new Map();
|
|
101
|
-
const commodity = posting.amount.commodity || '';
|
|
102
|
-
const currentBalance = accountBalances.get(commodity) || 0;
|
|
103
|
-
// Always use the original amount quantity for balance tracking,
|
|
104
|
-
// regardless of whether there's a cost notation
|
|
105
|
-
accountBalances.set(commodity, currentBalance + posting.amount.quantity);
|
|
106
|
-
balances.set(posting.account, accountBalances);
|
|
63
|
+
if (!result.get(txIndex).has(postingIndex)) {
|
|
64
|
+
result.get(txIndex).set(postingIndex, new Map());
|
|
107
65
|
}
|
|
66
|
+
result.get(txIndex).get(postingIndex).set(commodity, newBalance);
|
|
108
67
|
}
|
|
109
68
|
}
|
|
110
|
-
return
|
|
69
|
+
return result;
|
|
111
70
|
}
|
|
112
71
|
//# sourceMappingURL=runningBalanceCalculator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runningBalanceCalculator.js","sourceRoot":"","sources":["../../src/utils/runningBalanceCalculator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;
|
|
1
|
+
{"version":3,"file":"runningBalanceCalculator.js","sourceRoot":"","sources":["../../src/utils/runningBalanceCalculator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA6BH,4DA6DC;AAvFD,mCAA2C;AAc3C;;;;;;;;;;;GAWG;AACH,SAAgB,wBAAwB,CAAC,MAAsB;IAC7D,MAAM,MAAM,GAAsB,IAAI,GAAG,EAAE,CAAC;IAC5C,MAAM,eAAe,GAAsB,IAAI,GAAG,EAAE,CAAC;IAWrD,MAAM,WAAW,GAAyB,EAAE,CAAC;IAE7C,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,E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,SAAS,EAAE,UAAU,CAAC,CAAC;YAE7C,uDAAuD;YACvD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzB,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACjC,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/out/extension.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=extension.d.ts.map
|
package/out/extension.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":""}
|
package/out/extension.js
DELETED
package/out/extension.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":""}
|