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.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/out/features/codeActions.d.ts +11 -32
  3. package/out/features/codeActions.d.ts.map +1 -1
  4. package/out/features/codeActions.js +98 -226
  5. package/out/features/codeActions.js.map +1 -1
  6. package/out/features/codeLens.d.ts.map +1 -1
  7. package/out/features/findReferences.d.ts +32 -11
  8. package/out/features/findReferences.d.ts.map +1 -1
  9. package/out/features/findReferences.js +495 -30
  10. package/out/features/findReferences.js.map +1 -1
  11. package/out/features/formatter.js +1 -0
  12. package/out/features/formatter.js.map +1 -1
  13. package/out/features/hover.d.ts.map +1 -1
  14. package/out/features/hover.js +2 -2
  15. package/out/features/hover.js.map +1 -1
  16. package/out/features/inlayHints.d.ts +3 -0
  17. package/out/features/inlayHints.d.ts.map +1 -1
  18. package/out/features/inlayHints.js +112 -301
  19. package/out/features/inlayHints.js.map +1 -1
  20. package/out/features/selectionRange.d.ts +1 -2
  21. package/out/features/selectionRange.d.ts.map +1 -1
  22. package/out/features/selectionRange.js +7 -7
  23. package/out/features/selectionRange.js.map +1 -1
  24. package/out/features/semanticTokens.d.ts +1 -2
  25. package/out/features/semanticTokens.d.ts.map +1 -1
  26. package/out/features/semanticTokens.js +5 -5
  27. package/out/features/semanticTokens.js.map +1 -1
  28. package/out/features/symbols.d.ts +1 -16
  29. package/out/features/symbols.d.ts.map +1 -1
  30. package/out/features/symbols.js +7 -53
  31. package/out/features/symbols.js.map +1 -1
  32. package/out/features/validator.d.ts +1 -0
  33. package/out/features/validator.d.ts.map +1 -1
  34. package/out/features/validator.js +43 -38
  35. package/out/features/validator.js.map +1 -1
  36. package/out/parser/ast.d.ts +1 -1
  37. package/out/parser/ast.d.ts.map +1 -1
  38. package/out/parser/ast.js +55 -6
  39. package/out/parser/ast.js.map +1 -1
  40. package/out/parser/index.d.ts.map +1 -1
  41. package/out/server/workspace.d.ts +5 -0
  42. package/out/server/workspace.d.ts.map +1 -1
  43. package/out/server/workspace.js +28 -0
  44. package/out/server/workspace.js.map +1 -1
  45. package/out/server.js +32 -56
  46. package/out/server.js.map +1 -1
  47. package/out/types.d.ts +1 -0
  48. package/out/types.d.ts.map +1 -1
  49. package/out/types.js.map +1 -1
  50. package/out/utils/balanceCalculator.d.ts +1 -8
  51. package/out/utils/balanceCalculator.d.ts.map +1 -1
  52. package/out/utils/balanceCalculator.js +0 -28
  53. package/out/utils/balanceCalculator.js.map +1 -1
  54. package/out/utils/index.d.ts +18 -2
  55. package/out/utils/index.d.ts.map +1 -1
  56. package/out/utils/index.js +33 -6
  57. package/out/utils/index.js.map +1 -1
  58. package/out/utils/runningBalanceCalculator.d.ts +6 -15
  59. package/out/utils/runningBalanceCalculator.d.ts.map +1 -1
  60. package/out/utils/runningBalanceCalculator.js +40 -81
  61. package/out/utils/runningBalanceCalculator.js.map +1 -1
  62. package/package.json +1 -1
  63. package/out/extension.d.ts +0 -1
  64. package/out/extension.d.ts.map +0 -1
  65. package/out/extension.js +0 -2
  66. 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
- exports.calculateAccountBalances = calculateAccountBalances;
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. Sorts transactions chronologically by date
20
- * 2. Processes each posting to update account balances
21
- * 3. Returns a map of balances after each posting
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
- // Sort transactions by date to calculate balances in chronological order
31
- // This is critical when transactions come from multiple files via includes
32
- const sortedTransactions = [...parsed.transactions].sort((a, b) => {
33
- return a.date.localeCompare(b.date);
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
- // Create a map from sorted index to original index
36
- const sortedToOriginalIndex = new Map();
37
- sortedTransactions.forEach((tx, sortedIdx) => {
38
- const originalIdx = parsed.transactions.indexOf(tx);
39
- sortedToOriginalIndex.set(sortedIdx, originalIdx);
40
- });
41
- for (let sortedIdx = 0; sortedIdx < sortedTransactions.length; sortedIdx++) {
42
- const transaction = sortedTransactions[sortedIdx];
43
- const txIndex = sortedToOriginalIndex.get(sortedIdx);
44
- const postingBalances = new Map();
45
- for (let postingIndex = 0; postingIndex < transaction.postings.length; postingIndex++) {
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
- if (amountMap) {
56
- // Update balance for each commodity in this posting
57
- for (const [commodity, quantity] of amountMap.entries()) {
58
- // Get or create account balance map
59
- if (!accountBalances.has(account)) {
60
- accountBalances.set(account, new Map());
61
- }
62
- const commodityBalances = accountBalances.get(account);
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
- result.set(txIndex, postingBalances);
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 balances;
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;;AA2BH,4DAgEC;AAWD,4DA0BC;AAhHD;;;;;;;;;;GAUG;AACH,SAAgB,wBAAwB,CAAC,MAAsB;IAC7D,MAAM,MAAM,GAAsB,IAAI,GAAG,EAAE,CAAC;IAE5C,wDAAwD;IACxD,MAAM,eAAe,GAAsB,IAAI,GAAG,EAAE,CAAC;IAErD,yEAAyE;IACzE,2EAA2E;IAC3E,MAAM,kBAAkB,GAAG,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAChE,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,mDAAmD;IACnD,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxD,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE;QAC3C,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACpD,qBAAqB,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,KA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AAO,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hledger-lsp",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Language Server Protocol implementation for hledger plain text accounting",
5
5
  "main": "./out/server.js",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- //# sourceMappingURL=extension.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":""}
package/out/extension.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":""}