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.
- package/LICENSE +21 -0
- package/README.md +2306 -2
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +338 -0
- package/dist/cli.js.map +1 -0
- package/dist/commentParser.d.ts +384 -0
- package/dist/commentParser.d.ts.map +1 -0
- package/dist/commentParser.js +2487 -0
- package/dist/commentParser.js.map +1 -0
- package/dist/config.d.ts +203 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +375 -0
- package/dist/config.js.map +1 -0
- package/dist/debugLog.d.ts +13 -0
- package/dist/debugLog.d.ts.map +1 -0
- package/dist/debugLog.js +44 -0
- package/dist/debugLog.js.map +1 -0
- package/dist/estree.d.ts +100 -0
- package/dist/estree.d.ts.map +1 -0
- package/dist/estree.js +34 -0
- package/dist/estree.js.map +1 -0
- package/dist/hm/env.d.ts +134 -0
- package/dist/hm/env.d.ts.map +1 -0
- package/dist/hm/env.js +939 -0
- package/dist/hm/env.js.map +1 -0
- package/dist/hm/index.d.ts +7 -0
- package/dist/hm/index.d.ts.map +1 -0
- package/dist/hm/index.js +26 -0
- package/dist/hm/index.js.map +1 -0
- package/dist/hm/substitution.d.ts +57 -0
- package/dist/hm/substitution.d.ts.map +1 -0
- package/dist/hm/substitution.js +546 -0
- package/dist/hm/substitution.js.map +1 -0
- package/dist/hm/typeParser.d.ts +39 -0
- package/dist/hm/typeParser.d.ts.map +1 -0
- package/dist/hm/typeParser.js +1285 -0
- package/dist/hm/typeParser.js.map +1 -0
- package/dist/hm/typeUtils.d.ts +248 -0
- package/dist/hm/typeUtils.d.ts.map +1 -0
- package/dist/hm/typeUtils.js +905 -0
- package/dist/hm/typeUtils.js.map +1 -0
- package/dist/hm/types.d.ts +738 -0
- package/dist/hm/types.d.ts.map +1 -0
- package/dist/hm/types.js +1853 -0
- package/dist/hm/types.js.map +1 -0
- package/dist/hm/unify.d.ts +59 -0
- package/dist/hm/unify.d.ts.map +1 -0
- package/dist/hm/unify.js +1700 -0
- package/dist/hm/unify.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -0
- package/dist/infer/annotation-rigid.d.ts +76 -0
- package/dist/infer/annotation-rigid.d.ts.map +1 -0
- package/dist/infer/annotation-rigid.js +542 -0
- package/dist/infer/annotation-rigid.js.map +1 -0
- package/dist/infer/annotation-validation.d.ts +109 -0
- package/dist/infer/annotation-validation.d.ts.map +1 -0
- package/dist/infer/annotation-validation.js +1078 -0
- package/dist/infer/annotation-validation.js.map +1 -0
- package/dist/infer/annotations.d.ts +277 -0
- package/dist/infer/annotations.d.ts.map +1 -0
- package/dist/infer/annotations.js +1343 -0
- package/dist/infer/annotations.js.map +1 -0
- package/dist/infer/call-overloads.d.ts +24 -0
- package/dist/infer/call-overloads.d.ts.map +1 -0
- package/dist/infer/call-overloads.js +900 -0
- package/dist/infer/call-overloads.js.map +1 -0
- package/dist/infer/call-rows.d.ts +154 -0
- package/dist/infer/call-rows.d.ts.map +1 -0
- package/dist/infer/call-rows.js +2162 -0
- package/dist/infer/call-rows.js.map +1 -0
- package/dist/infer/calls.d.ts +20 -0
- package/dist/infer/calls.d.ts.map +1 -0
- package/dist/infer/calls.js +1468 -0
- package/dist/infer/calls.js.map +1 -0
- package/dist/infer/constraints.d.ts +99 -0
- package/dist/infer/constraints.d.ts.map +1 -0
- package/dist/infer/constraints.js +1208 -0
- package/dist/infer/constraints.js.map +1 -0
- package/dist/infer/expr-assignment.d.ts +20 -0
- package/dist/infer/expr-assignment.d.ts.map +1 -0
- package/dist/infer/expr-assignment.js +620 -0
- package/dist/infer/expr-assignment.js.map +1 -0
- package/dist/infer/expr-constraint-lookup.d.ts +44 -0
- package/dist/infer/expr-constraint-lookup.d.ts.map +1 -0
- package/dist/infer/expr-constraint-lookup.js +207 -0
- package/dist/infer/expr-constraint-lookup.js.map +1 -0
- package/dist/infer/expr-functions.d.ts +20 -0
- package/dist/infer/expr-functions.d.ts.map +1 -0
- package/dist/infer/expr-functions.js +1359 -0
- package/dist/infer/expr-functions.js.map +1 -0
- package/dist/infer/expr-jsx.d.ts +19 -0
- package/dist/infer/expr-jsx.d.ts.map +1 -0
- package/dist/infer/expr-jsx.js +310 -0
- package/dist/infer/expr-jsx.js.map +1 -0
- package/dist/infer/expr-member.d.ts +40 -0
- package/dist/infer/expr-member.d.ts.map +1 -0
- package/dist/infer/expr-member.js +1154 -0
- package/dist/infer/expr-member.js.map +1 -0
- package/dist/infer/expr-prototype.d.ts +11 -0
- package/dist/infer/expr-prototype.d.ts.map +1 -0
- package/dist/infer/expr-prototype.js +202 -0
- package/dist/infer/expr-prototype.js.map +1 -0
- package/dist/infer/expressions.d.ts +40 -0
- package/dist/infer/expressions.d.ts.map +1 -0
- package/dist/infer/expressions.js +1497 -0
- package/dist/infer/expressions.js.map +1 -0
- package/dist/infer/functionPatterns.d.ts +229 -0
- package/dist/infer/functionPatterns.d.ts.map +1 -0
- package/dist/infer/functionPatterns.js +1035 -0
- package/dist/infer/functionPatterns.js.map +1 -0
- package/dist/infer/helpers.d.ts +73 -0
- package/dist/infer/helpers.d.ts.map +1 -0
- package/dist/infer/helpers.js +187 -0
- package/dist/infer/helpers.js.map +1 -0
- package/dist/infer/index.d.ts +551 -0
- package/dist/infer/index.d.ts.map +1 -0
- package/dist/infer/index.js +1127 -0
- package/dist/infer/index.js.map +1 -0
- package/dist/infer/jsx-dom.d.ts +26 -0
- package/dist/infer/jsx-dom.d.ts.map +1 -0
- package/dist/infer/jsx-dom.js +303 -0
- package/dist/infer/jsx-dom.js.map +1 -0
- package/dist/infer/moduleReps.d.ts +7 -0
- package/dist/infer/moduleReps.d.ts.map +1 -0
- package/dist/infer/moduleReps.js +48 -0
- package/dist/infer/moduleReps.js.map +1 -0
- package/dist/infer/modules.d.ts +10 -0
- package/dist/infer/modules.d.ts.map +1 -0
- package/dist/infer/modules.js +775 -0
- package/dist/infer/modules.js.map +1 -0
- package/dist/infer/narrowing.d.ts +199 -0
- package/dist/infer/narrowing.d.ts.map +1 -0
- package/dist/infer/narrowing.js +1428 -0
- package/dist/infer/narrowing.js.map +1 -0
- package/dist/infer/results.d.ts +24 -0
- package/dist/infer/results.d.ts.map +1 -0
- package/dist/infer/results.js +611 -0
- package/dist/infer/results.js.map +1 -0
- package/dist/infer/setupPass.d.ts +11 -0
- package/dist/infer/setupPass.d.ts.map +1 -0
- package/dist/infer/setupPass.js +524 -0
- package/dist/infer/setupPass.js.map +1 -0
- package/dist/infer/statements.d.ts +26 -0
- package/dist/infer/statements.d.ts.map +1 -0
- package/dist/infer/statements.js +750 -0
- package/dist/infer/statements.js.map +1 -0
- package/dist/infer/stmt-bindings.d.ts +22 -0
- package/dist/infer/stmt-bindings.d.ts.map +1 -0
- package/dist/infer/stmt-bindings.js +1482 -0
- package/dist/infer/stmt-bindings.js.map +1 -0
- package/dist/infer/stmt-destructure.d.ts +29 -0
- package/dist/infer/stmt-destructure.d.ts.map +1 -0
- package/dist/infer/stmt-destructure.js +490 -0
- package/dist/infer/stmt-destructure.js.map +1 -0
- package/dist/infer/types.d.ts +220 -0
- package/dist/infer/types.d.ts.map +1 -0
- package/dist/infer/types.js +46 -0
- package/dist/infer/types.js.map +1 -0
- package/dist/infer/unifyDiag.d.ts +46 -0
- package/dist/infer/unifyDiag.d.ts.map +1 -0
- package/dist/infer/unifyDiag.js +642 -0
- package/dist/infer/unifyDiag.js.map +1 -0
- package/dist/parsing-babel.d.ts +3 -0
- package/dist/parsing-babel.d.ts.map +1 -0
- package/dist/parsing-babel.js +353 -0
- package/dist/parsing-babel.js.map +1 -0
- package/dist/parsing.d.ts +69 -0
- package/dist/parsing.d.ts.map +1 -0
- package/dist/parsing.js +288 -0
- package/dist/parsing.js.map +1 -0
- package/dist/registries/constraintRegistry.d.ts +233 -0
- package/dist/registries/constraintRegistry.d.ts.map +1 -0
- package/dist/registries/constraintRegistry.js +803 -0
- package/dist/registries/constraintRegistry.js.map +1 -0
- package/dist/registries/dataTypeRegistry.d.ts +63 -0
- package/dist/registries/dataTypeRegistry.d.ts.map +1 -0
- package/dist/registries/dataTypeRegistry.js +180 -0
- package/dist/registries/dataTypeRegistry.js.map +1 -0
- package/dist/registries/domGlobals.d.ts +33 -0
- package/dist/registries/domGlobals.d.ts.map +1 -0
- package/dist/registries/domGlobals.js +309 -0
- package/dist/registries/domGlobals.js.map +1 -0
- package/dist/registries/methodRegistry.d.ts +277 -0
- package/dist/registries/methodRegistry.d.ts.map +1 -0
- package/dist/registries/methodRegistry.js +2074 -0
- package/dist/registries/methodRegistry.js.map +1 -0
- package/dist/registries/session.d.ts +38 -0
- package/dist/registries/session.d.ts.map +1 -0
- package/dist/registries/session.js +75 -0
- package/dist/registries/session.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1896 -0
- package/dist/server.js.map +1 -0
- package/dist/services/codeActions.d.ts +22 -0
- package/dist/services/codeActions.d.ts.map +1 -0
- package/dist/services/codeActions.js +465 -0
- package/dist/services/codeActions.js.map +1 -0
- package/dist/services/completion.d.ts +259 -0
- package/dist/services/completion.d.ts.map +1 -0
- package/dist/services/completion.js +2794 -0
- package/dist/services/completion.js.map +1 -0
- package/dist/services/definitions.d.ts +37 -0
- package/dist/services/definitions.d.ts.map +1 -0
- package/dist/services/definitions.js +605 -0
- package/dist/services/definitions.js.map +1 -0
- package/dist/services/diagnosticCodes.d.ts +70 -0
- package/dist/services/diagnosticCodes.d.ts.map +1 -0
- package/dist/services/diagnosticCodes.js +239 -0
- package/dist/services/diagnosticCodes.js.map +1 -0
- package/dist/services/diagnostics.d.ts +86 -0
- package/dist/services/diagnostics.d.ts.map +1 -0
- package/dist/services/diagnostics.js +665 -0
- package/dist/services/diagnostics.js.map +1 -0
- package/dist/services/documentCache.d.ts +88 -0
- package/dist/services/documentCache.d.ts.map +1 -0
- package/dist/services/documentCache.js +108 -0
- package/dist/services/documentCache.js.map +1 -0
- package/dist/services/documentSymbols.d.ts +20 -0
- package/dist/services/documentSymbols.d.ts.map +1 -0
- package/dist/services/documentSymbols.js +381 -0
- package/dist/services/documentSymbols.js.map +1 -0
- package/dist/services/fileSelection.d.ts +24 -0
- package/dist/services/fileSelection.d.ts.map +1 -0
- package/dist/services/fileSelection.js +154 -0
- package/dist/services/fileSelection.js.map +1 -0
- package/dist/services/fileSelectionRefresh.d.ts +26 -0
- package/dist/services/fileSelectionRefresh.d.ts.map +1 -0
- package/dist/services/fileSelectionRefresh.js +77 -0
- package/dist/services/fileSelectionRefresh.js.map +1 -0
- package/dist/services/files.d.ts +342 -0
- package/dist/services/files.d.ts.map +1 -0
- package/dist/services/files.js +1712 -0
- package/dist/services/files.js.map +1 -0
- package/dist/services/fsProbe.d.ts +14 -0
- package/dist/services/fsProbe.d.ts.map +1 -0
- package/dist/services/fsProbe.js +112 -0
- package/dist/services/fsProbe.js.map +1 -0
- package/dist/services/globalsLoader.d.ts +20 -0
- package/dist/services/globalsLoader.d.ts.map +1 -0
- package/dist/services/globalsLoader.js +122 -0
- package/dist/services/globalsLoader.js.map +1 -0
- package/dist/services/hmFileServices.d.ts +113 -0
- package/dist/services/hmFileServices.d.ts.map +1 -0
- package/dist/services/hmFileServices.js +686 -0
- package/dist/services/hmFileServices.js.map +1 -0
- package/dist/services/hover.d.ts +280 -0
- package/dist/services/hover.d.ts.map +1 -0
- package/dist/services/hover.js +1687 -0
- package/dist/services/hover.js.map +1 -0
- package/dist/services/importContext.d.ts +396 -0
- package/dist/services/importContext.d.ts.map +1 -0
- package/dist/services/importContext.js +1999 -0
- package/dist/services/importContext.js.map +1 -0
- package/dist/services/projectChecker.d.ts +50 -0
- package/dist/services/projectChecker.d.ts.map +1 -0
- package/dist/services/projectChecker.js +228 -0
- package/dist/services/projectChecker.js.map +1 -0
- package/dist/services/references.d.ts +41 -0
- package/dist/services/references.d.ts.map +1 -0
- package/dist/services/references.js +757 -0
- package/dist/services/references.js.map +1 -0
- package/dist/services/rename.d.ts +22 -0
- package/dist/services/rename.d.ts.map +1 -0
- package/dist/services/rename.js +101 -0
- package/dist/services/rename.js.map +1 -0
- package/dist/services/shortCircuit.d.ts +27 -0
- package/dist/services/shortCircuit.d.ts.map +1 -0
- package/dist/services/shortCircuit.js +28 -0
- package/dist/services/shortCircuit.js.map +1 -0
- package/dist/services/sidecarPerf.d.ts +19 -0
- package/dist/services/sidecarPerf.d.ts.map +1 -0
- package/dist/services/sidecarPerf.js +59 -0
- package/dist/services/sidecarPerf.js.map +1 -0
- package/dist/services/signatureHelp.d.ts +27 -0
- package/dist/services/signatureHelp.d.ts.map +1 -0
- package/dist/services/signatureHelp.js +984 -0
- package/dist/services/signatureHelp.js.map +1 -0
- package/dist/walking.d.ts +25 -0
- package/dist/walking.d.ts.map +1 -0
- package/dist/walking.js +107 -0
- package/dist/walking.js.map +1 -0
- package/hm-types-builtin/assert.hm +20 -0
- package/hm-types-builtin/buffer.hm +8 -0
- package/hm-types-builtin/child_process.hm +16 -0
- package/hm-types-builtin/crypto.hm +17 -0
- package/hm-types-builtin/fs.hm +15 -0
- package/hm-types-builtin/http.hm +14 -0
- package/hm-types-builtin/os.hm +19 -0
- package/hm-types-builtin/path.hm +18 -0
- package/hm-types-builtin/react-dom.hm +27 -0
- package/hm-types-builtin/react.hm +113 -0
- package/hm-types-builtin/url.hm +7 -0
- package/hm-types-builtin/zlib.hm +12 -0
- package/package.json +53 -4
- package/schemas/hinmil.config.schema.json +261 -0
- package/schemas/package-hinmil.schema.json +59 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// hmFileServices — language services on standalone `.hm` declaration files
|
|
4
|
+
//
|
|
5
|
+
// `.hm` files are bare-syntax type-declaration sources consumed by other JS
|
|
6
|
+
// files via the sidecar / globals mechanism in `services/files.ts`. Until
|
|
7
|
+
// now the language server provided no features *on* `.hm` files themselves
|
|
8
|
+
// (`validateTextDocument` early-returned, hover/definition were calling
|
|
9
|
+
// `engine.infer` on the raw source).
|
|
10
|
+
//
|
|
11
|
+
// This module is the small "declarations-only" pipeline used by the server
|
|
12
|
+
// when the active document is a `.hm` file. It:
|
|
13
|
+
//
|
|
14
|
+
// 1. Wraps the source via the existing `wrapHmSource` so the JS comment
|
|
15
|
+
// parser can extract annotations.
|
|
16
|
+
// 2. Builds a bidirectional offset map between the original `.hm` text
|
|
17
|
+
// and the wrapped buffer (each non-comment line gains a 3-char `// `
|
|
18
|
+
// prefix in the wrapped buffer; line numbers are preserved).
|
|
19
|
+
// 3. Surfaces parse errors as diagnostics, an `Name :: ...` hover, an
|
|
20
|
+
// uppercase-type go-to-definition, and a flat document-symbol list.
|
|
21
|
+
//
|
|
22
|
+
// All cross-file resolution (globals, query-builder index, package `hinmil.sidecars`,
|
|
23
|
+
// project overrides, per-file sidecars, constraint directives) is reused
|
|
24
|
+
// from `services/importContext.ts` and `services/files.ts`; this module
|
|
25
|
+
// only owns offset translation and `.hm`-aware delegation.
|
|
26
|
+
// ============================================================================
|
|
27
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
30
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
31
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(o, k2, desc);
|
|
34
|
+
}) : (function(o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
o[k2] = m[k];
|
|
37
|
+
}));
|
|
38
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
39
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
40
|
+
}) : function(o, v) {
|
|
41
|
+
o["default"] = v;
|
|
42
|
+
});
|
|
43
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
44
|
+
var ownKeys = function(o) {
|
|
45
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
46
|
+
var ar = [];
|
|
47
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
48
|
+
return ar;
|
|
49
|
+
};
|
|
50
|
+
return ownKeys(o);
|
|
51
|
+
};
|
|
52
|
+
return function (mod) {
|
|
53
|
+
if (mod && mod.__esModule) return mod;
|
|
54
|
+
var result = {};
|
|
55
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
56
|
+
__setModuleDefault(result, mod);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
})();
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.buildHmOffsetMap = buildHmOffsetMap;
|
|
62
|
+
exports.parseHm = parseHm;
|
|
63
|
+
exports.clearHmParseCache = clearHmParseCache;
|
|
64
|
+
exports.clearHmParseCacheForFile = clearHmParseCacheForFile;
|
|
65
|
+
exports.getHmDiagnostics = getHmDiagnostics;
|
|
66
|
+
exports.getHmHover = getHmHover;
|
|
67
|
+
exports.getHmDefinition = getHmDefinition;
|
|
68
|
+
exports.getHmDocumentSymbols = getHmDocumentSymbols;
|
|
69
|
+
const fs = __importStar(require("fs"));
|
|
70
|
+
const url_1 = require("url");
|
|
71
|
+
const node_1 = require("vscode-languageserver/node");
|
|
72
|
+
const commentParser_1 = require("../commentParser");
|
|
73
|
+
const files_1 = require("./files");
|
|
74
|
+
const annotations_1 = require("../infer/annotations");
|
|
75
|
+
const domGlobals_1 = require("../registries/domGlobals");
|
|
76
|
+
const types_1 = require("../hm/types");
|
|
77
|
+
const typeUtils_1 = require("../hm/typeUtils");
|
|
78
|
+
const dataTypeRegistry_1 = require("../registries/dataTypeRegistry");
|
|
79
|
+
const methodRegistry_1 = require("../registries/methodRegistry");
|
|
80
|
+
const constraintRegistry_1 = require("../registries/constraintRegistry");
|
|
81
|
+
function buildHmOffsetMap(source) {
|
|
82
|
+
const wrapped = (0, files_1.wrapHmSource)(source);
|
|
83
|
+
// Per-line starts in each buffer.
|
|
84
|
+
const lines = source.split('\n');
|
|
85
|
+
const wrappedLines = wrapped.split('\n');
|
|
86
|
+
const origLineStart = new Array(lines.length);
|
|
87
|
+
const wrapLineStart = new Array(wrappedLines.length);
|
|
88
|
+
/** True when the wrapped line gained a `// ` prefix relative to the original. */
|
|
89
|
+
const wrappedFlag = new Array(lines.length);
|
|
90
|
+
let oAcc = 0;
|
|
91
|
+
let wAcc = 0;
|
|
92
|
+
for (let i = 0; i < lines.length; i++) {
|
|
93
|
+
origLineStart[i] = oAcc;
|
|
94
|
+
wrapLineStart[i] = wAcc;
|
|
95
|
+
const origLen = lines[i].length;
|
|
96
|
+
const wrapLen = wrappedLines[i] !== undefined ? wrappedLines[i].length : origLen;
|
|
97
|
+
wrappedFlag[i] = wrapLen === origLen + 3;
|
|
98
|
+
oAcc += origLen + 1; // include trailing '\n'
|
|
99
|
+
wAcc += wrapLen + 1;
|
|
100
|
+
}
|
|
101
|
+
/** Find the line index containing `offset` using `lineStart[]`. */
|
|
102
|
+
const findLine = (lineStart, offset) => {
|
|
103
|
+
if (offset <= 0)
|
|
104
|
+
return 0;
|
|
105
|
+
// Binary search: greatest index whose start <= offset.
|
|
106
|
+
let lo = 0;
|
|
107
|
+
let hi = lineStart.length - 1;
|
|
108
|
+
while (lo < hi) {
|
|
109
|
+
const mid = (lo + hi + 1) >>> 1;
|
|
110
|
+
if (lineStart[mid] <= offset)
|
|
111
|
+
lo = mid;
|
|
112
|
+
else
|
|
113
|
+
hi = mid - 1;
|
|
114
|
+
}
|
|
115
|
+
return lo;
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
wrapped,
|
|
119
|
+
toOriginal(wOff) {
|
|
120
|
+
if (wOff <= 0)
|
|
121
|
+
return 0;
|
|
122
|
+
if (wOff >= wrapped.length)
|
|
123
|
+
return source.length;
|
|
124
|
+
const li = findLine(wrapLineStart, wOff);
|
|
125
|
+
const col = wOff - wrapLineStart[li];
|
|
126
|
+
const origCol = wrappedFlag[li] ? Math.max(0, col - 3) : col;
|
|
127
|
+
const lineLen = lines[li].length;
|
|
128
|
+
return origLineStart[li] + Math.min(origCol, lineLen);
|
|
129
|
+
},
|
|
130
|
+
toWrapped(oOff) {
|
|
131
|
+
if (oOff <= 0)
|
|
132
|
+
return 0;
|
|
133
|
+
if (oOff >= source.length)
|
|
134
|
+
return wrapped.length;
|
|
135
|
+
const li = findLine(origLineStart, oOff);
|
|
136
|
+
const col = oOff - origLineStart[li];
|
|
137
|
+
const wrappedCol = wrappedFlag[li] ? col + 3 : col;
|
|
138
|
+
return wrapLineStart[li] + wrappedCol;
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const parseCache = new Map();
|
|
143
|
+
const PARSE_CACHE_MAX = 16;
|
|
144
|
+
function parseHm(uri, source) {
|
|
145
|
+
const cached = parseCache.get(uri);
|
|
146
|
+
if (cached && cached.source === source)
|
|
147
|
+
return cached.parsed;
|
|
148
|
+
const map = buildHmOffsetMap(source);
|
|
149
|
+
const annotations = (0, commentParser_1.extractAnnotations)(map.wrapped);
|
|
150
|
+
const parsed = { source, map, annotations };
|
|
151
|
+
parseCache.set(uri, { source, parsed });
|
|
152
|
+
if (parseCache.size > PARSE_CACHE_MAX) {
|
|
153
|
+
// Drop the oldest insertion order entry.
|
|
154
|
+
const firstKey = parseCache.keys().next().value;
|
|
155
|
+
if (firstKey && firstKey !== uri)
|
|
156
|
+
parseCache.delete(firstKey);
|
|
157
|
+
}
|
|
158
|
+
return parsed;
|
|
159
|
+
}
|
|
160
|
+
function clearHmParseCache() {
|
|
161
|
+
parseCache.clear();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Evict a single parsed `.hm` entry by its key (typically a `file://` URI
|
|
165
|
+
* or absolute path — must match the key used at the corresponding
|
|
166
|
+
* {@link parseHm} call site). Used by the `.hm` watcher / change-content
|
|
167
|
+
* handler so per-file invalidation does not nuke unrelated sidecars from
|
|
168
|
+
* the small 16-slot LRU.
|
|
169
|
+
*/
|
|
170
|
+
function clearHmParseCacheForFile(uri) {
|
|
171
|
+
parseCache.delete(uri);
|
|
172
|
+
}
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// Diagnostics
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
/**
|
|
177
|
+
* Build diagnostics for a `.hm` file. Three classes of errors are
|
|
178
|
+
* surfaced:
|
|
179
|
+
*
|
|
180
|
+
* 1. **Parse errors** — the existing `TypeAnnotation.error` field
|
|
181
|
+
* already carries the relevant message from
|
|
182
|
+
* `parseTypeSignature` / `parseMethodTypeSignature`.
|
|
183
|
+
*
|
|
184
|
+
* 2. **Arity mismatches** — `QueryTag a` in a file that declares
|
|
185
|
+
* `QueryTag :: (a, b) -> QueryTag a b` (or whose registered arity is 2).
|
|
186
|
+
* Reuses the same `findArityMismatches` walker the JS pipeline uses.
|
|
187
|
+
*
|
|
188
|
+
* 3. **Unknown type-constructor references** — e.g. `Property` typo
|
|
189
|
+
* for `Prop`. An identifier is considered unknown only after
|
|
190
|
+
* checking: builtins, locally declared annotations / sumtypes /
|
|
191
|
+
* aliases, the global registries, AND the cross-file sidecar +
|
|
192
|
+
* globals chain via `ctx.findTypeDefinitions`. This avoids false
|
|
193
|
+
* positives on legitimate forward references in stubs like
|
|
194
|
+
* `node_modules/query-builder/query-builder.hm`.
|
|
195
|
+
*
|
|
196
|
+
* Severity is Error for all three — user explicitly wants typos caught.
|
|
197
|
+
*/
|
|
198
|
+
function getHmDiagnostics(uri, source, ctx) {
|
|
199
|
+
const parsed = parseHm(uri, source);
|
|
200
|
+
const diagnostics = [];
|
|
201
|
+
// --- 1. Parse errors ---
|
|
202
|
+
for (const ann of parsed.annotations) {
|
|
203
|
+
if (!ann.error)
|
|
204
|
+
continue;
|
|
205
|
+
const startOff = parsed.map.toOriginal(ann.commentStart);
|
|
206
|
+
const endOff = parsed.map.toOriginal(ann.commentEnd);
|
|
207
|
+
diagnostics.push({
|
|
208
|
+
severity: node_1.DiagnosticSeverity.Error,
|
|
209
|
+
range: rangeFromOffsets(source, startOff, endOff),
|
|
210
|
+
message: ann.error,
|
|
211
|
+
source: 'hinmil',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// --- Build local indices (shared by arity + unknown-type checks) ---
|
|
215
|
+
const annotationMap = (0, commentParser_1.buildAnnotationMap)(parsed.map.wrapped);
|
|
216
|
+
const aliasResult = (0, files_1.parseHmTypeAliases)(source);
|
|
217
|
+
const localTypeAliases = aliasResult.aliases;
|
|
218
|
+
// --- 2. Arity mismatches ---
|
|
219
|
+
const { arities: constructorArities, constructors: localConstructorNames } = collectLocalArities(annotationMap, localTypeAliases);
|
|
220
|
+
const aliasNames = new Set(localTypeAliases.keys());
|
|
221
|
+
const seenArityKeys = new Set();
|
|
222
|
+
const recordArity = (ann, name, actual, expected, localKeys) => {
|
|
223
|
+
const key = `${ann.commentStart}:${name}:${actual}:${expected}`;
|
|
224
|
+
if (localKeys.has(key))
|
|
225
|
+
return;
|
|
226
|
+
localKeys.add(key);
|
|
227
|
+
if (seenArityKeys.has(key))
|
|
228
|
+
return;
|
|
229
|
+
seenArityKeys.add(key);
|
|
230
|
+
diagnostics.push({
|
|
231
|
+
severity: node_1.DiagnosticSeverity.Error,
|
|
232
|
+
range: annotationDiagnosticRange(source, parsed.map, ann),
|
|
233
|
+
message: `Type constructor '${name}' expects ${expected} type argument(s) but got ${actual}`,
|
|
234
|
+
source: 'hinmil',
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
for (const ann of parsed.annotations) {
|
|
238
|
+
if (!ann.scheme)
|
|
239
|
+
continue;
|
|
240
|
+
const localKeys = new Set();
|
|
241
|
+
for (const t of (0, annotations_1.annotationTypeParts)(ann)) {
|
|
242
|
+
// Standard arity walker (mirrors JS pipeline). Note: this walker
|
|
243
|
+
// intentionally exempts zero-arg uses of names that look like type
|
|
244
|
+
// aliases (so `[Selector]` works), so it does not catch bare uses
|
|
245
|
+
// of real constructor annotations. We handle those below.
|
|
246
|
+
for (const m of (0, annotations_1.findArityMismatches)(t, constructorArities, aliasNames)) {
|
|
247
|
+
recordArity(ann, m.name, m.actual, m.expected, localKeys);
|
|
248
|
+
}
|
|
249
|
+
// Real constructors (e.g. `Prop :: (String, a) -> Prop b`) require
|
|
250
|
+
// their type arguments even when used bare — unlike aliases there
|
|
251
|
+
// is no "instantiate with fresh vars" fallback for them at the use
|
|
252
|
+
// site. Emit a dedicated arity error for `Prop` (not `Prop a`).
|
|
253
|
+
(0, typeUtils_1.eachType)(t, n => {
|
|
254
|
+
if (n.tag !== 'TCon')
|
|
255
|
+
return;
|
|
256
|
+
if (n.args.length !== 0)
|
|
257
|
+
return;
|
|
258
|
+
if (!localConstructorNames.has(n.name))
|
|
259
|
+
return;
|
|
260
|
+
const expected = constructorArities.get(n.name);
|
|
261
|
+
if (expected === undefined || expected === 0)
|
|
262
|
+
return;
|
|
263
|
+
recordArity(ann, n.name, 0, expected, localKeys);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// --- 3. Unknown type-constructor references ---
|
|
268
|
+
const known = buildKnownNames(annotationMap, localTypeAliases, parsed.map.wrapped, ctx);
|
|
269
|
+
for (const name of namesFromTypeDirectives(uri, parsed.map.wrapped))
|
|
270
|
+
known.add(name);
|
|
271
|
+
// Per-call resolution cache for cross-file fallback so we don't walk
|
|
272
|
+
// the sidecar chain twice for the same identifier.
|
|
273
|
+
const resolved = new Map();
|
|
274
|
+
const isResolvable = (name) => {
|
|
275
|
+
if (known.has(name))
|
|
276
|
+
return true;
|
|
277
|
+
const cached = resolved.get(name);
|
|
278
|
+
if (cached !== undefined)
|
|
279
|
+
return cached;
|
|
280
|
+
const ok = !!ctx && ctx.findTypeDefinitions(name).length > 0;
|
|
281
|
+
resolved.set(name, ok);
|
|
282
|
+
return ok;
|
|
283
|
+
};
|
|
284
|
+
for (const ann of parsed.annotations) {
|
|
285
|
+
if (!ann.scheme)
|
|
286
|
+
continue;
|
|
287
|
+
const reported = new Set();
|
|
288
|
+
for (const t of (0, annotations_1.annotationTypeParts)(ann)) {
|
|
289
|
+
const candidates = (0, types_1.findUnknownTCons)(t, known);
|
|
290
|
+
for (const name of candidates) {
|
|
291
|
+
if (reported.has(name))
|
|
292
|
+
continue;
|
|
293
|
+
if (isResolvable(name))
|
|
294
|
+
continue;
|
|
295
|
+
reported.add(name);
|
|
296
|
+
diagnostics.push({
|
|
297
|
+
severity: node_1.DiagnosticSeverity.Error,
|
|
298
|
+
range: annotationDiagnosticRange(source, parsed.map, ann),
|
|
299
|
+
message: `Unknown type constructor '${name}'`,
|
|
300
|
+
source: 'hinmil',
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// --- 4. `::curried` that does not mark a function of several arguments ---
|
|
306
|
+
for (const { line, name } of (0, files_1.curriedHmDeclarations)(source)) {
|
|
307
|
+
const anns = name ? parsed.annotations.filter(a => a.name === name && a.scheme) : [];
|
|
308
|
+
if (anns.length > 0 && anns.some(a => (0, files_1.takesSeveralArguments)(a.scheme.type)))
|
|
309
|
+
continue;
|
|
310
|
+
const start = source.split('\n').slice(0, line).reduce((n, l) => n + l.length + 1, 0);
|
|
311
|
+
diagnostics.push({
|
|
312
|
+
severity: node_1.DiagnosticSeverity.Warning,
|
|
313
|
+
range: rangeFromOffsets(source, start, start + source.split('\n')[line].length),
|
|
314
|
+
message: name
|
|
315
|
+
? `::curried has no effect: '${name}' is not a function of several arguments (a -> b -> c)`
|
|
316
|
+
: '::curried must stand directly above the declaration of a function',
|
|
317
|
+
source: 'hinmil',
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return diagnostics;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Collect arity information for type constructors visible *to this file*.
|
|
324
|
+
* Combines local constructor annotations / aliases / sumtypes with the
|
|
325
|
+
* global data-type and method registries plus hardcoded builtins. Mirrors
|
|
326
|
+
* the lookup cascade in `findArityMismatches` so registry-only types
|
|
327
|
+
* (e.g. `Array`, `Map`, `Promise`) participate too.
|
|
328
|
+
*/
|
|
329
|
+
function collectLocalArities(annotationMap, typeAliases) {
|
|
330
|
+
const arities = new Map();
|
|
331
|
+
const constructors = new Set();
|
|
332
|
+
// Constructor annotations: `Pair :: (a, b) -> Pair a b` → arity 2.
|
|
333
|
+
for (const [name, ann] of annotationMap) {
|
|
334
|
+
if (!ann.scheme)
|
|
335
|
+
continue;
|
|
336
|
+
if (name.includes('#') || name.includes('.'))
|
|
337
|
+
continue;
|
|
338
|
+
const ret = (0, types_1.getReturnType)(ann.scheme.type);
|
|
339
|
+
if (ret.tag === 'TCon' && ret.name === name && ret.args.length > 0) {
|
|
340
|
+
arities.set(name, ret.args.length);
|
|
341
|
+
constructors.add(name);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// Type aliases: free-var count is the alias's arity.
|
|
345
|
+
for (const [name, type] of typeAliases) {
|
|
346
|
+
if (arities.has(name))
|
|
347
|
+
continue;
|
|
348
|
+
const seen = new Set();
|
|
349
|
+
let count = 0;
|
|
350
|
+
(0, typeUtils_1.eachType)(type, n => {
|
|
351
|
+
if (n.tag === 'TVar' && !seen.has(n.name)) {
|
|
352
|
+
seen.add(n.name);
|
|
353
|
+
count++;
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
if (count > 0)
|
|
357
|
+
arities.set(name, count);
|
|
358
|
+
}
|
|
359
|
+
// Registered data types (from sumtype declarations across the workspace).
|
|
360
|
+
for (const name of (0, dataTypeRegistry_1.getDataTypeNames)()) {
|
|
361
|
+
if (arities.has(name))
|
|
362
|
+
continue;
|
|
363
|
+
const dt = (0, dataTypeRegistry_1.getDataType)(name);
|
|
364
|
+
if (dt && dt.decl.typeVars.length > 0)
|
|
365
|
+
arities.set(name, dt.decl.typeVars.length);
|
|
366
|
+
}
|
|
367
|
+
// Method registry arities (Array, Map, Set, Promise, registered sidecars).
|
|
368
|
+
for (const name of (0, methodRegistry_1.getRegisteredTypeNames)()) {
|
|
369
|
+
if (arities.has(name))
|
|
370
|
+
continue;
|
|
371
|
+
const a = (0, methodRegistry_1.getTypeArity)(name);
|
|
372
|
+
if (a > 0)
|
|
373
|
+
arities.set(name, a);
|
|
374
|
+
}
|
|
375
|
+
// Hardcoded builtins (StrMap etc.).
|
|
376
|
+
for (const [name, a] of annotations_1.BUILTIN_TYPE_ARITIES) {
|
|
377
|
+
if (!arities.has(name))
|
|
378
|
+
arities.set(name, a);
|
|
379
|
+
}
|
|
380
|
+
return { arities, constructors };
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Build the set of type-constructor names considered "known" for the
|
|
384
|
+
* unknown-type check. Anything not in this set falls through to the
|
|
385
|
+
* cross-file `findTypeDefinitions` fallback before being reported.
|
|
386
|
+
*/
|
|
387
|
+
/**
|
|
388
|
+
* Type names declared by the files a `.hm` file pulls in with `::types`
|
|
389
|
+
* (followed transitively). Without this, a sidecar that starts with
|
|
390
|
+
* `::types query-builder` (a query builder's generated `src/generated/client/index.hm`) reported
|
|
391
|
+
* every query-builder constructor as unknown whenever the target was not already
|
|
392
|
+
* known through package sidecars — e.g. inside a query builder's own repository.
|
|
393
|
+
*/
|
|
394
|
+
function namesFromTypeDirectives(uri, wrappedSource) {
|
|
395
|
+
const names = new Set();
|
|
396
|
+
const seen = new Set();
|
|
397
|
+
const visit = (fromUri, wrapped) => {
|
|
398
|
+
for (const spec of (0, commentParser_1.extractTypeDirectives)(wrapped)) {
|
|
399
|
+
let target = null;
|
|
400
|
+
try {
|
|
401
|
+
target = (0, files_1.resolveTypeDirectiveSpecifier)(spec, fromUri);
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
target = null;
|
|
405
|
+
}
|
|
406
|
+
if (!target || seen.has(target))
|
|
407
|
+
continue;
|
|
408
|
+
seen.add(target);
|
|
409
|
+
let text;
|
|
410
|
+
try {
|
|
411
|
+
text = fs.readFileSync(target, 'utf-8');
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const targetWrapped = target.endsWith('.hm') ? (0, files_1.wrapHmSource)(text) : text;
|
|
417
|
+
for (const name of (0, commentParser_1.buildAnnotationMap)(targetWrapped).keys()) {
|
|
418
|
+
if (name.includes('#'))
|
|
419
|
+
names.add(name.split('#')[0]);
|
|
420
|
+
else if (name.includes('.'))
|
|
421
|
+
names.add(name.split('.')[0]);
|
|
422
|
+
else if (/^[A-Z]/.test(name))
|
|
423
|
+
names.add(name);
|
|
424
|
+
}
|
|
425
|
+
if (target.endsWith('.hm')) {
|
|
426
|
+
for (const name of (0, files_1.parseHmTypeAliases)(text).aliases.keys())
|
|
427
|
+
names.add(name);
|
|
428
|
+
}
|
|
429
|
+
for (const decl of (0, commentParser_1.extractDataDirectives)(targetWrapped)) {
|
|
430
|
+
names.add(decl.name);
|
|
431
|
+
for (const v of decl.variants)
|
|
432
|
+
names.add(v.name);
|
|
433
|
+
}
|
|
434
|
+
visit((0, url_1.pathToFileURL)(target).href, targetWrapped);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
visit(uri, wrappedSource);
|
|
438
|
+
return names;
|
|
439
|
+
}
|
|
440
|
+
function buildKnownNames(annotationMap, typeAliases, wrappedSource, ctx) {
|
|
441
|
+
const known = new Set(annotations_1.BUILTIN_TYPE_NAMES);
|
|
442
|
+
// DOM/Fetch nominal types (Element, Event, Response, …) — valid in
|
|
443
|
+
// annotations when typed globals are on; Response always (fetch API).
|
|
444
|
+
for (const name of (0, domGlobals_1.activeDomAnnotationTypeNames)())
|
|
445
|
+
known.add(name);
|
|
446
|
+
// Local annotations — every uppercase non-method name + every method
|
|
447
|
+
// receiver type. This handles forward references within the same file.
|
|
448
|
+
for (const name of annotationMap.keys()) {
|
|
449
|
+
if (name.includes('#')) {
|
|
450
|
+
known.add(name.split('#')[0]);
|
|
451
|
+
}
|
|
452
|
+
else if (name.includes('.')) {
|
|
453
|
+
known.add(name.split('.')[0]);
|
|
454
|
+
}
|
|
455
|
+
else if (/^[A-Z]/.test(name)) {
|
|
456
|
+
known.add(name);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// Local type aliases.
|
|
460
|
+
for (const name of typeAliases.keys())
|
|
461
|
+
known.add(name);
|
|
462
|
+
// Local sumtype declarations (with their variants).
|
|
463
|
+
for (const decl of (0, commentParser_1.extractDataDirectives)(wrappedSource)) {
|
|
464
|
+
known.add(decl.name);
|
|
465
|
+
for (const v of decl.variants)
|
|
466
|
+
known.add(v.name);
|
|
467
|
+
}
|
|
468
|
+
// Global registries.
|
|
469
|
+
for (const name of (0, dataTypeRegistry_1.getDataTypeNames)())
|
|
470
|
+
known.add(name);
|
|
471
|
+
for (const name of (0, dataTypeRegistry_1.getVariantNames)())
|
|
472
|
+
known.add(name);
|
|
473
|
+
for (const name of (0, methodRegistry_1.getRegisteredTypeNames)())
|
|
474
|
+
known.add(name);
|
|
475
|
+
for (const name of (0, constraintRegistry_1.getConstraintNames)())
|
|
476
|
+
known.add(name);
|
|
477
|
+
// Names declared in the project globals file, when available.
|
|
478
|
+
if (ctx?.globals) {
|
|
479
|
+
const wrapped = (0, files_1.wrapHmSource)(ctx.globals.source);
|
|
480
|
+
for (const name of (0, commentParser_1.buildAnnotationMap)(wrapped).keys()) {
|
|
481
|
+
if (name.includes('#'))
|
|
482
|
+
known.add(name.split('#')[0]);
|
|
483
|
+
else if (name.includes('.'))
|
|
484
|
+
known.add(name.split('.')[0]);
|
|
485
|
+
else if (/^[A-Z]/.test(name))
|
|
486
|
+
known.add(name);
|
|
487
|
+
}
|
|
488
|
+
for (const decl of (0, commentParser_1.extractDataDirectives)(wrapped)) {
|
|
489
|
+
known.add(decl.name);
|
|
490
|
+
for (const v of decl.variants)
|
|
491
|
+
known.add(v.name);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return known;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Translate an annotation's diagnostic range from the wrapped buffer back
|
|
498
|
+
* to the original `.hm` source. Prefers the signature-name span (so only
|
|
499
|
+
* the LHS name is underlined) and falls back to the comment range.
|
|
500
|
+
*/
|
|
501
|
+
function annotationDiagnosticRange(source, map, ann) {
|
|
502
|
+
if (typeof ann.signatureNameStart === 'number' && typeof ann.signatureNameEnd === 'number') {
|
|
503
|
+
return rangeFromOffsets(source, map.toOriginal(ann.signatureNameStart), map.toOriginal(ann.signatureNameEnd));
|
|
504
|
+
}
|
|
505
|
+
return rangeFromOffsets(source, map.toOriginal(ann.commentStart), map.toOriginal(ann.commentEnd));
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Build a hover for a position inside a `.hm` file.
|
|
509
|
+
*
|
|
510
|
+
* Classification by token at `offset`:
|
|
511
|
+
* - Inside the LHS name span of an annotation → render the user-written
|
|
512
|
+
* raw signature (preserves overloads and original formatting).
|
|
513
|
+
* - On an uppercase identifier elsewhere → resolve via the cross-file
|
|
514
|
+
* `findTypeDefinitions` chain and render the raw signature.
|
|
515
|
+
* - Otherwise → no hover.
|
|
516
|
+
*/
|
|
517
|
+
function getHmHover(uri, source, offset, ctx) {
|
|
518
|
+
const parsed = parseHm(uri, source);
|
|
519
|
+
// Word boundaries in the ORIGINAL source.
|
|
520
|
+
const word = scanWordAt(source, offset);
|
|
521
|
+
if (!word)
|
|
522
|
+
return null;
|
|
523
|
+
const name = source.slice(word.start, word.end);
|
|
524
|
+
// 1) LHS name → render annotation signature (overload-aware).
|
|
525
|
+
for (const ann of parsed.annotations) {
|
|
526
|
+
if (ann.signatureNameStart === undefined || ann.signatureNameEnd === undefined)
|
|
527
|
+
continue;
|
|
528
|
+
if (!ann.name)
|
|
529
|
+
continue;
|
|
530
|
+
const startOrig = parsed.map.toOriginal(ann.signatureNameStart);
|
|
531
|
+
const endOrig = parsed.map.toOriginal(ann.signatureNameEnd);
|
|
532
|
+
if (offset >= startOrig && offset <= endOrig) {
|
|
533
|
+
const raws = (0, files_1.parseHmSourceRaw)(source);
|
|
534
|
+
const raw = raws.get(ann.name) ?? ann.raw;
|
|
535
|
+
return {
|
|
536
|
+
contents: { kind: 'markdown', value: '```hm\n' + ann.name + ' :: ' + raw + '\n```' },
|
|
537
|
+
range: rangeFromOffsets(source, startOrig, endOrig),
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
// 2) Uppercase identifier elsewhere → cross-file definition lookup.
|
|
542
|
+
if (/^[A-Z]/.test(name)) {
|
|
543
|
+
const defs = ctx.findTypeDefinitions(name);
|
|
544
|
+
if (defs.length > 0) {
|
|
545
|
+
const lines = ['```hm'];
|
|
546
|
+
for (const def of defs) {
|
|
547
|
+
lines.push(name + ' :: ' + def.raw);
|
|
548
|
+
}
|
|
549
|
+
lines.push('```');
|
|
550
|
+
if (defs.length > 1) {
|
|
551
|
+
const origins = defs.map(d => '`' + d.origin + '`').join(', ');
|
|
552
|
+
lines.push('', '_Defined in: ' + origins + '_');
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
lines.push('', '_Defined in: `' + defs[0].origin + '`_');
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
contents: { kind: 'markdown', value: lines.join('\n') },
|
|
559
|
+
range: rangeFromOffsets(source, word.start, word.end),
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
// ---------------------------------------------------------------------------
|
|
566
|
+
// Go-to-definition
|
|
567
|
+
// ---------------------------------------------------------------------------
|
|
568
|
+
/**
|
|
569
|
+
* Resolve go-to-definition for a position inside a `.hm` file. Only
|
|
570
|
+
* meaningful for uppercase identifiers (type constructors, sumtypes,
|
|
571
|
+
* constraints) — these are resolved by walking the same cross-file chain
|
|
572
|
+
* used by hover. When the identifier resolves to multiple sources they
|
|
573
|
+
* are all returned; the editor picks how to present them.
|
|
574
|
+
*/
|
|
575
|
+
function getHmDefinition(uri, source, offset, ctx) {
|
|
576
|
+
const word = scanWordAt(source, offset);
|
|
577
|
+
if (!word)
|
|
578
|
+
return null;
|
|
579
|
+
const name = source.slice(word.start, word.end);
|
|
580
|
+
if (!/^[A-Z]/.test(name))
|
|
581
|
+
return null;
|
|
582
|
+
const defs = ctx.findTypeDefinitions(name);
|
|
583
|
+
// Drop self-locations: when the cursor is on a declaration that lives in
|
|
584
|
+
// this very file, `findTypeDefinitions` will surface it again — returning
|
|
585
|
+
// it would be a no-op jump that hides results from other files.
|
|
586
|
+
const selfPath = (() => {
|
|
587
|
+
try {
|
|
588
|
+
return (0, url_1.fileURLToPath)(uri);
|
|
589
|
+
}
|
|
590
|
+
catch {
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
})();
|
|
594
|
+
const filtered = defs.filter(d => d.sourcePath !== selfPath);
|
|
595
|
+
const useDefs = filtered.length > 0 ? filtered : defs;
|
|
596
|
+
if (useDefs.length === 0)
|
|
597
|
+
return null;
|
|
598
|
+
const locations = [];
|
|
599
|
+
for (const def of useDefs) {
|
|
600
|
+
if (!def.sourcePath)
|
|
601
|
+
continue;
|
|
602
|
+
let text;
|
|
603
|
+
try {
|
|
604
|
+
text = fs.readFileSync(def.sourcePath, 'utf-8');
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
locations.push(node_1.Location.create((0, url_1.pathToFileURL)(def.sourcePath).href, {
|
|
610
|
+
start: (0, files_1.positionAt)(text, def.commentStart),
|
|
611
|
+
end: (0, files_1.positionAt)(text, def.commentEnd),
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
if (locations.length === 0)
|
|
615
|
+
return null;
|
|
616
|
+
return locations.length === 1 ? locations[0] : locations;
|
|
617
|
+
}
|
|
618
|
+
// ---------------------------------------------------------------------------
|
|
619
|
+
// Document symbols
|
|
620
|
+
// ---------------------------------------------------------------------------
|
|
621
|
+
/**
|
|
622
|
+
* A flat list of every named annotation in the file. Method annotations
|
|
623
|
+
* (`Type#method`) are marked as Method; uppercase-named annotations as
|
|
624
|
+
* Class; everything else as Variable. Directives (no `name`) and parse
|
|
625
|
+
* failures are skipped.
|
|
626
|
+
*/
|
|
627
|
+
function getHmDocumentSymbols(uri, source) {
|
|
628
|
+
const parsed = parseHm(uri, source);
|
|
629
|
+
const symbols = [];
|
|
630
|
+
for (const ann of parsed.annotations) {
|
|
631
|
+
if (!ann.name)
|
|
632
|
+
continue;
|
|
633
|
+
const cStart = parsed.map.toOriginal(ann.commentStart);
|
|
634
|
+
const cEnd = parsed.map.toOriginal(ann.commentEnd);
|
|
635
|
+
const range = rangeFromOffsets(source, cStart, cEnd);
|
|
636
|
+
let selectionRange = range;
|
|
637
|
+
if (ann.signatureNameStart !== undefined && ann.signatureNameEnd !== undefined) {
|
|
638
|
+
const nStart = parsed.map.toOriginal(ann.signatureNameStart);
|
|
639
|
+
const nEnd = parsed.map.toOriginal(ann.signatureNameEnd);
|
|
640
|
+
selectionRange = rangeFromOffsets(source, nStart, nEnd);
|
|
641
|
+
}
|
|
642
|
+
const kind = ann.name.includes('#')
|
|
643
|
+
? node_1.SymbolKind.Method
|
|
644
|
+
: ann.name.includes('.')
|
|
645
|
+
? node_1.SymbolKind.Method
|
|
646
|
+
: /^[A-Z]/.test(ann.name)
|
|
647
|
+
? node_1.SymbolKind.Class
|
|
648
|
+
: node_1.SymbolKind.Variable;
|
|
649
|
+
const detail = ann.raw ? ':: ' + ann.raw : undefined;
|
|
650
|
+
symbols.push({
|
|
651
|
+
name: ann.name,
|
|
652
|
+
detail,
|
|
653
|
+
kind,
|
|
654
|
+
range,
|
|
655
|
+
selectionRange,
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
return symbols;
|
|
659
|
+
}
|
|
660
|
+
// ---------------------------------------------------------------------------
|
|
661
|
+
// Helpers
|
|
662
|
+
// ---------------------------------------------------------------------------
|
|
663
|
+
function rangeFromOffsets(source, start, end) {
|
|
664
|
+
return { start: (0, files_1.positionAt)(source, start), end: (0, files_1.positionAt)(source, end) };
|
|
665
|
+
}
|
|
666
|
+
function scanWordAt(source, offset) {
|
|
667
|
+
const isWord = (ch) => /[A-Za-z0-9_$#]/.test(ch);
|
|
668
|
+
let start = offset;
|
|
669
|
+
while (start > 0 && isWord(source[start - 1]))
|
|
670
|
+
start--;
|
|
671
|
+
let end = offset;
|
|
672
|
+
while (end < source.length && isWord(source[end]))
|
|
673
|
+
end++;
|
|
674
|
+
if (start >= end)
|
|
675
|
+
return null;
|
|
676
|
+
// Strip a trailing or leading '#': we want either `Foo` or `Foo#bar`,
|
|
677
|
+
// not bare `#`.
|
|
678
|
+
let s = start;
|
|
679
|
+
let e = end;
|
|
680
|
+
while (s < e && source[s] === '#')
|
|
681
|
+
s++;
|
|
682
|
+
while (e > s && source[e - 1] === '#')
|
|
683
|
+
e--;
|
|
684
|
+
return s < e ? { start: s, end: e } : null;
|
|
685
|
+
}
|
|
686
|
+
//# sourceMappingURL=hmFileServices.js.map
|