@gmb/bitmark-parser 6.11.1 → 7.1.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 (45) hide show
  1. package/README.md +361 -57
  2. package/dist/browser/bitmark-parser.min.js +4 -4
  3. package/dist/browser/bitmark-parser.min.js.map +1 -1
  4. package/dist/browser/cjs/index.cjs +966 -372
  5. package/dist/browser/cjs/index.cjs.map +1 -1
  6. package/dist/browser/cjs/index.d.cts +642 -70
  7. package/dist/browser/esm/index.d.ts +642 -70
  8. package/dist/browser/esm/index.js +958 -371
  9. package/dist/browser/esm/index.js.map +1 -1
  10. package/dist/browser/esm/worker-entry.js +790 -247
  11. package/dist/browser/esm/worker-entry.js.map +1 -1
  12. package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
  13. package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
  14. package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
  15. package/dist/index.cjs +163 -124
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +637 -70
  18. package/dist/index.d.ts +637 -70
  19. package/dist/index.js +155 -123
  20. package/dist/index.js.map +1 -1
  21. package/dist/legacy.cjs +8 -30
  22. package/dist/legacy.cjs.map +1 -1
  23. package/dist/legacy.d.cts +0 -2
  24. package/dist/legacy.d.ts +0 -2
  25. package/dist/legacy.js +8 -30
  26. package/dist/legacy.js.map +1 -1
  27. package/dist/worker-entry.cjs +1 -5
  28. package/dist/worker-entry.cjs.map +1 -1
  29. package/package.json +7 -7
  30. package/schema/bitmark.schema.json +507 -141
  31. package/wasm/bitmark_wasm.d.ts +65 -26
  32. package/wasm/bitmark_wasm.js +348 -116
  33. package/wasm/bitmark_wasm_bg.wasm +0 -0
  34. package/wasm/bitmark_wasm_bg.wasm.d.ts +6 -3
  35. package/wasm/package.json +1 -1
  36. package/wasm-bitmark-json/bitmark_json_wasm.d.ts +56 -15
  37. package/wasm-bitmark-json/bitmark_json_wasm.js +321 -77
  38. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
  39. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +5 -2
  40. package/wasm-bitmark-json/package.json +1 -1
  41. package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +65 -26
  42. package/wasm-browser-full/bitmark_browser_full_wasm.js +348 -116
  43. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
  44. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +6 -3
  45. package/wasm-browser-full/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { createRequire } from "module";
10
10
  // src/generated/package_info.ts
11
11
  var PACKAGE_INFO = {
12
12
  "name": "@gmb/bitmark-parser",
13
- "version": "6.11.1",
13
+ "version": "7.1.0",
14
14
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
15
15
  "license": "ISC",
16
16
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -49,8 +49,11 @@ function getActive() {
49
49
  }
50
50
  function setActive(feature, module) {
51
51
  for (const [type, data] of registrations) {
52
- const error = module.register(type, data);
53
- if (error) throw new RegisterError(error.replace(/^error:\s*/, ""));
52
+ try {
53
+ module.register(type, data);
54
+ } catch (e) {
55
+ throw new RegisterError(e instanceof Error ? e.message : String(e));
56
+ }
54
57
  }
55
58
  active = module;
56
59
  activeFeature = feature;
@@ -66,13 +69,6 @@ function variant() {
66
69
  }
67
70
 
68
71
  // src/core/hooked-transform.ts
69
- function isError(s) {
70
- return s.startsWith("error:");
71
- }
72
- function errorString(e) {
73
- const m = e instanceof Error ? e.message : String(e);
74
- return m.startsWith("error:") ? m : `error: ${m}`;
75
- }
76
72
  function stripArray(doc) {
77
73
  const t = doc.trim();
78
74
  return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
@@ -84,17 +80,13 @@ function patchJsonOf(patch) {
84
80
  }
85
81
  function buildUnits(wasm, input, inputIsBitmark) {
86
82
  if (inputIsBitmark) {
87
- const out2 = wasm.split_bits(input);
88
- if (isError(out2)) throw new Error(out2);
89
- const slices = JSON.parse(out2);
83
+ const slices = JSON.parse(wasm.split_bits(input));
90
84
  return slices.map((s) => ({
91
85
  view: { format: "bitmark", index: s.index, total: slices.length, source: s.source },
92
86
  source: s.source
93
87
  }));
94
88
  }
95
- const out = wasm.split_json_bits(input);
96
- if (isError(out)) throw new Error(out);
97
- const envelopes = JSON.parse(out);
89
+ const envelopes = JSON.parse(wasm.split_json_bits(input));
98
90
  return envelopes.map((env, index) => ({
99
91
  view: { format: "json", index, total: envelopes.length, bit: env.bit ?? {} },
100
92
  // Per-bit transform consumes a one-bit JSON document.
@@ -110,6 +102,7 @@ function planTransform(wasm, input, options) {
110
102
  const sel = options.inputFormat ?? "auto";
111
103
  const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
112
104
  const inputFormat = inputIsBitmark ? "bitmark" : "json";
105
+ wasm.transform("", "bitmark", output, mode, "", false, indent, spacesAroundValues);
113
106
  const units = buildUnits(wasm, input, inputIsBitmark);
114
107
  const total = units.length;
115
108
  const hooked = [];
@@ -125,9 +118,9 @@ function planTransform(wasm, input, options) {
125
118
  if (patchJson === "") {
126
119
  resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
127
120
  } else {
128
- const out = wasm.resolve_patch_document(input, patchJson);
129
- if (isError(out)) throw new Error(out);
130
- resolved = JSON.parse(out);
121
+ resolved = JSON.parse(
122
+ wasm.resolve_patch_document(input, inputFormat, patchJson)
123
+ );
131
124
  }
132
125
  const jobs = [];
133
126
  const views = [];
@@ -174,25 +167,18 @@ function computeBit(wasm, job) {
174
167
  2,
175
168
  job.spacesAroundValues
176
169
  );
177
- if (isError(out)) return out;
178
170
  return job.outputFormat === "json" ? stripArray(out) : out;
179
171
  }
180
172
  function recombine(wasm, elements, output, pretty, indent) {
181
- if (output === "bitmark" || output === "text") return elements.join("\n");
173
+ if (output !== "json") return elements.join("\n");
182
174
  const arr = `[${elements.join(",")}]`;
183
175
  return pretty ? wasm.prettify(arr, indent) : arr;
184
176
  }
185
177
  function runHookedTransform(wasm, input, options) {
186
- let plan;
187
- try {
188
- plan = planTransform(wasm, input, options);
189
- } catch (e) {
190
- return errorString(e);
191
- }
178
+ const plan = planTransform(wasm, input, options);
192
179
  const rendered = [];
193
180
  for (let i = 0; i < plan.jobs.length; i++) {
194
181
  const element = computeBit(wasm, plan.jobs[i]);
195
- if (isError(element)) return element;
196
182
  options.postHook?.(plan.views[i], element);
197
183
  rendered.push(element);
198
184
  }
@@ -201,20 +187,9 @@ function runHookedTransform(wasm, input, options) {
201
187
 
202
188
  // src/core/parallel.ts
203
189
  async function orchestrateParallel(wasm, input, options, runJobs) {
204
- let plan;
205
- try {
206
- plan = planTransform(wasm, input, options);
207
- } catch (e) {
208
- return errorString(e);
209
- }
210
- let elements;
211
- try {
212
- elements = await runJobs(plan.jobs, options.workers ?? 4);
213
- } catch (e) {
214
- return errorString(e);
215
- }
190
+ const plan = planTransform(wasm, input, options);
191
+ const elements = await runJobs(plan.jobs, options.workers ?? 4);
216
192
  for (let i = 0; i < elements.length; i++) {
217
- if (isError(elements[i])) return elements[i];
218
193
  options.postHook?.(plan.views[i], elements[i]);
219
194
  }
220
195
  return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
@@ -223,62 +198,57 @@ async function orchestrateParallel(wasm, input, options, runJobs) {
223
198
  // src/node/pool.ts
224
199
  import { fileURLToPath } from "url";
225
200
  import { Worker } from "worker_threads";
226
- function workerPath() {
227
- return fileURLToPath(new URL("./worker-entry.cjs", import.meta.url));
228
- }
229
- function runJobsParallel(jobs, workers, feature) {
201
+
202
+ // src/core/pool.ts
203
+ function runJobsWithPool(jobs, workers, spawn) {
230
204
  if (jobs.length === 0) return Promise.resolve([]);
231
205
  const poolSize = Math.max(1, Math.min(workers, jobs.length));
232
- const path2 = workerPath();
233
- return new Promise((resolve, reject) => {
206
+ return new Promise((resolve2, reject) => {
234
207
  const results = new Array(jobs.length);
235
208
  let next = 0;
236
209
  let settled = 0;
237
210
  let done = false;
238
211
  const pool = [];
239
- const shutdown = () => {
240
- for (const w of pool) void w.terminate();
241
- };
242
- const fail = (err) => {
212
+ const finish = (err) => {
243
213
  if (done) return;
244
214
  done = true;
245
- shutdown();
246
- reject(err);
215
+ for (const w of pool) w.terminate();
216
+ if (err) reject(err);
217
+ else resolve2(results);
247
218
  };
248
219
  const dispatch = (w) => {
249
- if (done) return;
250
- if (next >= jobs.length) return;
220
+ if (done || next >= jobs.length) return;
251
221
  const id = next++;
252
- w.postMessage({ id, job: jobs[id] });
222
+ w.post({ id, job: jobs[id] });
253
223
  };
254
224
  for (let i = 0; i < poolSize; i++) {
255
- const w = new Worker(path2, { workerData: { feature } });
256
- pool.push(w);
257
- w.on("message", (res) => {
225
+ const w = spawn((res) => {
258
226
  if (done) return;
259
- if (!res.ok) {
260
- fail(new Error(res.error ?? "worker job failed"));
261
- return;
262
- }
227
+ if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
263
228
  results[res.id] = res.element;
264
- settled++;
265
- if (settled === jobs.length) {
266
- done = true;
267
- shutdown();
268
- resolve(results);
269
- return;
270
- }
271
- dispatch(w);
272
- });
273
- w.on("error", fail);
274
- w.on("exit", (code) => {
275
- if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));
276
- });
229
+ if (++settled === jobs.length) finish();
230
+ else dispatch(w);
231
+ }, finish);
232
+ pool.push(w);
277
233
  }
278
234
  for (const w of pool) dispatch(w);
279
235
  });
280
236
  }
281
237
 
238
+ // src/node/pool.ts
239
+ function runJobsParallel(jobs, workers, feature) {
240
+ const path2 = fileURLToPath(new URL("./worker-entry.cjs", import.meta.url));
241
+ return runJobsWithPool(jobs, workers, (onResult, onError) => {
242
+ const w = new Worker(path2, { workerData: { feature } });
243
+ w.on("message", (res) => onResult(res));
244
+ w.on("error", onError);
245
+ w.on("exit", (code) => {
246
+ if (code !== 0) onError(new Error(`worker exited with code ${code}`));
247
+ });
248
+ return { post: (msg) => w.postMessage(msg), terminate: () => void w.terminate() };
249
+ });
250
+ }
251
+
282
252
  // src/node/transform-parallel.ts
283
253
  function runParallelTransform(wasm, input, options) {
284
254
  const feature = variant() ?? "full";
@@ -569,10 +539,7 @@ var Builder = class {
569
539
  }
570
540
  }
571
541
  this.parseStringTexts(bit);
572
- const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
573
- if (out.startsWith("error:")) {
574
- throw new Error(out.slice("error:".length).trim());
575
- }
542
+ const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false, "", "");
576
543
  const entries = JSON.parse(out);
577
544
  const built = entries[0]?.bit ?? bit;
578
545
  for (const [key, value] of Object.entries(bit)) {
@@ -709,8 +676,7 @@ var BitmarkParserGenerator = class {
709
676
  const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
710
677
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
711
678
  const includeUnknown = !jsonOptions.excludeUnknownProperties;
712
- const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
713
- this.throwOnError(out);
679
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false, "", "");
714
680
  if (outputFormat === "bitmark" || outputFormat === "text") {
715
681
  return this.deliver(out, opts.outputFile, opts.fileOptions);
716
682
  }
@@ -744,7 +710,6 @@ var BitmarkParserGenerator = class {
744
710
  );
745
711
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
746
712
  const out = wasm.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
747
- this.throwOnError(out);
748
713
  if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
749
714
  if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
750
715
  if (pretty || jsonOptions.stringify) return out;
@@ -761,7 +726,6 @@ var BitmarkParserGenerator = class {
761
726
  const { pretty, indent } = prettyIndent(opts.prettify);
762
727
  const coreFormat = format === "pojo" ? "json" : format;
763
728
  const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true, "");
764
- this.throwOnError(out);
765
729
  if (format === "pojo") return JSON.parse(out);
766
730
  return out;
767
731
  }
@@ -793,8 +757,7 @@ var BitmarkParserGenerator = class {
793
757
  const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
794
758
  if (!isHtmlInput) {
795
759
  const { source, isBitmark } = this.resolveInput(input, void 0);
796
- const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
797
- this.throwOnError(out2);
760
+ const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false, "", "");
798
761
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
799
762
  }
800
763
  const bitType = opts.tableFormat === "table" ? "table" : "table-extended";
@@ -803,13 +766,11 @@ var BitmarkParserGenerator = class {
803
766
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
804
767
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
805
768
  if (outputFormat === "html") {
806
- const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
807
- this.throwOnError(out2);
769
+ const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false, "", "");
808
770
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
809
771
  }
810
772
  const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
811
- const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
812
- this.throwOnError(out);
773
+ const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false, "", "");
813
774
  if (outputFormat === "bitmark" || outputFormat === "text") {
814
775
  return this.deliver(out, opts.outputFile, opts.fileOptions);
815
776
  }
@@ -833,8 +794,7 @@ var BitmarkParserGenerator = class {
833
794
  const opts = Object.assign({}, options);
834
795
  const wasm = getLegacyWasm();
835
796
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
836
- const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
837
- this.throwOnError(out);
797
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false, "", "");
838
798
  return makePseudoAst(JSON.parse(out));
839
799
  }
840
800
  /**
@@ -886,11 +846,9 @@ var BitmarkParserGenerator = class {
886
846
  }
887
847
  if (ast !== void 0) {
888
848
  const out2 = isBitmarkText ? wasm.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
889
- this.throwOnError(out2);
890
849
  return this.deliver(out2, opts.outputFile, opts.fileOptions);
891
850
  }
892
851
  const out = wasm.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
893
- this.throwOnError(out);
894
852
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
895
853
  const outStr = pretty ? wasm.prettify(out, indent) : out;
896
854
  if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
@@ -908,7 +866,6 @@ var BitmarkParserGenerator = class {
908
866
  "bitmark++",
909
867
  "body"
910
868
  );
911
- this.throwOnError(out);
912
869
  return out;
913
870
  }
914
871
  /**
@@ -923,7 +880,6 @@ var BitmarkParserGenerator = class {
923
880
  if (inputFormat === "bitmarkText") {
924
881
  const ast = wasm.convert_text(String(input), "textToAst", "bitmark++", "body");
925
882
  const out2 = wasm.convert_text(ast, "astToPlainText", "bitmark++", "body");
926
- this.throwOnError(out2);
927
883
  return out2;
928
884
  }
929
885
  if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm.is_bitmark(input)) {
@@ -940,8 +896,7 @@ var BitmarkParserGenerator = class {
940
896
  }
941
897
  }
942
898
  const { source, isBitmark } = this.resolveInput(input, void 0);
943
- const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
944
- this.throwOnError(out);
899
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false, "", "");
945
900
  return out;
946
901
  }
947
902
  /** If `s` parses as a TextAst JSON array, return it. */
@@ -1045,12 +1000,6 @@ var BitmarkParserGenerator = class {
1045
1000
  encoding: fileOptions?.encoding ?? "utf8"
1046
1001
  });
1047
1002
  }
1048
- /** The core reports failures as `error:`-prefixed strings; bpg throws. */
1049
- throwOnError(out) {
1050
- if (out.startsWith("error:")) {
1051
- throw new Error(out.slice("error:".length).trim());
1052
- }
1053
- }
1054
1003
  };
1055
1004
  function extractHtmlTables(html) {
1056
1005
  const tables = [];
@@ -1087,7 +1036,6 @@ function extractHtmlTables(html) {
1087
1036
  }
1088
1037
  function bitmarkTextParse(text) {
1089
1038
  const out = getLegacyWasm().convert_text(text, "textToAst", "bitmark++", "body");
1090
- if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1091
1039
  return JSON.parse(out);
1092
1040
  }
1093
1041
 
@@ -1410,6 +1358,24 @@ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
1410
1358
  var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
1411
1359
  var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
1412
1360
 
1361
+ // src/editor-types.ts
1362
+ var DiagnosticSeverity = {
1363
+ Error: 1,
1364
+ Warning: 2,
1365
+ Information: 3,
1366
+ Hint: 4
1367
+ };
1368
+ var CompletionItemKind = {
1369
+ Class: 7,
1370
+ Property: 10,
1371
+ Value: 12,
1372
+ Keyword: 14,
1373
+ Snippet: 15,
1374
+ EnumMember: 20,
1375
+ TypeParameter: 25
1376
+ };
1377
+ var CompletionItemTag = { Deprecated: 1 };
1378
+
1413
1379
  // src/types.ts
1414
1380
  function patchEntry(path2, op, value) {
1415
1381
  return value === void 0 ? { path: path2, op } : { path: path2, op, value };
@@ -1417,11 +1383,6 @@ function patchEntry(path2, op, value) {
1417
1383
  var ALL_LANGUAGES = "all";
1418
1384
 
1419
1385
  // src/core/api.ts
1420
- function lex(input, options = {}) {
1421
- const wasm = getActive();
1422
- if (typeof wasm.lex !== "function") throw new UnsupportedFeatureError("lex", variant());
1423
- return wasm.lex(input, options.stage ?? "lex");
1424
- }
1425
1386
  function bitmarkToObjects(input, options = {}) {
1426
1387
  const out = getActive().convert(
1427
1388
  input,
@@ -1432,9 +1393,10 @@ function bitmarkToObjects(input, options = {}) {
1432
1393
  2,
1433
1394
  1,
1434
1395
  options.includeUnknownProperties ?? false,
1435
- false
1396
+ false,
1397
+ "",
1398
+ ""
1436
1399
  );
1437
- if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1438
1400
  return JSON.parse(out);
1439
1401
  }
1440
1402
  function objectsToBitmark(bits, options = {}) {
@@ -1450,9 +1412,10 @@ function objectsToBitmark(bits, options = {}) {
1450
1412
  2,
1451
1413
  1,
1452
1414
  false,
1453
- false
1415
+ false,
1416
+ "",
1417
+ ""
1454
1418
  );
1455
- if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1456
1419
  return out;
1457
1420
  }
1458
1421
  function convert(input, options = {}) {
@@ -1465,7 +1428,65 @@ function convert(input, options = {}) {
1465
1428
  options.indent ?? 2,
1466
1429
  options.spacesAroundValues ?? 1,
1467
1430
  options.includeUnknownProperties ?? false,
1468
- options.mappingReport ?? false
1431
+ options.mappingReport ?? false,
1432
+ options.positionEncoding ?? "",
1433
+ options.tokensLayout ?? ""
1434
+ );
1435
+ }
1436
+ function semanticTokens(input, options = {}) {
1437
+ return JSON.parse(
1438
+ convert(input, {
1439
+ inputFormat: "bitmark",
1440
+ outputFormat: "semantic-tokens",
1441
+ positionEncoding: options.positionEncoding,
1442
+ tokensLayout: options.tokensLayout
1443
+ })
1444
+ );
1445
+ }
1446
+ function diagnostics(input, options = {}) {
1447
+ return JSON.parse(
1448
+ convert(input, {
1449
+ inputFormat: "bitmark",
1450
+ outputFormat: "diagnostics",
1451
+ positionEncoding: options.positionEncoding
1452
+ })
1453
+ );
1454
+ }
1455
+ function complete(input, position, options = {}) {
1456
+ const wasm = getActive();
1457
+ if (typeof wasm.complete !== "function") throw new UnsupportedFeatureError("complete", variant());
1458
+ return JSON.parse(
1459
+ wasm.complete(
1460
+ input,
1461
+ position.line,
1462
+ position.character,
1463
+ options.positionEncoding ?? "",
1464
+ options.includeDeprecated ?? false,
1465
+ options.triggerCharacter ?? ""
1466
+ )
1467
+ );
1468
+ }
1469
+ function resolve(input, position, item, options = {}) {
1470
+ const wasm = getActive();
1471
+ if (typeof wasm.resolve !== "function") throw new UnsupportedFeatureError("resolve", variant());
1472
+ const resolved = JSON.parse(
1473
+ wasm.resolve(
1474
+ input,
1475
+ position.line,
1476
+ position.character,
1477
+ options.positionEncoding ?? "",
1478
+ options.includeDeprecated ?? false,
1479
+ item.label,
1480
+ item.kind
1481
+ )
1482
+ );
1483
+ return resolved ?? item;
1484
+ }
1485
+ function hover(input, position, options = {}) {
1486
+ const wasm = getActive();
1487
+ if (typeof wasm.hover !== "function") throw new UnsupportedFeatureError("hover", variant());
1488
+ return JSON.parse(
1489
+ wasm.hover(input, position.line, position.character, options.positionEncoding ?? "")
1469
1490
  );
1470
1491
  }
1471
1492
  function canonicalize(input, options = {}) {
@@ -1479,9 +1500,7 @@ function canonicalize(input, options = {}) {
1479
1500
  );
1480
1501
  }
1481
1502
  function countBits(input) {
1482
- const out = getActive().count_bits(input);
1483
- if (out.startsWith("error:")) throw new Error(out);
1484
- return Number.parseInt(out, 10);
1503
+ return Number.parseInt(getActive().count_bits(input), 10);
1485
1504
  }
1486
1505
  function splitBits(input) {
1487
1506
  return JSON.parse(getActive().split_bits(input));
@@ -1517,7 +1536,6 @@ function diff(a, b, options = {}) {
1517
1536
  options.bboxTolerance ?? 8,
1518
1537
  options.spacesAroundValues ?? 0
1519
1538
  );
1520
- if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1521
1539
  return out;
1522
1540
  }
1523
1541
  function diffBits(a, b, options = {}) {
@@ -1543,7 +1561,11 @@ function info(options = {}) {
1543
1561
  const onlyDeprecated = options.onlyDeprecated ?? false;
1544
1562
  const full = options.full ?? false;
1545
1563
  const language = typeof options.language === "string" ? options.language : options.language?.join(",") ?? "";
1546
- return getActive().info(
1564
+ const wasm = getActive();
1565
+ if (format !== "json" && typeof wasm.info_text_supported !== "function") {
1566
+ throw new UnsupportedFeatureError('info (format: "text")', variant());
1567
+ }
1568
+ return wasm.info(
1547
1569
  infoType,
1548
1570
  format,
1549
1571
  bit,
@@ -1556,8 +1578,11 @@ function info(options = {}) {
1556
1578
  );
1557
1579
  }
1558
1580
  function register(options) {
1559
- const result = getActive().register(options.type, options.data);
1560
- if (result) throw new RegisterError(result.replace(/^error:\s*/, ""));
1581
+ try {
1582
+ getActive().register(options.type, options.data);
1583
+ } catch (e) {
1584
+ throw new RegisterError(e instanceof Error ? e.message : String(e));
1585
+ }
1561
1586
  rememberRegistration(options.type, options.data);
1562
1587
  }
1563
1588
 
@@ -1592,24 +1617,31 @@ function transformParallel(input, options = {}) {
1592
1617
  }
1593
1618
  export {
1594
1619
  ALL_LANGUAGES,
1620
+ CompletionItemKind,
1621
+ CompletionItemTag,
1622
+ DiagnosticSeverity,
1595
1623
  NotInitializedError,
1596
1624
  RegisterError,
1597
1625
  UnsupportedFeatureError,
1598
1626
  bitmarkToObjects,
1599
1627
  breakscapeText,
1600
1628
  canonicalize,
1629
+ complete,
1601
1630
  convert,
1602
1631
  countBits,
1632
+ diagnostics,
1603
1633
  diff,
1604
1634
  diffBits,
1635
+ hover,
1605
1636
  info,
1606
1637
  init,
1607
1638
  initSync,
1608
1639
  legacy_exports as legacy,
1609
- lex,
1610
1640
  objectsToBitmark,
1611
1641
  patchEntry,
1612
1642
  register,
1643
+ resolve,
1644
+ semanticTokens,
1613
1645
  splitBits,
1614
1646
  transform,
1615
1647
  transformParallel,