hinmil 0.0.0-stage → 0.2.0

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 (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2306 -2
  3. package/dist/cli.d.ts +15 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +338 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commentParser.d.ts +384 -0
  8. package/dist/commentParser.d.ts.map +1 -0
  9. package/dist/commentParser.js +2487 -0
  10. package/dist/commentParser.js.map +1 -0
  11. package/dist/config.d.ts +203 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +375 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/debugLog.d.ts +13 -0
  16. package/dist/debugLog.d.ts.map +1 -0
  17. package/dist/debugLog.js +44 -0
  18. package/dist/debugLog.js.map +1 -0
  19. package/dist/estree.d.ts +100 -0
  20. package/dist/estree.d.ts.map +1 -0
  21. package/dist/estree.js +34 -0
  22. package/dist/estree.js.map +1 -0
  23. package/dist/hm/env.d.ts +134 -0
  24. package/dist/hm/env.d.ts.map +1 -0
  25. package/dist/hm/env.js +939 -0
  26. package/dist/hm/env.js.map +1 -0
  27. package/dist/hm/index.d.ts +7 -0
  28. package/dist/hm/index.d.ts.map +1 -0
  29. package/dist/hm/index.js +26 -0
  30. package/dist/hm/index.js.map +1 -0
  31. package/dist/hm/substitution.d.ts +57 -0
  32. package/dist/hm/substitution.d.ts.map +1 -0
  33. package/dist/hm/substitution.js +546 -0
  34. package/dist/hm/substitution.js.map +1 -0
  35. package/dist/hm/typeParser.d.ts +39 -0
  36. package/dist/hm/typeParser.d.ts.map +1 -0
  37. package/dist/hm/typeParser.js +1285 -0
  38. package/dist/hm/typeParser.js.map +1 -0
  39. package/dist/hm/typeUtils.d.ts +248 -0
  40. package/dist/hm/typeUtils.d.ts.map +1 -0
  41. package/dist/hm/typeUtils.js +905 -0
  42. package/dist/hm/typeUtils.js.map +1 -0
  43. package/dist/hm/types.d.ts +738 -0
  44. package/dist/hm/types.d.ts.map +1 -0
  45. package/dist/hm/types.js +1853 -0
  46. package/dist/hm/types.js.map +1 -0
  47. package/dist/hm/unify.d.ts +59 -0
  48. package/dist/hm/unify.d.ts.map +1 -0
  49. package/dist/hm/unify.js +1700 -0
  50. package/dist/hm/unify.js.map +1 -0
  51. package/dist/index.d.ts +20 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +196 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/infer/annotation-rigid.d.ts +76 -0
  56. package/dist/infer/annotation-rigid.d.ts.map +1 -0
  57. package/dist/infer/annotation-rigid.js +542 -0
  58. package/dist/infer/annotation-rigid.js.map +1 -0
  59. package/dist/infer/annotation-validation.d.ts +109 -0
  60. package/dist/infer/annotation-validation.d.ts.map +1 -0
  61. package/dist/infer/annotation-validation.js +1078 -0
  62. package/dist/infer/annotation-validation.js.map +1 -0
  63. package/dist/infer/annotations.d.ts +277 -0
  64. package/dist/infer/annotations.d.ts.map +1 -0
  65. package/dist/infer/annotations.js +1343 -0
  66. package/dist/infer/annotations.js.map +1 -0
  67. package/dist/infer/call-overloads.d.ts +24 -0
  68. package/dist/infer/call-overloads.d.ts.map +1 -0
  69. package/dist/infer/call-overloads.js +900 -0
  70. package/dist/infer/call-overloads.js.map +1 -0
  71. package/dist/infer/call-rows.d.ts +154 -0
  72. package/dist/infer/call-rows.d.ts.map +1 -0
  73. package/dist/infer/call-rows.js +2162 -0
  74. package/dist/infer/call-rows.js.map +1 -0
  75. package/dist/infer/calls.d.ts +20 -0
  76. package/dist/infer/calls.d.ts.map +1 -0
  77. package/dist/infer/calls.js +1468 -0
  78. package/dist/infer/calls.js.map +1 -0
  79. package/dist/infer/constraints.d.ts +99 -0
  80. package/dist/infer/constraints.d.ts.map +1 -0
  81. package/dist/infer/constraints.js +1208 -0
  82. package/dist/infer/constraints.js.map +1 -0
  83. package/dist/infer/expr-assignment.d.ts +20 -0
  84. package/dist/infer/expr-assignment.d.ts.map +1 -0
  85. package/dist/infer/expr-assignment.js +620 -0
  86. package/dist/infer/expr-assignment.js.map +1 -0
  87. package/dist/infer/expr-constraint-lookup.d.ts +44 -0
  88. package/dist/infer/expr-constraint-lookup.d.ts.map +1 -0
  89. package/dist/infer/expr-constraint-lookup.js +207 -0
  90. package/dist/infer/expr-constraint-lookup.js.map +1 -0
  91. package/dist/infer/expr-functions.d.ts +20 -0
  92. package/dist/infer/expr-functions.d.ts.map +1 -0
  93. package/dist/infer/expr-functions.js +1359 -0
  94. package/dist/infer/expr-functions.js.map +1 -0
  95. package/dist/infer/expr-jsx.d.ts +19 -0
  96. package/dist/infer/expr-jsx.d.ts.map +1 -0
  97. package/dist/infer/expr-jsx.js +310 -0
  98. package/dist/infer/expr-jsx.js.map +1 -0
  99. package/dist/infer/expr-member.d.ts +40 -0
  100. package/dist/infer/expr-member.d.ts.map +1 -0
  101. package/dist/infer/expr-member.js +1154 -0
  102. package/dist/infer/expr-member.js.map +1 -0
  103. package/dist/infer/expr-prototype.d.ts +11 -0
  104. package/dist/infer/expr-prototype.d.ts.map +1 -0
  105. package/dist/infer/expr-prototype.js +202 -0
  106. package/dist/infer/expr-prototype.js.map +1 -0
  107. package/dist/infer/expressions.d.ts +40 -0
  108. package/dist/infer/expressions.d.ts.map +1 -0
  109. package/dist/infer/expressions.js +1497 -0
  110. package/dist/infer/expressions.js.map +1 -0
  111. package/dist/infer/functionPatterns.d.ts +229 -0
  112. package/dist/infer/functionPatterns.d.ts.map +1 -0
  113. package/dist/infer/functionPatterns.js +1035 -0
  114. package/dist/infer/functionPatterns.js.map +1 -0
  115. package/dist/infer/helpers.d.ts +73 -0
  116. package/dist/infer/helpers.d.ts.map +1 -0
  117. package/dist/infer/helpers.js +187 -0
  118. package/dist/infer/helpers.js.map +1 -0
  119. package/dist/infer/index.d.ts +551 -0
  120. package/dist/infer/index.d.ts.map +1 -0
  121. package/dist/infer/index.js +1127 -0
  122. package/dist/infer/index.js.map +1 -0
  123. package/dist/infer/jsx-dom.d.ts +26 -0
  124. package/dist/infer/jsx-dom.d.ts.map +1 -0
  125. package/dist/infer/jsx-dom.js +303 -0
  126. package/dist/infer/jsx-dom.js.map +1 -0
  127. package/dist/infer/moduleReps.d.ts +7 -0
  128. package/dist/infer/moduleReps.d.ts.map +1 -0
  129. package/dist/infer/moduleReps.js +48 -0
  130. package/dist/infer/moduleReps.js.map +1 -0
  131. package/dist/infer/modules.d.ts +10 -0
  132. package/dist/infer/modules.d.ts.map +1 -0
  133. package/dist/infer/modules.js +775 -0
  134. package/dist/infer/modules.js.map +1 -0
  135. package/dist/infer/narrowing.d.ts +199 -0
  136. package/dist/infer/narrowing.d.ts.map +1 -0
  137. package/dist/infer/narrowing.js +1428 -0
  138. package/dist/infer/narrowing.js.map +1 -0
  139. package/dist/infer/results.d.ts +24 -0
  140. package/dist/infer/results.d.ts.map +1 -0
  141. package/dist/infer/results.js +611 -0
  142. package/dist/infer/results.js.map +1 -0
  143. package/dist/infer/setupPass.d.ts +11 -0
  144. package/dist/infer/setupPass.d.ts.map +1 -0
  145. package/dist/infer/setupPass.js +524 -0
  146. package/dist/infer/setupPass.js.map +1 -0
  147. package/dist/infer/statements.d.ts +26 -0
  148. package/dist/infer/statements.d.ts.map +1 -0
  149. package/dist/infer/statements.js +750 -0
  150. package/dist/infer/statements.js.map +1 -0
  151. package/dist/infer/stmt-bindings.d.ts +22 -0
  152. package/dist/infer/stmt-bindings.d.ts.map +1 -0
  153. package/dist/infer/stmt-bindings.js +1482 -0
  154. package/dist/infer/stmt-bindings.js.map +1 -0
  155. package/dist/infer/stmt-destructure.d.ts +29 -0
  156. package/dist/infer/stmt-destructure.d.ts.map +1 -0
  157. package/dist/infer/stmt-destructure.js +490 -0
  158. package/dist/infer/stmt-destructure.js.map +1 -0
  159. package/dist/infer/types.d.ts +220 -0
  160. package/dist/infer/types.d.ts.map +1 -0
  161. package/dist/infer/types.js +46 -0
  162. package/dist/infer/types.js.map +1 -0
  163. package/dist/infer/unifyDiag.d.ts +46 -0
  164. package/dist/infer/unifyDiag.d.ts.map +1 -0
  165. package/dist/infer/unifyDiag.js +642 -0
  166. package/dist/infer/unifyDiag.js.map +1 -0
  167. package/dist/parsing-babel.d.ts +3 -0
  168. package/dist/parsing-babel.d.ts.map +1 -0
  169. package/dist/parsing-babel.js +353 -0
  170. package/dist/parsing-babel.js.map +1 -0
  171. package/dist/parsing.d.ts +69 -0
  172. package/dist/parsing.d.ts.map +1 -0
  173. package/dist/parsing.js +288 -0
  174. package/dist/parsing.js.map +1 -0
  175. package/dist/registries/constraintRegistry.d.ts +233 -0
  176. package/dist/registries/constraintRegistry.d.ts.map +1 -0
  177. package/dist/registries/constraintRegistry.js +803 -0
  178. package/dist/registries/constraintRegistry.js.map +1 -0
  179. package/dist/registries/dataTypeRegistry.d.ts +63 -0
  180. package/dist/registries/dataTypeRegistry.d.ts.map +1 -0
  181. package/dist/registries/dataTypeRegistry.js +180 -0
  182. package/dist/registries/dataTypeRegistry.js.map +1 -0
  183. package/dist/registries/domGlobals.d.ts +33 -0
  184. package/dist/registries/domGlobals.d.ts.map +1 -0
  185. package/dist/registries/domGlobals.js +309 -0
  186. package/dist/registries/domGlobals.js.map +1 -0
  187. package/dist/registries/methodRegistry.d.ts +277 -0
  188. package/dist/registries/methodRegistry.d.ts.map +1 -0
  189. package/dist/registries/methodRegistry.js +2074 -0
  190. package/dist/registries/methodRegistry.js.map +1 -0
  191. package/dist/registries/session.d.ts +38 -0
  192. package/dist/registries/session.d.ts.map +1 -0
  193. package/dist/registries/session.js +75 -0
  194. package/dist/registries/session.js.map +1 -0
  195. package/dist/server.d.ts +2 -0
  196. package/dist/server.d.ts.map +1 -0
  197. package/dist/server.js +1896 -0
  198. package/dist/server.js.map +1 -0
  199. package/dist/services/codeActions.d.ts +22 -0
  200. package/dist/services/codeActions.d.ts.map +1 -0
  201. package/dist/services/codeActions.js +465 -0
  202. package/dist/services/codeActions.js.map +1 -0
  203. package/dist/services/completion.d.ts +259 -0
  204. package/dist/services/completion.d.ts.map +1 -0
  205. package/dist/services/completion.js +2794 -0
  206. package/dist/services/completion.js.map +1 -0
  207. package/dist/services/definitions.d.ts +37 -0
  208. package/dist/services/definitions.d.ts.map +1 -0
  209. package/dist/services/definitions.js +605 -0
  210. package/dist/services/definitions.js.map +1 -0
  211. package/dist/services/diagnosticCodes.d.ts +70 -0
  212. package/dist/services/diagnosticCodes.d.ts.map +1 -0
  213. package/dist/services/diagnosticCodes.js +239 -0
  214. package/dist/services/diagnosticCodes.js.map +1 -0
  215. package/dist/services/diagnostics.d.ts +86 -0
  216. package/dist/services/diagnostics.d.ts.map +1 -0
  217. package/dist/services/diagnostics.js +665 -0
  218. package/dist/services/diagnostics.js.map +1 -0
  219. package/dist/services/documentCache.d.ts +88 -0
  220. package/dist/services/documentCache.d.ts.map +1 -0
  221. package/dist/services/documentCache.js +108 -0
  222. package/dist/services/documentCache.js.map +1 -0
  223. package/dist/services/documentSymbols.d.ts +20 -0
  224. package/dist/services/documentSymbols.d.ts.map +1 -0
  225. package/dist/services/documentSymbols.js +381 -0
  226. package/dist/services/documentSymbols.js.map +1 -0
  227. package/dist/services/fileSelection.d.ts +24 -0
  228. package/dist/services/fileSelection.d.ts.map +1 -0
  229. package/dist/services/fileSelection.js +154 -0
  230. package/dist/services/fileSelection.js.map +1 -0
  231. package/dist/services/fileSelectionRefresh.d.ts +26 -0
  232. package/dist/services/fileSelectionRefresh.d.ts.map +1 -0
  233. package/dist/services/fileSelectionRefresh.js +77 -0
  234. package/dist/services/fileSelectionRefresh.js.map +1 -0
  235. package/dist/services/files.d.ts +342 -0
  236. package/dist/services/files.d.ts.map +1 -0
  237. package/dist/services/files.js +1712 -0
  238. package/dist/services/files.js.map +1 -0
  239. package/dist/services/fsProbe.d.ts +14 -0
  240. package/dist/services/fsProbe.d.ts.map +1 -0
  241. package/dist/services/fsProbe.js +112 -0
  242. package/dist/services/fsProbe.js.map +1 -0
  243. package/dist/services/globalsLoader.d.ts +20 -0
  244. package/dist/services/globalsLoader.d.ts.map +1 -0
  245. package/dist/services/globalsLoader.js +122 -0
  246. package/dist/services/globalsLoader.js.map +1 -0
  247. package/dist/services/hmFileServices.d.ts +113 -0
  248. package/dist/services/hmFileServices.d.ts.map +1 -0
  249. package/dist/services/hmFileServices.js +686 -0
  250. package/dist/services/hmFileServices.js.map +1 -0
  251. package/dist/services/hover.d.ts +280 -0
  252. package/dist/services/hover.d.ts.map +1 -0
  253. package/dist/services/hover.js +1687 -0
  254. package/dist/services/hover.js.map +1 -0
  255. package/dist/services/importContext.d.ts +396 -0
  256. package/dist/services/importContext.d.ts.map +1 -0
  257. package/dist/services/importContext.js +1999 -0
  258. package/dist/services/importContext.js.map +1 -0
  259. package/dist/services/projectChecker.d.ts +50 -0
  260. package/dist/services/projectChecker.d.ts.map +1 -0
  261. package/dist/services/projectChecker.js +228 -0
  262. package/dist/services/projectChecker.js.map +1 -0
  263. package/dist/services/references.d.ts +41 -0
  264. package/dist/services/references.d.ts.map +1 -0
  265. package/dist/services/references.js +757 -0
  266. package/dist/services/references.js.map +1 -0
  267. package/dist/services/rename.d.ts +22 -0
  268. package/dist/services/rename.d.ts.map +1 -0
  269. package/dist/services/rename.js +101 -0
  270. package/dist/services/rename.js.map +1 -0
  271. package/dist/services/shortCircuit.d.ts +27 -0
  272. package/dist/services/shortCircuit.d.ts.map +1 -0
  273. package/dist/services/shortCircuit.js +28 -0
  274. package/dist/services/shortCircuit.js.map +1 -0
  275. package/dist/services/sidecarPerf.d.ts +19 -0
  276. package/dist/services/sidecarPerf.d.ts.map +1 -0
  277. package/dist/services/sidecarPerf.js +59 -0
  278. package/dist/services/sidecarPerf.js.map +1 -0
  279. package/dist/services/signatureHelp.d.ts +27 -0
  280. package/dist/services/signatureHelp.d.ts.map +1 -0
  281. package/dist/services/signatureHelp.js +984 -0
  282. package/dist/services/signatureHelp.js.map +1 -0
  283. package/dist/walking.d.ts +25 -0
  284. package/dist/walking.d.ts.map +1 -0
  285. package/dist/walking.js +107 -0
  286. package/dist/walking.js.map +1 -0
  287. package/hm-types-builtin/assert.hm +20 -0
  288. package/hm-types-builtin/buffer.hm +8 -0
  289. package/hm-types-builtin/child_process.hm +16 -0
  290. package/hm-types-builtin/crypto.hm +17 -0
  291. package/hm-types-builtin/fs.hm +15 -0
  292. package/hm-types-builtin/http.hm +14 -0
  293. package/hm-types-builtin/os.hm +19 -0
  294. package/hm-types-builtin/path.hm +18 -0
  295. package/hm-types-builtin/react-dom.hm +27 -0
  296. package/hm-types-builtin/react.hm +113 -0
  297. package/hm-types-builtin/url.hm +7 -0
  298. package/hm-types-builtin/zlib.hm +12 -0
  299. package/package.json +53 -4
  300. package/schemas/hinmil.config.schema.json +261 -0
  301. package/schemas/package-hinmil.schema.json +59 -0
@@ -0,0 +1,665 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Diagnostics — LSP diagnostic creation and filtering helpers
4
+ //
5
+ // Plain language: this file turns the engine's internal findings into the
6
+ // squiggly underlines users see — mapping each finding to an editor warning
7
+ // with a location, severity and code — and then filters the list according
8
+ // to the user's settings (e.g. "trust my annotations", "hide missing-
9
+ // signature hints") so only wanted warnings reach the screen.
10
+ // ============================================================================
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.levelToSeverity = levelToSeverity;
46
+ exports.mapInferenceDiagnostics = mapInferenceDiagnostics;
47
+ exports.detectMissingSignatures = detectMissingSignatures;
48
+ exports.filterIgnoredDiagnostics = filterIgnoredDiagnostics;
49
+ exports.filterAnnotationMismatchDiagnostics = filterAnnotationMismatchDiagnostics;
50
+ exports.filterDiagnosticsInsideBindings = filterDiagnosticsInsideBindings;
51
+ exports.collectBindingIntervals = collectBindingIntervals;
52
+ exports.detectDuplicateImports = detectDuplicateImports;
53
+ exports.detectCircularImports = detectCircularImports;
54
+ const node_1 = require("vscode-languageserver/node");
55
+ const walk = __importStar(require("../walking"));
56
+ const parsing_1 = require("../parsing");
57
+ const commentParser_1 = require("../commentParser");
58
+ const dataTypeRegistry_1 = require("../registries/dataTypeRegistry");
59
+ const diagnosticCodes_1 = require("./diagnosticCodes");
60
+ const hover_1 = require("./hover");
61
+ const files_1 = require("./files");
62
+ // ---------------------------------------------------------------------------
63
+ // Severity helpers
64
+ // ---------------------------------------------------------------------------
65
+ /**
66
+ * Convert a {@link DiagnosticLevel} to the corresponding LSP
67
+ * `DiagnosticSeverity` enum value, or `null` for `'off'` (the diagnostic
68
+ * should be dropped entirely).
69
+ */
70
+ function levelToSeverity(level) {
71
+ switch (level) {
72
+ case 'off': return null;
73
+ case 'hint': return node_1.DiagnosticSeverity.Hint;
74
+ case 'information': return node_1.DiagnosticSeverity.Information;
75
+ case 'warning': return node_1.DiagnosticSeverity.Warning;
76
+ case 'error': return node_1.DiagnosticSeverity.Error;
77
+ }
78
+ }
79
+ // ---------------------------------------------------------------------------
80
+ // Inference → LSP diagnostic mapping
81
+ // ---------------------------------------------------------------------------
82
+ /**
83
+ * Convert inference-level diagnostics (offset-based) to LSP `Diagnostic`
84
+ * objects. Parse errors are filtered out (they are too noisy while the
85
+ * user is still typing).
86
+ *
87
+ * @param inferDiags Raw diagnostics produced by the inference engine.
88
+ * @param textDocument The LSP text document (used for offset → position conversion).
89
+ * @param insertions Insertion offsets from `normalizeArrayLiteralASI` — used
90
+ * to map patched offsets back to the original source.
91
+ * @param severityFor Maps a diagnostic code to its configured LSP severity;
92
+ * `null` drops the diagnostic (its category is `'off'`).
93
+ * An engine-attached severity takes precedence over the
94
+ * returned severity, but `null` still drops.
95
+ */
96
+ function mapInferenceDiagnostics(inferDiags, textDocument, insertions, severityFor, unmapOffset) {
97
+ const out = [];
98
+ for (const d of inferDiags) {
99
+ if (d.message.startsWith('Parse error'))
100
+ continue;
101
+ const code = (0, diagnosticCodes_1.classifyDiagnosticCode)(d.message);
102
+ const severity = severityFor(code);
103
+ if (severity === null)
104
+ continue;
105
+ const origStart = unmapOffset(d.start, insertions);
106
+ const origEnd = unmapOffset(d.end, insertions);
107
+ const startPos = textDocument.positionAt(origStart);
108
+ const endPos = textDocument.positionAt(origEnd);
109
+ const diag = {
110
+ severity: d.severity ?? severity,
111
+ range: { start: startPos, end: endPos },
112
+ message: d.message,
113
+ source: 'hinmil',
114
+ code,
115
+ };
116
+ if (d.relatedInformation && d.relatedInformation.length > 0) {
117
+ diag.relatedInformation = d.relatedInformation.map((ri) => {
118
+ const riStart = unmapOffset(ri.start, insertions);
119
+ const riEnd = unmapOffset(ri.end, insertions);
120
+ return node_1.DiagnosticRelatedInformation.create(node_1.Location.create(textDocument.uri, node_1.Range.create(textDocument.positionAt(riStart), textDocument.positionAt(riEnd))), ri.message);
121
+ });
122
+ }
123
+ out.push(diag);
124
+ }
125
+ return out;
126
+ }
127
+ // ---------------------------------------------------------------------------
128
+ // Missing-signature detection
129
+ // ---------------------------------------------------------------------------
130
+ /** Push a "missing HM type signature" diagnostic for a given node range. */
131
+ function pushMissingSigDiag(diagnostics, textDocument, severity, start, end, label, name) {
132
+ diagnostics.push({
133
+ severity,
134
+ range: { start: textDocument.positionAt(start), end: textDocument.positionAt(end) },
135
+ message: `${label} '${name}' has no HM annotation`,
136
+ source: 'hinmil',
137
+ code: diagnosticCodes_1.HM_MISSING_SIGNATURE,
138
+ });
139
+ }
140
+ /**
141
+ * Check whether an annotation exists for a given declaration name.
142
+ * Handles the `X$prototype$Y` ↔ `X#Y` aliasing convention.
143
+ */
144
+ function hasAnnotation(annotations, name) {
145
+ if (annotations.has(name))
146
+ return true;
147
+ const alias = (0, hover_1.prototypeToHashName)(name);
148
+ return alias !== null && annotations.has(alias);
149
+ }
150
+ /**
151
+ * Check whether *any* annotation (including parse-error ones that never made
152
+ * it into the annotation map) exists for a given declaration name. Used to
153
+ * suppress "missing HM annotation" when the user has provided an annotation
154
+ * with a syntax error — the parse-error diagnostic already covers that case.
155
+ */
156
+ function hasAnnotationIncludingErrored(annotations, erroredNames, name) {
157
+ if (hasAnnotation(annotations, name))
158
+ return true;
159
+ if (erroredNames.has(name))
160
+ return true;
161
+ const alias = (0, hover_1.prototypeToHashName)(name);
162
+ return alias !== null && erroredNames.has(alias);
163
+ }
164
+ /**
165
+ * Check whether an annotation exists that is directly attached to a method
166
+ * at a given offset (handles TypeName#method annotations, e.g. Maybe#map).
167
+ */
168
+ function hasAnnotationAtOffset(annotations, offset) {
169
+ for (const ann of annotations.values()) {
170
+ if (ann.nodeStart === offset)
171
+ return true;
172
+ }
173
+ return false;
174
+ }
175
+ /**
176
+ * Check whether a parent-type method annotation exists for a given method name.
177
+ * E.g. `Maybe#map :: Maybe a ~> ...` is a parent-type annotation that covers
178
+ * all subtypes (Just, Nothing) even if they don't have their own annotation.
179
+ * A parent-type annotation is one where the key's type name matches the
180
+ * receiver's TCon name (e.g. Maybe#map has receiver Maybe).
181
+ */
182
+ function hasParentMethodAnnotation(annotations, className, methodName) {
183
+ const parentName = (0, dataTypeRegistry_1.getParentTypeName)(className);
184
+ if (!parentName)
185
+ return false;
186
+ return annotations.has(`${parentName}#${methodName}`);
187
+ }
188
+ /**
189
+ * True when `node` is a call to an already-annotated top-level binding, e.g.
190
+ * `leftIdentity(C)` where `leftIdentity` has an HM annotation. Such a value is
191
+ * fully derivable by inference without any extra help.
192
+ */
193
+ function isCallToAnnotatedFn(node, hasAnn) {
194
+ const call = node;
195
+ if (!call || call.type !== 'CallExpression')
196
+ return false;
197
+ const callee = call.callee;
198
+ return callee?.type === 'Identifier' && hasAnn(callee.name);
199
+ }
200
+ /**
201
+ * True when `node` is a plain reference to an already-annotated top-level
202
+ * binding, e.g. the shorthand property in `({ associativity })` where
203
+ * `associativity` has an HM annotation.
204
+ */
205
+ function isRefToAnnotatedBinding(node, hasAnn) {
206
+ const ident = node;
207
+ return ident?.type === 'Identifier' && hasAnn(ident.name);
208
+ }
209
+ /**
210
+ * True when `obj` is a non-empty object literal whose every field value is
211
+ * either a call to an already-annotated binding (see {@link isCallToAnnotatedFn})
212
+ * or a direct reference to one (see {@link isRefToAnnotatedBinding}).
213
+ */
214
+ function objectAllFieldsAnnotated(obj, hasAnn) {
215
+ if (obj.type !== 'ObjectExpression' || obj.properties.length === 0)
216
+ return false;
217
+ for (const prop of obj.properties) {
218
+ const p = prop;
219
+ if (p.type !== 'Property' || p.computed)
220
+ return false;
221
+ if (!isCallToAnnotatedFn(p.value, hasAnn) && !isRefToAnnotatedBinding(p.value, hasAnn))
222
+ return false;
223
+ }
224
+ return true;
225
+ }
226
+ /**
227
+ * True when `fn` is a function/arrow (possibly curried) whose ultimate return
228
+ * value is an object literal whose fields are all calls to, or direct
229
+ * references to, annotated bindings. In that case inference can fully derive
230
+ * the wrapper's type from the referenced definitions, so the "missing HM
231
+ * annotation" warning is redundant.
232
+ *
233
+ * Handles `C => ({ ... })`, `C => a => ({ ... })`, `() => ({ law1, law2 })`,
234
+ * and block bodies with a top-level `return { ... }`.
235
+ */
236
+ function returnsAnnotatedObjectLiteral(fn, hasAnn) {
237
+ const f = fn;
238
+ if (!f || (f.type !== 'ArrowFunctionExpression' && f.type !== 'FunctionExpression' && f.type !== 'FunctionDeclaration')) {
239
+ return false;
240
+ }
241
+ let body = f.body;
242
+ // Unwrap curried arrow/function chains: `C => a => ({ ... })`.
243
+ while (body && (body.type === 'ArrowFunctionExpression' || body.type === 'FunctionExpression')) {
244
+ body = body.body;
245
+ }
246
+ if (!body)
247
+ return false;
248
+ if (body.type === 'ObjectExpression') {
249
+ return objectAllFieldsAnnotated(body, hasAnn);
250
+ }
251
+ if (body.type === 'BlockStatement') {
252
+ for (const st of body.body) {
253
+ if (st.type === 'ReturnStatement' && st.argument?.type === 'ObjectExpression') {
254
+ return objectAllFieldsAnnotated(st.argument, hasAnn);
255
+ }
256
+ }
257
+ }
258
+ return false;
259
+ }
260
+ /** `curry ((a, b) => …)`, `curryN (3) (function (a, b, c) { … })`: a call
261
+ * whose only argument is a function literal. */
262
+ function wrapsOneFunctionLiteral(call) {
263
+ if (call.arguments.length !== 1)
264
+ return false;
265
+ const arg = call.arguments[0];
266
+ return arg.type === 'ArrowFunctionExpression' || arg.type === 'FunctionExpression';
267
+ }
268
+ /** `require ("x")`, `require ("x").y` or `require ("x") (…)`-style imports. */
269
+ function isRequireLike(node) {
270
+ let n = node;
271
+ while (n && (n.type === 'CallExpression' || n.type === 'MemberExpression')) {
272
+ if (n.type === 'CallExpression') {
273
+ const callee = n.callee;
274
+ if (callee.type === 'Identifier' && callee.name === 'require')
275
+ return true;
276
+ n = callee;
277
+ }
278
+ else {
279
+ n = n.object;
280
+ }
281
+ }
282
+ return false;
283
+ }
284
+ /**
285
+ * Detect top-level function declarations and arrow/function-expression
286
+ * bindings that lack an HM type annotation and produce an informational
287
+ * diagnostic for each one.
288
+ *
289
+ * @param source Original (un-patched) source code of the file.
290
+ * @param textDocument LSP text document for offset → position mapping.
291
+ * @param annotations Map of declaration names that *do* have an HM annotation.
292
+ * @param fnSeverity Severity for function/method diagnostics (null to skip).
293
+ * @param varSeverity Severity for non-function variable diagnostics (null to skip).
294
+ */
295
+ function detectMissingSignatures(source, textDocument, annotations, fnSeverity, varSeverity, isFunctionValuedAt) {
296
+ const diagnostics = [];
297
+ // Build a set of names whose annotation failed to parse. These are *not*
298
+ // in `annotations` (buildAnnotationMap drops failed entries), but the user
299
+ // *did* provide an annotation — so we must not also report "missing HM
300
+ // annotation" on top of the parse-error diagnostic.
301
+ const erroredNames = new Set();
302
+ const erroredOffsets = new Set();
303
+ for (const ann of (0, commentParser_1.extractAnnotations)(source)) {
304
+ if (!ann.error)
305
+ continue;
306
+ if (ann.name)
307
+ erroredNames.add(ann.name);
308
+ if (ann.nodeStart !== undefined)
309
+ erroredOffsets.add(ann.nodeStart);
310
+ }
311
+ const hasAnn = (name) => hasAnnotationIncludingErrored(annotations, erroredNames, name);
312
+ const hasAnnAtOffset = (offset) => hasAnnotationAtOffset(annotations, offset) || erroredOffsets.has(offset);
313
+ try {
314
+ const ast = (0, parsing_1.parseStrict)(source);
315
+ for (const stmt of ast.body) {
316
+ // Unwrap export wrappers
317
+ const decl = (stmt.type === 'ExportNamedDeclaration' || stmt.type === 'ExportDefaultDeclaration')
318
+ && stmt.declaration ? stmt.declaration : stmt;
319
+ // Case 1: function declarations — function foo() { ... }
320
+ if (decl.type === 'FunctionDeclaration' && decl.id?.name && fnSeverity != null) {
321
+ const name = decl.id.name;
322
+ // A function whose name matches a registered sumtype carrier is
323
+ // already "annotated" via the `// TypeName :: V1 | V2` directive.
324
+ // A wrapper that returns an object literal built entirely from calls to
325
+ // annotated bindings is fully derivable — no annotation needed.
326
+ if (!hasAnn(name) && !(0, dataTypeRegistry_1.isDataType)(name) && !returnsAnnotatedObjectLiteral(decl, hasAnn)) {
327
+ pushMissingSigDiag(diagnostics, textDocument, fnSeverity, decl.id.start, decl.id.end, 'Function', name);
328
+ }
329
+ }
330
+ // Case 2: class declarations — check each method for missing signature
331
+ if (decl.type === 'ClassDeclaration' && decl.id?.name && fnSeverity != null) {
332
+ const className = decl.id.name;
333
+ for (const member of (decl.body?.body ?? [])) {
334
+ if (member.type !== 'MethodDefinition')
335
+ continue;
336
+ if (member.key?.type !== 'Identifier')
337
+ continue;
338
+ const methodName = member.key.name;
339
+ if (methodName === 'constructor')
340
+ continue;
341
+ const isStatic = !!member.static;
342
+ const qualifiedName = isStatic ? `${className}.${methodName}` : `${className}#${methodName}`;
343
+ // Accept both ClassName#method and TypeName#method (e.g. Just#map or Maybe#map)
344
+ if (!hasAnn(qualifiedName) && !hasAnnAtOffset(member.value?.start)
345
+ && !hasParentMethodAnnotation(annotations, className, methodName)) {
346
+ pushMissingSigDiag(diagnostics, textDocument, fnSeverity, member.key.start, member.key.end, 'Method', qualifiedName);
347
+ }
348
+ }
349
+ }
350
+ // Case 3: const/let/var bindings
351
+ if (decl.type === 'VariableDeclaration') {
352
+ for (const declarator of decl.declarations) {
353
+ if (declarator.id?.name == null || !declarator.init)
354
+ continue;
355
+ const name = declarator.id.name;
356
+ // Sumtype carrier bindings (e.g. `const Param = function () {}`
357
+ // beneath `// Param :: Path | Query`) are covered by the directive.
358
+ if (!hasAnn(name) && !(0, dataTypeRegistry_1.isDataType)(name)) {
359
+ // A point-free binding (partial application or composition of
360
+ // existing functions: `pipe (map (prop ("total")), sum)`,
361
+ // `subtract (__, 2.5)`) is fully derived from those functions and
362
+ // is not asked for a signature. A call that wraps one function
363
+ // literal (`curry ((a, b) => …)`) defines a new function and is.
364
+ if (declarator.init.type === 'CallExpression' && !isRequireLike(declarator.init)
365
+ && !!isFunctionValuedAt?.(declarator.id.start)
366
+ && !wrapsOneFunctionLiteral(declarator.init))
367
+ continue;
368
+ const isFn = declarator.init.type === 'ArrowFunctionExpression' ||
369
+ declarator.init.type === 'FunctionExpression' ||
370
+ // A function built by a call (`const f = curry (…)`,
371
+ // `compose (g) (h)`) is a function too, judged by its INFERRED
372
+ // type. Imports (`require (…)`) are not definitions and are
373
+ // never asked for a signature.
374
+ (declarator.init.type === 'CallExpression' && !isRequireLike(declarator.init)
375
+ && !!isFunctionValuedAt?.(declarator.id.start));
376
+ // A function wrapper that returns an object literal built entirely
377
+ // from calls to annotated bindings is fully derivable by inference.
378
+ if (isFn && returnsAnnotatedObjectLiteral(declarator.init, hasAnn))
379
+ continue;
380
+ const sev = isFn ? fnSeverity : varSeverity;
381
+ if (sev == null)
382
+ continue;
383
+ const label = isFn ? 'Function' : 'Variable';
384
+ pushMissingSigDiag(diagnostics, textDocument, sev, declarator.id.start, declarator.id.end, label, name);
385
+ }
386
+ }
387
+ }
388
+ // Case 4: prototype method assignments — X.prototype.method = function() { ... }
389
+ if (fnSeverity != null
390
+ && decl.type === 'ExpressionStatement'
391
+ && decl.expression?.type === 'AssignmentExpression'
392
+ && decl.expression.left?.type === 'MemberExpression'
393
+ && !decl.expression.left.computed
394
+ && (decl.expression.right?.type === 'FunctionExpression'
395
+ || decl.expression.right?.type === 'ArrowFunctionExpression')) {
396
+ const proto = (0, commentParser_1.extractPrototypeMethod)(decl.expression.left);
397
+ if (proto) {
398
+ const qualifiedName = `${proto.typeName}#${proto.methodName}`;
399
+ if (!hasAnn(qualifiedName)
400
+ && !hasAnnAtOffset(decl.expression.right.start)
401
+ && !hasParentMethodAnnotation(annotations, proto.typeName, proto.methodName)) {
402
+ const propNode = decl.expression.left.property;
403
+ pushMissingSigDiag(diagnostics, textDocument, fnSeverity, propNode.start, propNode.end, 'Method', qualifiedName);
404
+ }
405
+ }
406
+ }
407
+ // Case 5: static method assignment — X.method = function() { ... }
408
+ // (non-prototype: obj.prop = fn where obj is a simple Identifier)
409
+ if (fnSeverity != null
410
+ && decl.type === 'ExpressionStatement'
411
+ && decl.expression?.type === 'AssignmentExpression'
412
+ && decl.expression.left?.type === 'MemberExpression'
413
+ && !decl.expression.left.computed
414
+ && decl.expression.left.object?.type === 'Identifier'
415
+ && decl.expression.left.property?.type === 'Identifier'
416
+ && (decl.expression.right?.type === 'FunctionExpression'
417
+ || decl.expression.right?.type === 'ArrowFunctionExpression')) {
418
+ // Skip prototype assignments (handled by Case 4 above)
419
+ const proto = (0, commentParser_1.extractPrototypeMethod)(decl.expression.left);
420
+ if (!proto) {
421
+ const objName = decl.expression.left.object.name;
422
+ const propName = decl.expression.left.property.name;
423
+ // Skip module.exports and exports.X
424
+ if (objName !== 'module' && objName !== 'exports') {
425
+ const qualifiedName = `${objName}.${propName}`;
426
+ if (!hasAnn(qualifiedName)
427
+ && !hasAnnAtOffset(decl.expression.right.start)) {
428
+ const propNode = decl.expression.left.property;
429
+ pushMissingSigDiag(diagnostics, textDocument, fnSeverity, propNode.start, propNode.end, 'Method', qualifiedName);
430
+ }
431
+ }
432
+ }
433
+ }
434
+ }
435
+ // Case 6: nested bindings inside function bodies
436
+ detectNestedMissingSignatures(ast, annotations, erroredNames, erroredOffsets, textDocument, fnSeverity, varSeverity ?? null, diagnostics);
437
+ }
438
+ catch {
439
+ // AST parse failed — skip missing-signature check
440
+ }
441
+ return diagnostics;
442
+ }
443
+ // ---------------------------------------------------------------------------
444
+ // Nested missing-signature detection
445
+ // ---------------------------------------------------------------------------
446
+ /**
447
+ * Walk all function bodies looking for `const x = fn => ...` or
448
+ * `const x = function(...) { ... }` bindings that lack an HM annotation.
449
+ */
450
+ function detectNestedMissingSignatures(ast, annotations, erroredNames, erroredOffsets, textDocument, fnSeverity, varSeverity, diagnostics) {
451
+ // Collect all top-level declaration names so we can skip them (already handled).
452
+ const topLevelStarts = new Set();
453
+ for (const stmt of ast.body) {
454
+ topLevelStarts.add(stmt.start);
455
+ const decl = (stmt.type === 'ExportNamedDeclaration' || stmt.type === 'ExportDefaultDeclaration')
456
+ && stmt.declaration ? stmt.declaration : stmt;
457
+ if (decl !== stmt)
458
+ topLevelStarts.add(decl.start);
459
+ }
460
+ // Helper: check if a nested function name is covered by any annotation
461
+ function isNestedFunctionAnnotated(name, nodeStart) {
462
+ // Check: does any annotation point to this node's offset?
463
+ if (hasAnnotationAtOffset(annotations, nodeStart))
464
+ return true;
465
+ if (erroredOffsets.has(nodeStart))
466
+ return true;
467
+ // Also accept if the name is directly annotated
468
+ if (annotations.has(name))
469
+ return true;
470
+ if (erroredNames.has(name))
471
+ return true;
472
+ // Also accept method-style annotations (e.g. Either2#map for a nested `const map = ...`)
473
+ return [...annotations.keys()].some(key => key.endsWith('#' + name));
474
+ }
475
+ walk.simple(ast, {
476
+ VariableDeclaration(node) {
477
+ // Only care about nested declarations (inside function bodies)
478
+ if (topLevelStarts.has(node.start))
479
+ return;
480
+ for (const declarator of node.declarations) {
481
+ const id = declarator.id;
482
+ if (!id?.name || !declarator.init)
483
+ continue;
484
+ const name = id.name;
485
+ if (isNestedFunctionAnnotated(name, declarator.init.start))
486
+ continue;
487
+ if ((0, dataTypeRegistry_1.isDataType)(name))
488
+ continue;
489
+ const isFn = declarator.init.type === 'ArrowFunctionExpression' ||
490
+ declarator.init.type === 'FunctionExpression';
491
+ const sev = isFn ? fnSeverity : varSeverity;
492
+ if (sev == null)
493
+ continue;
494
+ const label = isFn ? 'Function' : 'Variable';
495
+ pushMissingSigDiag(diagnostics, textDocument, sev, id.start, id.end, label, name);
496
+ }
497
+ },
498
+ FunctionDeclaration(node) {
499
+ // Only care about nested declarations (inside function bodies)
500
+ if (topLevelStarts.has(node.start))
501
+ return;
502
+ if (!node.id?.name)
503
+ return;
504
+ if (fnSeverity == null)
505
+ return;
506
+ const name = node.id.name;
507
+ if (isNestedFunctionAnnotated(name, node.start))
508
+ return;
509
+ if ((0, dataTypeRegistry_1.isDataType)(name))
510
+ return;
511
+ pushMissingSigDiag(diagnostics, textDocument, fnSeverity, node.id.start, node.id.end, 'Function', name);
512
+ },
513
+ });
514
+ }
515
+ // ---------------------------------------------------------------------------
516
+ // Ignored-line filtering
517
+ // ---------------------------------------------------------------------------
518
+ /**
519
+ * Remove diagnostics whose start line appears in the set of ignored lines
520
+ * (from `::ignore` / `::ignore-function` directives).
521
+ */
522
+ function filterIgnoredDiagnostics(diagnostics, ignoredLines) {
523
+ return diagnostics.filter((d) => !ignoredLines.has(d.range.start.line));
524
+ }
525
+ // ---------------------------------------------------------------------------
526
+ // Annotation mismatch filtering (trustAnnotations)
527
+ // ---------------------------------------------------------------------------
528
+ /** Patterns that indicate a diagnostic was caused by an annotation vs inferred type mismatch. */
529
+ const ANNOTATION_MISMATCH_PATTERNS = [
530
+ 'Type mismatch: implementation does not match annotation',
531
+ 'Type mismatch: function returns',
532
+ ];
533
+ /** Regex matching the unified annotation-mismatch message format. */
534
+ const UNIFIED_MISMATCH_RE = /^Type mismatch: ('[^']+'|value) has (return )?type /;
535
+ /**
536
+ * Filter out diagnostics that are caused by a mismatch between the
537
+ * user-written annotation and the inferred type. Used when the
538
+ * `trustAnnotations` setting is enabled.
539
+ */
540
+ function filterAnnotationMismatchDiagnostics(diagnostics) {
541
+ return diagnostics.filter((d) => !ANNOTATION_MISMATCH_PATTERNS.some((p) => d.message.startsWith(p)) &&
542
+ !UNIFIED_MISMATCH_RE.test(d.message));
543
+ }
544
+ // ---------------------------------------------------------------------------
545
+ // Binding-body filtering (trustAnnotations: 'annotated-bodies' / 'all-bodies')
546
+ // ---------------------------------------------------------------------------
547
+ /**
548
+ * Drop any diagnostic whose `[start, end]` source range lies entirely
549
+ * inside one of the supplied intervals.
550
+ *
551
+ * Pure / knowledge-free: callers decide which intervals to pass. The
552
+ * comparison is inclusive at both ends so a diagnostic that exactly
553
+ * coincides with a binding's extent is treated as inside that binding.
554
+ */
555
+ function filterDiagnosticsInsideBindings(diagnostics, intervals) {
556
+ if (intervals.length === 0)
557
+ return diagnostics;
558
+ return diagnostics.filter((d) => {
559
+ for (const [s, e] of intervals) {
560
+ if (d.start >= s && d.end <= e)
561
+ return false;
562
+ }
563
+ return true;
564
+ });
565
+ }
566
+ /**
567
+ * Collect `[start, end]` source ranges of bindings from an
568
+ * {@link InferenceResult} for use with
569
+ * {@link filterDiagnosticsInsideBindings}.
570
+ *
571
+ * Reads `result.bindingExtents` (populated by the inference engine):
572
+ * - `'annotated'`: only extents flagged `annotated: true`.
573
+ * - `'all'`: every extent regardless of annotation.
574
+ *
575
+ * Returns an empty array when the engine did not publish extents
576
+ * (older results / non-default code paths) — conservative: never
577
+ * suppress diagnostics in code we cannot bound.
578
+ */
579
+ function collectBindingIntervals(result, mode) {
580
+ const extents = result.bindingExtents;
581
+ if (!extents)
582
+ return [];
583
+ const out = [];
584
+ for (const ext of extents) {
585
+ if (mode === 'annotated' && !ext.annotated)
586
+ continue;
587
+ out.push([ext.start, ext.end]);
588
+ }
589
+ return out;
590
+ }
591
+ // ---------------------------------------------------------------------------
592
+ // Import diagnostics — duplicate & circular import scans
593
+ // ---------------------------------------------------------------------------
594
+ /**
595
+ * Scan the source for `import` statements that bind a name which was
596
+ * already imported earlier in the file, and produce one warning per
597
+ * duplicate binding.
598
+ */
599
+ function detectDuplicateImports(source, textDocument) {
600
+ const diagnostics = [];
601
+ const seenImports = new Map();
602
+ const dupRe = /^import\s+(?:(\w+)|\{([^}]+)\}|\*\s+as\s+(\w+))\s+from\s+['"][^'"]+['"];?\s*$/gm;
603
+ let dm;
604
+ while ((dm = dupRe.exec(source)) !== null) {
605
+ const names = [];
606
+ if (dm[1])
607
+ names.push(dm[1]);
608
+ if (dm[3])
609
+ names.push(dm[3]);
610
+ if (dm[2]) {
611
+ for (const part of dm[2].split(',')) {
612
+ const t = part.trim();
613
+ const as = t.match(/\w+\s+as\s+(\w+)/);
614
+ names.push(as ? as[1] : t);
615
+ }
616
+ }
617
+ for (const name of names) {
618
+ if (seenImports.has(name)) {
619
+ const start = textDocument.positionAt(dm.index);
620
+ const end = textDocument.positionAt(dm.index + dm[0].length);
621
+ diagnostics.push({
622
+ severity: node_1.DiagnosticSeverity.Warning,
623
+ range: { start, end },
624
+ message: `Duplicate import: '${name}' is already imported`,
625
+ source: 'hinmil',
626
+ code: diagnosticCodes_1.HM_DUPLICATE_IMPORT,
627
+ });
628
+ }
629
+ else {
630
+ seenImports.set(name, dm.index);
631
+ }
632
+ }
633
+ }
634
+ return diagnostics;
635
+ }
636
+ /**
637
+ * Produce a warning for every `import ... from '<spec>'` whose resolved
638
+ * target participates in a circular dependency chain with this file.
639
+ * `circularDeps` is the set of URIs on a cycle through `textDocument.uri`
640
+ * (as reported by the import context).
641
+ */
642
+ function detectCircularImports(source, textDocument, circularDeps) {
643
+ const diagnostics = [];
644
+ if (circularDeps.size === 0)
645
+ return diagnostics;
646
+ const importRe = /^import\s+(?:\w+|\{[^}]+\}|\*\s+as\s+\w+)\s+from\s+['"]([^'"]+)['"];?\s*$/gm;
647
+ let im;
648
+ while ((im = importRe.exec(source)) !== null) {
649
+ const specifier = im[1];
650
+ const targetUri = (0, files_1.resolveImportSpecifier)(specifier, textDocument.uri);
651
+ if (targetUri && circularDeps.has(targetUri)) {
652
+ const start = textDocument.positionAt(im.index);
653
+ const end = textDocument.positionAt(im.index + im[0].length);
654
+ diagnostics.push({
655
+ severity: node_1.DiagnosticSeverity.Warning,
656
+ range: { start, end },
657
+ message: `Circular import: '${specifier}' is part of a circular dependency chain`,
658
+ source: 'hinmil',
659
+ code: diagnosticCodes_1.HM_CIRCULAR_IMPORT,
660
+ });
661
+ }
662
+ }
663
+ return diagnostics;
664
+ }
665
+ //# sourceMappingURL=diagnostics.js.map