openalgo-script 0.2.0 → 0.4.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 (276) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/README.md +65 -31
  3. package/dist/adapters/charts/surfaces.d.ts +17 -0
  4. package/dist/adapters/charts/surfaces.d.ts.map +1 -1
  5. package/dist/adapters/charts/tables.js +82 -0
  6. package/dist/adapters/charts/tables.js.map +1 -1
  7. package/dist/adapters/codemirror/commands.d.ts +14 -0
  8. package/dist/adapters/codemirror/commands.d.ts.map +1 -0
  9. package/dist/adapters/codemirror/commands.js +52 -0
  10. package/dist/adapters/codemirror/commands.js.map +1 -0
  11. package/dist/adapters/codemirror/completion.d.ts +15 -0
  12. package/dist/adapters/codemirror/completion.d.ts.map +1 -0
  13. package/dist/adapters/codemirror/completion.js +64 -0
  14. package/dist/adapters/codemirror/completion.js.map +1 -0
  15. package/dist/adapters/codemirror/contract.d.ts +156 -0
  16. package/dist/adapters/codemirror/contract.d.ts.map +1 -0
  17. package/dist/adapters/codemirror/contract.js +42 -0
  18. package/dist/adapters/codemirror/contract.js.map +1 -0
  19. package/dist/adapters/codemirror/index.d.ts +43 -0
  20. package/dist/adapters/codemirror/index.d.ts.map +1 -0
  21. package/dist/adapters/codemirror/index.js +8 -0
  22. package/dist/adapters/codemirror/index.js.map +1 -0
  23. package/dist/adapters/codemirror/lint.d.ts +17 -0
  24. package/dist/adapters/codemirror/lint.d.ts.map +1 -0
  25. package/dist/adapters/codemirror/lint.js +62 -0
  26. package/dist/adapters/codemirror/lint.js.map +1 -0
  27. package/dist/adapters/codemirror/positions.d.ts +16 -0
  28. package/dist/adapters/codemirror/positions.d.ts.map +1 -0
  29. package/dist/adapters/codemirror/positions.js +65 -0
  30. package/dist/adapters/codemirror/positions.js.map +1 -0
  31. package/dist/adapters/codemirror/stream.d.ts +23 -0
  32. package/dist/adapters/codemirror/stream.d.ts.map +1 -0
  33. package/dist/adapters/codemirror/stream.js +70 -0
  34. package/dist/adapters/codemirror/stream.js.map +1 -0
  35. package/dist/adapters/codemirror/tokens.d.ts +44 -0
  36. package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
  37. package/dist/adapters/codemirror/tokens.js +34 -0
  38. package/dist/adapters/codemirror/tokens.js.map +1 -0
  39. package/dist/adapters/codemirror/tooltips.d.ts +35 -0
  40. package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
  41. package/dist/adapters/codemirror/tooltips.js +108 -0
  42. package/dist/adapters/codemirror/tooltips.js.map +1 -0
  43. package/dist/core/accounting/charges.d.ts +136 -0
  44. package/dist/core/accounting/charges.d.ts.map +1 -0
  45. package/dist/core/accounting/charges.js +362 -0
  46. package/dist/core/accounting/charges.js.map +1 -0
  47. package/dist/core/accounting/equity.d.ts +158 -0
  48. package/dist/core/accounting/equity.d.ts.map +1 -0
  49. package/dist/core/accounting/equity.js +155 -0
  50. package/dist/core/accounting/equity.js.map +1 -0
  51. package/dist/core/accounting/index.d.ts +44 -0
  52. package/dist/core/accounting/index.d.ts.map +1 -0
  53. package/dist/core/accounting/index.js +36 -0
  54. package/dist/core/accounting/index.js.map +1 -0
  55. package/dist/core/accounting/markers.d.ts +43 -0
  56. package/dist/core/accounting/markers.d.ts.map +1 -0
  57. package/dist/core/accounting/markers.js +64 -0
  58. package/dist/core/accounting/markers.js.map +1 -0
  59. package/dist/core/accounting/monthly.d.ts +52 -0
  60. package/dist/core/accounting/monthly.d.ts.map +1 -0
  61. package/dist/core/accounting/monthly.js +99 -0
  62. package/dist/core/accounting/monthly.js.map +1 -0
  63. package/dist/core/accounting/report.d.ts +38 -0
  64. package/dist/core/accounting/report.d.ts.map +1 -0
  65. package/dist/core/accounting/report.js +63 -0
  66. package/dist/core/accounting/report.js.map +1 -0
  67. package/dist/core/accounting/shapes.d.ts +70 -0
  68. package/dist/core/accounting/shapes.d.ts.map +1 -0
  69. package/dist/core/accounting/shapes.js +21 -0
  70. package/dist/core/accounting/shapes.js.map +1 -0
  71. package/dist/core/accounting/statistics.d.ts +75 -0
  72. package/dist/core/accounting/statistics.d.ts.map +1 -0
  73. package/dist/core/accounting/statistics.js +246 -0
  74. package/dist/core/accounting/statistics.js.map +1 -0
  75. package/dist/core/accounting/trades.d.ts +118 -0
  76. package/dist/core/accounting/trades.d.ts.map +1 -0
  77. package/dist/core/accounting/trades.js +186 -0
  78. package/dist/core/accounting/trades.js.map +1 -0
  79. package/dist/core/backtest/compare.d.ts +38 -0
  80. package/dist/core/backtest/compare.d.ts.map +1 -0
  81. package/dist/core/backtest/compare.js +189 -0
  82. package/dist/core/backtest/compare.js.map +1 -0
  83. package/dist/core/backtest/declaration.d.ts +52 -0
  84. package/dist/core/backtest/declaration.d.ts.map +1 -0
  85. package/dist/core/backtest/declaration.js +48 -0
  86. package/dist/core/backtest/declaration.js.map +1 -0
  87. package/dist/core/backtest/drive.d.ts +29 -0
  88. package/dist/core/backtest/drive.d.ts.map +1 -0
  89. package/dist/core/backtest/drive.js +262 -0
  90. package/dist/core/backtest/drive.js.map +1 -0
  91. package/dist/core/backtest/index.d.ts +46 -0
  92. package/dist/core/backtest/index.d.ts.map +1 -0
  93. package/dist/core/backtest/index.js +36 -0
  94. package/dist/core/backtest/index.js.map +1 -0
  95. package/dist/core/backtest/range.d.ts +84 -0
  96. package/dist/core/backtest/range.d.ts.map +1 -0
  97. package/dist/core/backtest/range.js +90 -0
  98. package/dist/core/backtest/range.js.map +1 -0
  99. package/dist/core/backtest/record.d.ts +238 -0
  100. package/dist/core/backtest/record.d.ts.map +1 -0
  101. package/dist/core/backtest/record.js +176 -0
  102. package/dist/core/backtest/record.js.map +1 -0
  103. package/dist/core/backtest/replay.d.ts +48 -0
  104. package/dist/core/backtest/replay.d.ts.map +1 -0
  105. package/dist/core/backtest/replay.js +127 -0
  106. package/dist/core/backtest/replay.js.map +1 -0
  107. package/dist/core/backtest/resting.d.ts +62 -0
  108. package/dist/core/backtest/resting.d.ts.map +1 -0
  109. package/dist/core/backtest/resting.js +59 -0
  110. package/dist/core/backtest/resting.js.map +1 -0
  111. package/dist/core/backtest/settings.d.ts +117 -0
  112. package/dist/core/backtest/settings.d.ts.map +1 -0
  113. package/dist/core/backtest/settings.js +207 -0
  114. package/dist/core/backtest/settings.js.map +1 -0
  115. package/dist/core/backtest/simulate.d.ts +146 -0
  116. package/dist/core/backtest/simulate.d.ts.map +1 -0
  117. package/dist/core/backtest/simulate.js +217 -0
  118. package/dist/core/backtest/simulate.js.map +1 -0
  119. package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
  120. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  121. package/dist/core/catalogue/catalogue.generated.js +6 -0
  122. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  123. package/dist/core/catalogue/values.generated.d.ts +24 -0
  124. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  125. package/dist/core/check/index.d.ts +2 -1
  126. package/dist/core/check/index.d.ts.map +1 -1
  127. package/dist/core/check/index.js +1 -1
  128. package/dist/core/check/index.js.map +1 -1
  129. package/dist/core/check/library-prose.generated.d.ts +16 -0
  130. package/dist/core/check/library-prose.generated.d.ts.map +1 -0
  131. package/dist/core/check/library-prose.generated.js +353 -0
  132. package/dist/core/check/library-prose.generated.js.map +1 -0
  133. package/dist/core/check/surface.d.ts +24 -0
  134. package/dist/core/check/surface.d.ts.map +1 -1
  135. package/dist/core/check/surface.js +29 -0
  136. package/dist/core/check/surface.js.map +1 -1
  137. package/dist/core/emit/defaults.d.ts +35 -16
  138. package/dist/core/emit/defaults.d.ts.map +1 -1
  139. package/dist/core/emit/defaults.js +66 -0
  140. package/dist/core/emit/defaults.js.map +1 -1
  141. package/dist/core/emit/index.d.ts +2 -0
  142. package/dist/core/emit/index.d.ts.map +1 -1
  143. package/dist/core/emit/index.js +2 -0
  144. package/dist/core/emit/index.js.map +1 -1
  145. package/dist/core/engine/index.d.ts +1 -1
  146. package/dist/core/engine/index.d.ts.map +1 -1
  147. package/dist/core/engine/index.js +1 -1
  148. package/dist/core/engine/index.js.map +1 -1
  149. package/dist/core/engine/load.d.ts +15 -1
  150. package/dist/core/engine/load.d.ts.map +1 -1
  151. package/dist/core/engine/load.js +1 -0
  152. package/dist/core/engine/load.js.map +1 -1
  153. package/dist/core/index.d.ts +37 -3
  154. package/dist/core/index.d.ts.map +1 -1
  155. package/dist/core/index.js +17 -1
  156. package/dist/core/index.js.map +1 -1
  157. package/dist/core/version/version.generated.d.ts +1 -1
  158. package/dist/core/version/version.generated.js +1 -1
  159. package/dist/editor/complete.d.ts +40 -0
  160. package/dist/editor/complete.d.ts.map +1 -0
  161. package/dist/editor/complete.js +206 -0
  162. package/dist/editor/complete.js.map +1 -0
  163. package/dist/editor/diagnose.d.ts +18 -0
  164. package/dist/editor/diagnose.d.ts.map +1 -0
  165. package/dist/editor/diagnose.js +70 -0
  166. package/dist/editor/diagnose.js.map +1 -0
  167. package/dist/editor/format.d.ts +11 -0
  168. package/dist/editor/format.d.ts.map +1 -0
  169. package/dist/editor/format.js +50 -0
  170. package/dist/editor/format.js.map +1 -0
  171. package/dist/editor/highlight.d.ts +28 -0
  172. package/dist/editor/highlight.d.ts.map +1 -0
  173. package/dist/editor/highlight.js +65 -0
  174. package/dist/editor/highlight.js.map +1 -0
  175. package/dist/editor/hover.d.ts +40 -0
  176. package/dist/editor/hover.d.ts.map +1 -0
  177. package/dist/editor/hover.js +147 -0
  178. package/dist/editor/hover.js.map +1 -0
  179. package/dist/editor/index.d.ts +60 -0
  180. package/dist/editor/index.d.ts.map +1 -0
  181. package/dist/editor/index.js +7 -0
  182. package/dist/editor/index.js.map +1 -0
  183. package/dist/editor/kinds.d.ts +27 -0
  184. package/dist/editor/kinds.d.ts.map +1 -0
  185. package/dist/editor/kinds.js +118 -0
  186. package/dist/editor/kinds.js.map +1 -0
  187. package/dist/editor/layout.d.ts +47 -0
  188. package/dist/editor/layout.d.ts.map +1 -0
  189. package/dist/editor/layout.js +135 -0
  190. package/dist/editor/layout.js.map +1 -0
  191. package/dist/editor/manifest.d.ts +47 -0
  192. package/dist/editor/manifest.d.ts.map +1 -0
  193. package/dist/editor/manifest.js +93 -0
  194. package/dist/editor/manifest.js.map +1 -0
  195. package/dist/editor/reading.d.ts +41 -0
  196. package/dist/editor/reading.d.ts.map +1 -0
  197. package/dist/editor/reading.js +51 -0
  198. package/dist/editor/reading.js.map +1 -0
  199. package/dist/editor/scan.d.ts +26 -0
  200. package/dist/editor/scan.d.ts.map +1 -0
  201. package/dist/editor/scan.js +139 -0
  202. package/dist/editor/scan.js.map +1 -0
  203. package/dist/editor/scope.d.ts +19 -0
  204. package/dist/editor/scope.d.ts.map +1 -0
  205. package/dist/editor/scope.js +99 -0
  206. package/dist/editor/scope.js.map +1 -0
  207. package/dist/editor/signature.d.ts +38 -0
  208. package/dist/editor/signature.d.ts.map +1 -0
  209. package/dist/editor/signature.js +112 -0
  210. package/dist/editor/signature.js.map +1 -0
  211. package/dist/editor/site.d.ts +46 -0
  212. package/dist/editor/site.d.ts.map +1 -0
  213. package/dist/editor/site.js +184 -0
  214. package/dist/editor/site.js.map +1 -0
  215. package/dist/editor/spacing.d.ts +29 -0
  216. package/dist/editor/spacing.d.ts.map +1 -0
  217. package/dist/editor/spacing.js +116 -0
  218. package/dist/editor/spacing.js.map +1 -0
  219. package/package.json +30 -3
  220. package/spec/errors.json +140 -0
  221. package/src/adapters/charts/surfaces.ts +17 -0
  222. package/src/adapters/charts/tables.ts +88 -0
  223. package/src/adapters/codemirror/commands.ts +53 -0
  224. package/src/adapters/codemirror/completion.ts +74 -0
  225. package/src/adapters/codemirror/contract.ts +156 -0
  226. package/src/adapters/codemirror/index.ts +66 -0
  227. package/src/adapters/codemirror/lint.ts +66 -0
  228. package/src/adapters/codemirror/positions.ts +79 -0
  229. package/src/adapters/codemirror/stream.ts +87 -0
  230. package/src/adapters/codemirror/tokens.ts +64 -0
  231. package/src/adapters/codemirror/tooltips.ts +113 -0
  232. package/src/core/accounting/charges.ts +452 -0
  233. package/src/core/accounting/equity.ts +276 -0
  234. package/src/core/accounting/index.ts +49 -0
  235. package/src/core/accounting/markers.ts +95 -0
  236. package/src/core/accounting/monthly.ts +137 -0
  237. package/src/core/accounting/report.ts +89 -0
  238. package/src/core/accounting/shapes.ts +73 -0
  239. package/src/core/accounting/statistics.ts +350 -0
  240. package/src/core/accounting/trades.ts +313 -0
  241. package/src/core/backtest/compare.ts +244 -0
  242. package/src/core/backtest/declaration.ts +97 -0
  243. package/src/core/backtest/drive.ts +364 -0
  244. package/src/core/backtest/index.ts +52 -0
  245. package/src/core/backtest/range.ts +137 -0
  246. package/src/core/backtest/record.ts +341 -0
  247. package/src/core/backtest/replay.ts +158 -0
  248. package/src/core/backtest/resting.ts +125 -0
  249. package/src/core/backtest/settings.ts +280 -0
  250. package/src/core/backtest/simulate.ts +304 -0
  251. package/src/core/catalogue/catalogue.generated.ts +6 -0
  252. package/src/core/catalogue/values.generated.ts +6 -0
  253. package/src/core/check/index.ts +3 -0
  254. package/src/core/check/library-prose.generated.ts +367 -0
  255. package/src/core/check/surface.ts +34 -0
  256. package/src/core/emit/defaults.ts +70 -0
  257. package/src/core/emit/index.ts +2 -0
  258. package/src/core/engine/index.ts +1 -1
  259. package/src/core/engine/load.ts +16 -2
  260. package/src/core/index.ts +85 -1
  261. package/src/core/version/version.generated.ts +1 -1
  262. package/src/editor/complete.ts +266 -0
  263. package/src/editor/diagnose.ts +71 -0
  264. package/src/editor/format.ts +85 -0
  265. package/src/editor/highlight.ts +110 -0
  266. package/src/editor/hover.ts +199 -0
  267. package/src/editor/index.ts +65 -0
  268. package/src/editor/kinds.ts +157 -0
  269. package/src/editor/layout.ts +189 -0
  270. package/src/editor/manifest.ts +119 -0
  271. package/src/editor/reading.ts +69 -0
  272. package/src/editor/scan.ts +162 -0
  273. package/src/editor/scope.ts +122 -0
  274. package/src/editor/signature.ts +150 -0
  275. package/src/editor/site.ts +233 -0
  276. package/src/editor/spacing.ts +132 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Laying a script out again, as an editor command.
3
+ *
4
+ * `format` is the tier's, and the guarantee it carries is the one that makes a
5
+ * format button safe to put in front of somebody holding a position: laying a
6
+ * script out again cannot change what it computes. Every example and every gate
7
+ * script in the repository is formatted, both texts compiled, and the compiled
8
+ * programs compared field for field; and every call checks itself against the
9
+ * lexer, so a rule that is wrong returns the source untouched rather than a
10
+ * changed program.
11
+ *
12
+ * The whole document is replaced rather than a minimal edit computed. It is the
13
+ * honest version: a diff would have to be trusted to be equivalent to the
14
+ * replacement, and a formatter that moved a line somewhere unintended would do
15
+ * it silently. The cursor is kept where it was in the new text, clamped, because
16
+ * a format that sends the caret to the top of the file is a format nobody
17
+ * presses twice.
18
+ *
19
+ * **A document with two character line endings comes back with one character
20
+ * ones**, because that is what `language.md` 3.1 normalises a file to before
21
+ * anything reads it and what every offset in this tier indexes. It is the one
22
+ * change to a file's bytes that formatting makes without being asked, and it is
23
+ * recorded in `spec/editor-narrowings.json`.
24
+ */
25
+ import { format } from '../../editor/index.js';
26
+ import { documentOf, normalisedOffset } from './positions.js';
27
+ /**
28
+ * Lays the document out again, and says whether anything changed.
29
+ *
30
+ * ```ts
31
+ * keymap.of([{ key: "Shift-Alt-f", run: formatDocument }])
32
+ * ```
33
+ *
34
+ * False where the document is already laid out, which is what an editor command
35
+ * returns when it has nothing to do: the key press then falls through to
36
+ * whatever else is bound to it rather than being swallowed.
37
+ */
38
+ export function formatDocument(view) {
39
+ const raw = view.state.doc.toString();
40
+ const held = documentOf(raw);
41
+ const laid = format(held.text);
42
+ if (laid === raw)
43
+ return false;
44
+ const at = normalisedOffset(held, view.state.selection.main.head);
45
+ view.dispatch({
46
+ changes: { from: 0, to: view.state.doc.length, insert: laid },
47
+ selection: { anchor: Math.min(at, laid.length) },
48
+ scrollIntoView: true,
49
+ });
50
+ return true;
51
+ }
52
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAE/B,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,QAAQ,CAAC;QACZ,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE;QAC7D,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;QAChD,cAAc,EAAE,IAAI;KACrB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { EditorCompletionContext, EditorCompletionResult } from './contract.js';
2
+ /**
3
+ * Every completion for the position the editor is asking about.
4
+ *
5
+ * ```ts
6
+ * autocompletion({ override: [openscriptCompletion] })
7
+ * ```
8
+ *
9
+ * Nothing comes back for an empty list rather than an empty list, because the
10
+ * editor reads the two differently: an empty result closes the panel and null
11
+ * lets another source answer, and a host with a snippet source of its own should
12
+ * keep it.
13
+ */
14
+ export declare function openscriptCompletion(context: EditorCompletionContext): EditorCompletionResult | null;
15
+ //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/completion.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAEV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAmBvB;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,GAAG,IAAI,CAc/B"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Completions, as the editor's completion source.
3
+ *
4
+ * The whole of the work is done by `complete`, which reads the standard library
5
+ * manifest, the checker's bindings and the error catalogue. What is here is the
6
+ * translation: the editor wants a range to replace, a list of rows, and a note
7
+ * about whether the list is already filtered.
8
+ *
9
+ * **The list is already filtered**, by the word the writer has typed, compared
10
+ * exactly, because the language's names are case sensitive. So `filter` is false
11
+ * and the editor is told not to filter it again: its own matcher is fuzzy and
12
+ * case insensitive, and running it over a list that has already answered the
13
+ * question would put `EMA` in front of somebody as though it compiled.
14
+ *
15
+ * **A planned call is shown and marked.** `complete` carries the catalogue's own
16
+ * OS2020 sentence on a planned row, so that is what goes in the row's expanded
17
+ * note, and the row is pushed to the bottom of the list with the editor's own
18
+ * boost. A host that would rather not show them at all drops them with one
19
+ * field, which is why they are marked rather than filtered here.
20
+ */
21
+ import { complete } from '../../editor/index.js';
22
+ import { COMPLETION_TYPES } from './tokens.js';
23
+ /** As far down the list as the editor will move a row. */
24
+ const PLANNED_BOOST = -99;
25
+ function rowOf(one) {
26
+ const info = one.refusal ?? one.summary;
27
+ const type = COMPLETION_TYPES[one.kind];
28
+ return {
29
+ label: one.label,
30
+ ...(type === undefined ? {} : { type }),
31
+ detail: one.detail,
32
+ ...(info === undefined ? {} : { info }),
33
+ ...(one.insert === one.label ? {} : { apply: one.insert }),
34
+ ...(one.planned ? { boost: PLANNED_BOOST } : {}),
35
+ };
36
+ }
37
+ /**
38
+ * Every completion for the position the editor is asking about.
39
+ *
40
+ * ```ts
41
+ * autocompletion({ override: [openscriptCompletion] })
42
+ * ```
43
+ *
44
+ * Nothing comes back for an empty list rather than an empty list, because the
45
+ * editor reads the two differently: an empty result closes the panel and null
46
+ * lets another source answer, and a host with a snippet source of its own should
47
+ * keep it.
48
+ */
49
+ export function openscriptCompletion(context) {
50
+ const rows = complete(context.state.doc.toString(), context.pos);
51
+ // The first row carries the range every row replaces, so an empty list and a
52
+ // list whose first row is missing are one answer: nothing. Two guards for that
53
+ // would be one guard and a line no test can reach.
54
+ const first = rows[0];
55
+ if (first === undefined)
56
+ return null;
57
+ return {
58
+ from: first.replace.offset,
59
+ to: first.replace.offset + first.replace.length,
60
+ options: rows.map(rowOf),
61
+ filter: false,
62
+ };
63
+ }
64
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/completion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAOjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,0DAA0D;AAC1D,MAAM,aAAa,GAAG,CAAC,EAAE,CAAC;AAE1B,SAAS,KAAK,CAAC,GAAe;IAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC;IACxC,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACvC,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACvC,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAgC;IAEhC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,6EAA6E;IAC7E,+EAA+E;IAC/E,mDAAmD;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAErC,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;QAC1B,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM;QAC/C,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QACxB,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The editor component's own shapes, as this adapter targets them.
3
+ *
4
+ * **Why they are declared here rather than imported.** The editor component is a
5
+ * peer dependency: a host that wants a text area installs it, and a host that
6
+ * wants only the language must not be made to. This repository therefore does
7
+ * not install it, cannot type check against it, and would fail its own layering
8
+ * check the moment a file here imported it. It is the same decision the chart
9
+ * adapter took, for the same reason, and `src/adapters/charts/contract.ts` says
10
+ * it at length.
11
+ *
12
+ * So the shapes this produces values for are declared below and the host's own
13
+ * build is where the two meet. Each one is a one line check that costs a host
14
+ * nothing and fails to compile if this file has drifted:
15
+ *
16
+ * ```ts
17
+ * import type { StreamParser } from "<the editor's language package>";
18
+ * import type { CompletionSource } from "<the editor's completion package>";
19
+ * import type { Diagnostic } from "<the editor's lint package>";
20
+ *
21
+ * const parser: StreamParser<unknown> = openscriptStream;
22
+ * const source: CompletionSource = openscriptCompletion;
23
+ * const linter: (view: EditorView) => Diagnostic[] = openscriptLint;
24
+ * ```
25
+ *
26
+ * **That line catches a value of the wrong shape and not an argument of the
27
+ * wrong shape.** A method's parameters are compared in both directions, so a
28
+ * hook declared here as taking something the editor never passes still assigns.
29
+ * That is the failure the chart adapter has actually made, so every member below
30
+ * takes the editor's own argument, spelled as the editor spells it, and every
31
+ * test drives each one with the argument the editor passes rather than with one
32
+ * of its own.
33
+ *
34
+ * **A style name is not checked by any of those lines.** The names this adapter
35
+ * returns from `token` are looked up by the editor in its own table of
36
+ * highlighting tags at run time, and an unknown one is a warning on a console
37
+ * rather than a compile error. That is why the whole mapping is one exported
38
+ * record a host can replace in a line, and why it is recorded in
39
+ * `spec/editor-narrowings.json` as the one thing here a type cannot hold.
40
+ */
41
+ /**
42
+ * One line of the document, as the editor's tokenizer sees it.
43
+ *
44
+ * The editor hands a tokenizer a line at a time and expects `pos` to have moved
45
+ * forward when `token` returns. Only the members this adapter reads are
46
+ * declared: a narrower shape is still assignable from the editor's wider one.
47
+ */
48
+ export interface EditorStringStream {
49
+ /** The line's text, without its line ending. */
50
+ readonly string: string;
51
+ /** Where the tokenizer has got to, which this adapter moves. */
52
+ pos: number;
53
+ /** Where the current token began. */
54
+ readonly start: number;
55
+ /** Whether `pos` is at the end of the line. */
56
+ eol(): boolean;
57
+ /** Whether `pos` is at the start of the line. */
58
+ sol(): boolean;
59
+ }
60
+ /**
61
+ * A tokenizer the editor drives one line at a time.
62
+ *
63
+ * `token` returns a style name, or null for text with no style of its own. The
64
+ * state is the tokenizer's to define, and the editor copies it at line
65
+ * boundaries so that it can restart mid document, which is why `copyState` is
66
+ * here.
67
+ */
68
+ export interface EditorStreamParser<State> {
69
+ readonly name?: string;
70
+ startState?(indentUnit: number): State;
71
+ token(stream: EditorStringStream, state: State): string | null;
72
+ copyState?(state: State): State;
73
+ blankLine?(state: State, indentUnit: number): void;
74
+ readonly languageData?: Readonly<Record<string, unknown>>;
75
+ }
76
+ /** The document, which the editor holds as a rope rather than as a string. */
77
+ export interface EditorText {
78
+ readonly length: number;
79
+ toString(): string;
80
+ }
81
+ /** The part of the editor's state this adapter reads. */
82
+ export interface EditorState {
83
+ readonly doc: EditorText;
84
+ readonly selection: {
85
+ readonly main: {
86
+ readonly head: number;
87
+ readonly from: number;
88
+ readonly to: number;
89
+ };
90
+ };
91
+ }
92
+ /** The part of the editor's view this adapter reads and dispatches to. */
93
+ export interface EditorView {
94
+ readonly state: EditorState;
95
+ dispatch(transaction: {
96
+ readonly changes: {
97
+ readonly from: number;
98
+ readonly to: number;
99
+ readonly insert: string;
100
+ };
101
+ readonly selection?: {
102
+ readonly anchor: number;
103
+ };
104
+ readonly scrollIntoView?: boolean;
105
+ }): void;
106
+ }
107
+ /** What the editor hands a completion source. */
108
+ export interface EditorCompletionContext {
109
+ readonly state: EditorState;
110
+ readonly pos: number;
111
+ /** Whether the writer asked for completions rather than merely typing. */
112
+ readonly explicit: boolean;
113
+ }
114
+ /** One row of the editor's completion list. */
115
+ export interface EditorCompletion {
116
+ readonly label: string;
117
+ /** The editor's own name for the icon beside a row. */
118
+ readonly type?: string;
119
+ readonly detail?: string;
120
+ readonly info?: string;
121
+ /** The text to insert, where it differs from the label. */
122
+ readonly apply?: string;
123
+ /** Moves a row up or down the list, from -99 to 99. */
124
+ readonly boost?: number;
125
+ }
126
+ export interface EditorCompletionResult {
127
+ readonly from: number;
128
+ readonly to?: number;
129
+ readonly options: readonly EditorCompletion[];
130
+ /** False when the list is already filtered, which this adapter's is. */
131
+ readonly filter?: boolean;
132
+ }
133
+ /** One squiggle in the editor's lint panel and gutter. */
134
+ export interface EditorDiagnostic {
135
+ readonly from: number;
136
+ readonly to: number;
137
+ readonly severity: 'hint' | 'info' | 'warning' | 'error';
138
+ readonly message: string;
139
+ /** Where the diagnostic came from, shown beside the message. */
140
+ readonly source?: string;
141
+ readonly actions?: readonly {
142
+ readonly name: string;
143
+ apply(view: EditorView, from: number, to: number): void;
144
+ }[];
145
+ }
146
+ /** What the editor shows over the text, and the element it shows. */
147
+ export interface EditorTooltipView {
148
+ readonly dom: unknown;
149
+ }
150
+ export interface EditorTooltip {
151
+ readonly pos: number;
152
+ readonly end?: number;
153
+ readonly above?: boolean;
154
+ create(view: EditorView): EditorTooltipView;
155
+ }
156
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,GAAG,IAAI,OAAO,CAAC;IACf,iDAAiD;IACjD,GAAG,IAAI,OAAO,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CAAC,KAAK;IACvC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC;IACvC,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IA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ACzD,EAAE,CAAC;CACL;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,CAAC;CAC7C"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The editor component's own shapes, as this adapter targets them.
3
+ *
4
+ * **Why they are declared here rather than imported.** The editor component is a
5
+ * peer dependency: a host that wants a text area installs it, and a host that
6
+ * wants only the language must not be made to. This repository therefore does
7
+ * not install it, cannot type check against it, and would fail its own layering
8
+ * check the moment a file here imported it. It is the same decision the chart
9
+ * adapter took, for the same reason, and `src/adapters/charts/contract.ts` says
10
+ * it at length.
11
+ *
12
+ * So the shapes this produces values for are declared below and the host's own
13
+ * build is where the two meet. Each one is a one line check that costs a host
14
+ * nothing and fails to compile if this file has drifted:
15
+ *
16
+ * ```ts
17
+ * import type { StreamParser } from "<the editor's language package>";
18
+ * import type { CompletionSource } from "<the editor's completion package>";
19
+ * import type { Diagnostic } from "<the editor's lint package>";
20
+ *
21
+ * const parser: StreamParser<unknown> = openscriptStream;
22
+ * const source: CompletionSource = openscriptCompletion;
23
+ * const linter: (view: EditorView) => Diagnostic[] = openscriptLint;
24
+ * ```
25
+ *
26
+ * **That line catches a value of the wrong shape and not an argument of the
27
+ * wrong shape.** A method's parameters are compared in both directions, so a
28
+ * hook declared here as taking something the editor never passes still assigns.
29
+ * That is the failure the chart adapter has actually made, so every member below
30
+ * takes the editor's own argument, spelled as the editor spells it, and every
31
+ * test drives each one with the argument the editor passes rather than with one
32
+ * of its own.
33
+ *
34
+ * **A style name is not checked by any of those lines.** The names this adapter
35
+ * returns from `token` are looked up by the editor in its own table of
36
+ * highlighting tags at run time, and an unknown one is a warning on a console
37
+ * rather than a compile error. That is why the whole mapping is one exported
38
+ * record a host can replace in a line, and why it is recorded in
39
+ * `spec/editor-narrowings.json` as the one thing here a type cannot hold.
40
+ */
41
+ export {};
42
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The editor adapter: the language intelligence, wired into a text component.
3
+ *
4
+ * This and the chart adapter are the only modules in the repository allowed to
5
+ * know two worlds at once, and it is the piece a platform with its own editor
6
+ * replaces rather than the piece it patches. Everything under `src/editor` stays
7
+ * ignorant of any component, and the layering check is what keeps it that way.
8
+ *
9
+ * **The editor component is a peer dependency, and nothing here imports it.** A
10
+ * package that pulled a text component into everyone's install would defeat the
11
+ * point of a language a platform can take on its own, so the shapes this
12
+ * produces are declared in `contract.ts` and the host's own build is where the
13
+ * two are compared, in one line per piece. See that file for the lines. The
14
+ * entry point resolves and every function here runs in an install that holds no
15
+ * editor at all, which `scripts/check-entry-points.mjs` proves on every build.
16
+ *
17
+ * Six functions in, five pieces out:
18
+ *
19
+ * openscriptStream highlighting, a line at a time
20
+ * openscriptCompletion the completion list
21
+ * openscriptLint errors as you type, with their fixes
22
+ * openscriptHoverTooltip what the thing under the pointer is
23
+ * openscriptSignatureTooltip the call being written
24
+ * formatDocument lay the script out again
25
+ *
26
+ * The two tooltips take the markup as a parameter and have no default for it, so
27
+ * nothing in this package names a browser global at any tier. A host that wants
28
+ * none of this calls the six functions itself and draws its own. That is not the fallback, it is the supported path: what a host gives up
29
+ * by taking these instead is recorded in `spec/editor-narrowings.json`, which is
30
+ * three lines long and worth reading before choosing.
31
+ */
32
+ export type { EditorCompletion, EditorCompletionContext, EditorCompletionResult, EditorDiagnostic, EditorState, EditorStreamParser, EditorStringStream, EditorText, EditorTooltip, EditorTooltipView, EditorView, } from './contract.js';
33
+ export { COMPLETION_TYPES, HIGHLIGHT_TOKENS } from './tokens.js';
34
+ export type { StreamState } from './stream.js';
35
+ export { openscriptStream } from './stream.js';
36
+ export { openscriptCompletion } from './completion.js';
37
+ export { diagnosticsFor, openscriptLint } from './lint.js';
38
+ export type { Renderer } from './tooltips.js';
39
+ export { hoverLines, openscriptHoverTooltip, openscriptSignatureTooltip, signatureLines, } from './tooltips.js';
40
+ export { formatDocument } from './commands.js';
41
+ export type { Document } from './positions.js';
42
+ export { documentOf, normalisedOffset } from './positions.js';
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEjE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3D,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { COMPLETION_TYPES, HIGHLIGHT_TOKENS } from './tokens.js';
2
+ export { openscriptStream } from './stream.js';
3
+ export { openscriptCompletion } from './completion.js';
4
+ export { diagnosticsFor, openscriptLint } from './lint.js';
5
+ export { hoverLines, openscriptHoverTooltip, openscriptSignatureTooltip, signatureLines, } from './tooltips.js';
6
+ export { formatDocument } from './commands.js';
7
+ export { documentOf, normalisedOffset } from './positions.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/index.ts"],"names":[],"mappings":"AA6CA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3D,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { EditorDiagnostic, EditorView } from './contract.js';
2
+ /** Every diagnostic of a document, in the editor's own shape. */
3
+ export declare function diagnosticsFor(raw: string): readonly EditorDiagnostic[];
4
+ /**
5
+ * The linter a host wires in one line.
6
+ *
7
+ * ```ts
8
+ * linter(openscriptLint)
9
+ * ```
10
+ *
11
+ * It is synchronous because it is fast enough to be: a finished ninety line
12
+ * study compiles in a third of a millisecond and the same file with a bracket
13
+ * left open in about a millisecond, both with a budget in the benchmark suite.
14
+ * The editor's own linter already debounces, so nothing here does it twice.
15
+ */
16
+ export declare function openscriptLint(view: EditorView): readonly EditorDiagnostic[];
17
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/lint.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQlE,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAavE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,gBAAgB,EAAE,CAE5E"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Errors as you type, as the editor's linter.
3
+ *
4
+ * The diagnostics are the compiler's own, whole: `diagnose` runs the lexer, the
5
+ * parser, the checker and the emitter, so what a writer sees beside their line
6
+ * is exactly what a compile produces and nothing new can appear when they press
7
+ * apply. Every message and every fix came from the error catalogue that the
8
+ * documentation site is generated from.
9
+ *
10
+ * Three decisions worth stating, because each one is visible to a trader.
11
+ *
12
+ * **The fix is shown.** A `Diagnostic` carries a message saying what is wrong and
13
+ * a fix saying what to do, and the fix is the half that is worth reading. The
14
+ * editor's panel shows one string, so the two are joined with a line break
15
+ * rather than the fix being dropped.
16
+ *
17
+ * **The code is the source.** The editor shows a diagnostic's source beside its
18
+ * message, and a code is the one part of a diagnostic this project promises never
19
+ * to change, so it is what a trader quotes and what a support page is indexed by.
20
+ *
21
+ * **A zero width span is widened by one character.** The compiler points at a
22
+ * position for a mistake that is an absence, a missing bracket among them, and a
23
+ * squiggle of no width is a squiggle nobody sees.
24
+ */
25
+ import { endOffset } from '../../core/index.js';
26
+ import { diagnose } from '../../editor/index.js';
27
+ import { documentOf } from './positions.js';
28
+ /** What the editor prints beside a message, which is the code and nothing else. */
29
+ function sourceOf(one) {
30
+ return one.code;
31
+ }
32
+ /** Every diagnostic of a document, in the editor's own shape. */
33
+ export function diagnosticsFor(raw) {
34
+ const held = documentOf(raw);
35
+ return diagnose(held.text).map((one) => {
36
+ const from = held.at(one.span.offset);
37
+ const to = held.at(endOffset(one.span));
38
+ return {
39
+ from,
40
+ to: to > from ? to : from + 1,
41
+ severity: one.severity,
42
+ message: `${one.message}\n${one.fix}`,
43
+ source: sourceOf(one),
44
+ };
45
+ });
46
+ }
47
+ /**
48
+ * The linter a host wires in one line.
49
+ *
50
+ * ```ts
51
+ * linter(openscriptLint)
52
+ * ```
53
+ *
54
+ * It is synchronous because it is fast enough to be: a finished ninety line
55
+ * study compiles in a third of a millisecond and the same file with a bracket
56
+ * left open in about a millisecond, both with a budget in the benchmark suite.
57
+ * The editor's own linter already debounces, so nothing here does it twice.
58
+ */
59
+ export function openscriptLint(view) {
60
+ return diagnosticsFor(view.state.doc.toString());
61
+ }
62
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/lint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,mFAAmF;AACnF,SAAS,QAAQ,CAAC,GAAe;IAC/B,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,OAAO;YACL,IAAI;YACJ,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;YAC7B,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,GAAG,EAAE;YACrC,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC;SACtB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** The document as the compiler reads it, and where each of its offsets sits. */
2
+ export interface Document {
3
+ /** The normalised text: what `diagnose`, `complete` and the rest are given. */
4
+ readonly text: string;
5
+ /**
6
+ * The offset in the editor's own document that a normalised offset names.
7
+ *
8
+ * The identity where the document is already normalised, which is what a
9
+ * document written on a machine that ends its lines with one character is.
10
+ */
11
+ at(offset: number): number;
12
+ }
13
+ export declare function documentOf(raw: string): Document;
14
+ /** The normalised offset an editor offset names, which is the other direction. */
15
+ export declare function normalisedOffset(held: Document, raw: number): number;
16
+ //# sourceMappingURL=positions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/positions.ts"],"names":[],"mappings":"AA0BA,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAwBhD;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAYpE"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Offsets, translated between the document the editor holds and the text the
3
+ * compiler read.
4
+ *
5
+ * `language.md` 3.1 normalises a file before anything reads it: a byte order
6
+ * mark is dropped and every CRLF becomes LF. Every span the compiler produces
7
+ * therefore indexes the normalised text, which `docs/integrating/the-editor-half.md`
8
+ * tells a host plainly and expects it to handle.
9
+ *
10
+ * A drop-in cannot expect it. A document written on a machine that ends its
11
+ * lines with two characters is an ordinary document, the editor holds it exactly
12
+ * as it is, and an adapter that handed the editor a span from the normalised
13
+ * text would put every squiggle on a file's fiftieth line fifty characters to
14
+ * the left. That is the kind of defect that is reported as "the underline is in
15
+ * the wrong place" and survives for months.
16
+ *
17
+ * So the two are mapped. The map is built only when the document is not already
18
+ * normalised, which is the common case and costs a comparison; when it is built
19
+ * it is one walk of the text.
20
+ */
21
+ import { normaliseSource } from '../../core/index.js';
22
+ const BYTE_ORDER_MARK = 0xfeff;
23
+ const CARRIAGE_RETURN = 13;
24
+ const LINE_FEED = 10;
25
+ export function documentOf(raw) {
26
+ const text = normaliseSource(raw);
27
+ if (text === raw)
28
+ return { text, at: (offset) => offset };
29
+ // One entry per normalised offset, plus the one past its end, so that the end
30
+ // of a span at the end of the file maps as readily as its start.
31
+ const map = new Array(text.length + 1);
32
+ let normalised = 0;
33
+ let held = raw.charCodeAt(0) === BYTE_ORDER_MARK ? 1 : 0;
34
+ while (normalised <= text.length) {
35
+ map[normalised] = held;
36
+ if (normalised === text.length)
37
+ break;
38
+ if (raw.charCodeAt(held) === CARRIAGE_RETURN && raw.charCodeAt(held + 1) === LINE_FEED) {
39
+ held += 1;
40
+ }
41
+ held += 1;
42
+ normalised += 1;
43
+ }
44
+ return {
45
+ text,
46
+ at: (offset) => map[Math.min(Math.max(offset, 0), text.length)] ?? offset,
47
+ };
48
+ }
49
+ /** The normalised offset an editor offset names, which is the other direction. */
50
+ export function normalisedOffset(held, raw) {
51
+ // Walked rather than inverted, because the inverse of the map above is only
52
+ // needed at one position per call and building a second array to answer one
53
+ // question would cost a file's length for a comparison's worth of work.
54
+ let low = 0;
55
+ let high = held.text.length;
56
+ while (low < high) {
57
+ const middle = (low + high + 1) >> 1;
58
+ if (held.at(middle) <= raw)
59
+ low = middle;
60
+ else
61
+ high = middle - 1;
62
+ }
63
+ return low;
64
+ }
65
+ //# sourceMappingURL=positions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positions.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/positions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,SAAS,GAAG,EAAE,CAAC;AAerB,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;IAE1D,8EAA8E;IAC9E,iEAAiE;IACjE,MAAM,GAAG,GAAG,IAAI,KAAK,CAAS,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/C,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,CAA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2
+ import type { EditorStreamParser } from './contract.js';
3
+ /** What is carried from one call to the next: the line, and its pieces. */
4
+ export interface StreamState {
5
+ /** The line the pieces were computed from, so a changed line is redone. */
6
+ line: string;
7
+ pieces: readonly Highlight[];
8
+ }
9
+ /**
10
+ * The tokenizer, which a host turns into a language with one call.
11
+ *
12
+ * ```ts
13
+ * const openscript = StreamLanguage.define(openscriptStream);
14
+ * ```
15
+ *
16
+ * `token` moves the stream to the end of the piece that starts where it is and
17
+ * returns that piece's style. A stream that has somehow been left inside a piece,
18
+ * which the editor does when it re-tokenizes from a column rather than from the
19
+ * start of a line, is moved to the end of the piece containing it, so the
20
+ * tokenizer always advances and the editor cannot be made to loop.
21
+ */
22
+ export declare const openscriptStream: EditorStreamParser<StreamState>;
23
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/stream.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,eAAe,CAAC;AAG5E,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;CAC9B;AAWD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,kBAAkB,CAAC,WAAW,CA4B5D,CAAC"}