rapydscript-ns 0.8.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 (144) hide show
  1. package/.agignore +1 -0
  2. package/.gitattributes +4 -0
  3. package/.github/workflows/ci.yml +38 -0
  4. package/.github/workflows/web-repl-page-deploy.yml +42 -0
  5. package/=template.pyj +5 -0
  6. package/CHANGELOG.md +456 -0
  7. package/CONTRIBUTORS +13 -0
  8. package/HACKING.md +103 -0
  9. package/LICENSE +24 -0
  10. package/README.md +2512 -0
  11. package/TODO.md +327 -0
  12. package/add-toc-to-readme +2 -0
  13. package/bin/export +75 -0
  14. package/bin/rapydscript +70 -0
  15. package/bin/web-repl-export +102 -0
  16. package/build +3 -0
  17. package/package.json +46 -0
  18. package/publish.py +37 -0
  19. package/release/baselib-plain-pretty.js +4370 -0
  20. package/release/baselib-plain-ugly.js +3 -0
  21. package/release/compiler.js +18394 -0
  22. package/release/signatures.json +31 -0
  23. package/session.vim +4 -0
  24. package/setup.cfg +2 -0
  25. package/src/ast.pyj +1356 -0
  26. package/src/baselib-builtins.pyj +279 -0
  27. package/src/baselib-containers.pyj +723 -0
  28. package/src/baselib-errors.pyj +37 -0
  29. package/src/baselib-internal.pyj +421 -0
  30. package/src/baselib-itertools.pyj +97 -0
  31. package/src/baselib-str.pyj +798 -0
  32. package/src/compiler.pyj +36 -0
  33. package/src/errors.pyj +30 -0
  34. package/src/lib/aes.pyj +646 -0
  35. package/src/lib/collections.pyj +695 -0
  36. package/src/lib/elementmaker.pyj +83 -0
  37. package/src/lib/encodings.pyj +126 -0
  38. package/src/lib/functools.pyj +148 -0
  39. package/src/lib/gettext.pyj +569 -0
  40. package/src/lib/itertools.pyj +580 -0
  41. package/src/lib/math.pyj +193 -0
  42. package/src/lib/numpy.pyj +2101 -0
  43. package/src/lib/operator.pyj +11 -0
  44. package/src/lib/pythonize.pyj +20 -0
  45. package/src/lib/random.pyj +118 -0
  46. package/src/lib/re.pyj +470 -0
  47. package/src/lib/traceback.pyj +63 -0
  48. package/src/lib/uuid.pyj +77 -0
  49. package/src/monaco-language-service/analyzer.js +526 -0
  50. package/src/monaco-language-service/builtins.js +543 -0
  51. package/src/monaco-language-service/completions.js +498 -0
  52. package/src/monaco-language-service/diagnostics.js +643 -0
  53. package/src/monaco-language-service/dts.js +550 -0
  54. package/src/monaco-language-service/hover.js +121 -0
  55. package/src/monaco-language-service/index.js +386 -0
  56. package/src/monaco-language-service/scope.js +162 -0
  57. package/src/monaco-language-service/signature.js +144 -0
  58. package/src/output/__init__.pyj +0 -0
  59. package/src/output/classes.pyj +296 -0
  60. package/src/output/codegen.pyj +492 -0
  61. package/src/output/comments.pyj +45 -0
  62. package/src/output/exceptions.pyj +105 -0
  63. package/src/output/functions.pyj +491 -0
  64. package/src/output/literals.pyj +109 -0
  65. package/src/output/loops.pyj +444 -0
  66. package/src/output/modules.pyj +329 -0
  67. package/src/output/operators.pyj +429 -0
  68. package/src/output/statements.pyj +463 -0
  69. package/src/output/stream.pyj +309 -0
  70. package/src/output/treeshake.pyj +182 -0
  71. package/src/output/utils.pyj +72 -0
  72. package/src/parse.pyj +3106 -0
  73. package/src/string_interpolation.pyj +72 -0
  74. package/src/tokenizer.pyj +702 -0
  75. package/src/unicode_aliases.pyj +576 -0
  76. package/src/utils.pyj +192 -0
  77. package/test/_import_one.pyj +37 -0
  78. package/test/_import_two/__init__.pyj +11 -0
  79. package/test/_import_two/level2/__init__.pyj +0 -0
  80. package/test/_import_two/level2/deep.pyj +4 -0
  81. package/test/_import_two/other.pyj +6 -0
  82. package/test/_import_two/sub.pyj +13 -0
  83. package/test/aes_vectors.pyj +421 -0
  84. package/test/annotations.pyj +80 -0
  85. package/test/baselib.pyj +319 -0
  86. package/test/classes.pyj +452 -0
  87. package/test/collections.pyj +152 -0
  88. package/test/decorators.pyj +77 -0
  89. package/test/dict_spread.pyj +76 -0
  90. package/test/docstrings.pyj +39 -0
  91. package/test/elementmaker_test.pyj +45 -0
  92. package/test/ellipsis.pyj +49 -0
  93. package/test/functions.pyj +151 -0
  94. package/test/generators.pyj +41 -0
  95. package/test/generic.pyj +370 -0
  96. package/test/imports.pyj +72 -0
  97. package/test/internationalization.pyj +73 -0
  98. package/test/lint.pyj +164 -0
  99. package/test/loops.pyj +85 -0
  100. package/test/numpy.pyj +734 -0
  101. package/test/omit_function_metadata.pyj +20 -0
  102. package/test/regexp.pyj +55 -0
  103. package/test/repl.pyj +121 -0
  104. package/test/scoped_flags.pyj +76 -0
  105. package/test/starargs.pyj +506 -0
  106. package/test/starred_assign.pyj +104 -0
  107. package/test/str.pyj +198 -0
  108. package/test/subscript_tuple.pyj +53 -0
  109. package/test/unit/fixtures/fibonacci_expected.js +46 -0
  110. package/test/unit/index.js +2989 -0
  111. package/test/unit/language-service-builtins.js +815 -0
  112. package/test/unit/language-service-completions.js +1067 -0
  113. package/test/unit/language-service-dts.js +543 -0
  114. package/test/unit/language-service-hover.js +455 -0
  115. package/test/unit/language-service-scope.js +833 -0
  116. package/test/unit/language-service-signature.js +458 -0
  117. package/test/unit/language-service.js +705 -0
  118. package/test/unit/run-language-service.js +41 -0
  119. package/test/unit/web-repl.js +484 -0
  120. package/tools/build-language-service.js +190 -0
  121. package/tools/cli.js +547 -0
  122. package/tools/compile.js +219 -0
  123. package/tools/compiler.js +108 -0
  124. package/tools/completer.js +131 -0
  125. package/tools/embedded_compiler.js +251 -0
  126. package/tools/export.js +316 -0
  127. package/tools/gettext.js +185 -0
  128. package/tools/ini.js +65 -0
  129. package/tools/lint.js +705 -0
  130. package/tools/msgfmt.js +187 -0
  131. package/tools/repl.js +223 -0
  132. package/tools/self.js +162 -0
  133. package/tools/test.js +118 -0
  134. package/tools/utils.js +128 -0
  135. package/tools/web_repl.js +95 -0
  136. package/try +41 -0
  137. package/web-repl/env.js +74 -0
  138. package/web-repl/index.html +163 -0
  139. package/web-repl/language-service.js +4084 -0
  140. package/web-repl/main.js +254 -0
  141. package/web-repl/prism.css +139 -0
  142. package/web-repl/prism.js +113 -0
  143. package/web-repl/rapydscript.js +435 -0
  144. package/web-repl/sha1.js +25 -0
@@ -0,0 +1,458 @@
1
+ /*
2
+ * test/unit/language-service-signature.js
3
+ *
4
+ * Unit tests for src/monaco-language-service/signature.js (Phase 4).
5
+ *
6
+ * Usage:
7
+ * node test/unit/language-service-signature.js # run all tests
8
+ * node test/unit/language-service-signature.js <test-name> # run a single test by name
9
+ */
10
+ "use strict";
11
+
12
+ var assert = require("assert");
13
+ var path = require("path");
14
+ var url = require("url");
15
+ var compiler_module = require("../../tools/compiler");
16
+ var utils = require("../../tools/utils");
17
+ var colored = utils.safe_colored;
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Helpers
21
+ // ---------------------------------------------------------------------------
22
+
23
+ function pos(line, col) { return { lineNumber: line, column: col }; }
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Test definitions
27
+ // ---------------------------------------------------------------------------
28
+
29
+ function make_tests(SignatureHelpEngine, detect_call_context, SourceAnalyzer, RS) {
30
+
31
+ function make_engine() {
32
+ return new SignatureHelpEngine();
33
+ }
34
+
35
+ function analyze(src) {
36
+ var analyzer = new SourceAnalyzer(RS);
37
+ return analyzer.analyze(src, {});
38
+ }
39
+
40
+ var TESTS = [
41
+
42
+ // ── detect_call_context ───────────────────────────────────────────
43
+
44
+ {
45
+ name: "ctx_simple_call",
46
+ description: "detect_call_context finds callee and param 0 for 'func('",
47
+ run: function () {
48
+ var ctx = detect_call_context("func(");
49
+ assert.ok(ctx, "should return a context");
50
+ assert.strictEqual(ctx.callee, "func");
51
+ assert.strictEqual(ctx.activeParameter, 0);
52
+ },
53
+ },
54
+
55
+ {
56
+ name: "ctx_second_param",
57
+ description: "detect_call_context returns activeParameter 1 after first comma",
58
+ run: function () {
59
+ var ctx = detect_call_context("func(a, ");
60
+ assert.ok(ctx, "should return context");
61
+ assert.strictEqual(ctx.callee, "func");
62
+ assert.strictEqual(ctx.activeParameter, 1);
63
+ },
64
+ },
65
+
66
+ {
67
+ name: "ctx_third_param",
68
+ description: "detect_call_context returns activeParameter 2 after two commas",
69
+ run: function () {
70
+ var ctx = detect_call_context("func(a, b, ");
71
+ assert.ok(ctx, "should return context");
72
+ assert.strictEqual(ctx.activeParameter, 2);
73
+ },
74
+ },
75
+
76
+ {
77
+ name: "ctx_nested_call_ignored",
78
+ description: "Commas inside nested calls don't count as argument separators",
79
+ run: function () {
80
+ // outer(inner(x, y), <cursor> — outer's second arg
81
+ var ctx = detect_call_context("outer(inner(x, y), ");
82
+ assert.ok(ctx, "should return context");
83
+ assert.strictEqual(ctx.callee, "outer");
84
+ assert.strictEqual(ctx.activeParameter, 1);
85
+ },
86
+ },
87
+
88
+ {
89
+ name: "ctx_not_in_call",
90
+ description: "detect_call_context returns null when not inside a call",
91
+ run: function () {
92
+ var ctx = detect_call_context("x = 1");
93
+ assert.strictEqual(ctx, null, "should return null");
94
+ },
95
+ },
96
+
97
+ {
98
+ name: "ctx_closed_paren",
99
+ description: "detect_call_context returns null when all parens are closed",
100
+ run: function () {
101
+ var ctx = detect_call_context("func(a, b)");
102
+ assert.strictEqual(ctx, null, "should return null — paren is closed");
103
+ },
104
+ },
105
+
106
+ {
107
+ name: "ctx_method_call",
108
+ description: "detect_call_context handles obj.method( prefix",
109
+ run: function () {
110
+ var ctx = detect_call_context("obj.method(");
111
+ assert.ok(ctx, "should return context");
112
+ assert.strictEqual(ctx.callee, "method");
113
+ assert.strictEqual(ctx.activeParameter, 0);
114
+ },
115
+ },
116
+
117
+ {
118
+ name: "ctx_nested_bracket",
119
+ description: "Commas inside [] don't count as argument separators",
120
+ run: function () {
121
+ // func([1, 2, 3], <cursor>
122
+ var ctx = detect_call_context("func([1, 2, 3], ");
123
+ assert.ok(ctx, "should return context");
124
+ assert.strictEqual(ctx.callee, "func");
125
+ assert.strictEqual(ctx.activeParameter, 1);
126
+ },
127
+ },
128
+
129
+ // ── SignatureHelpEngine.getSignatureHelp ──────────────────────────
130
+
131
+ // NOTE: The scopeMap is built from clean, parseable source.
132
+ // The linePrefix (e.g. "greet(") is passed separately and does NOT need
133
+ // to match what is literally on that line of the source.
134
+ // We query at col 1 of the last "pass" line so the position is safely
135
+ // inside the module scope range.
136
+
137
+ {
138
+ name: "help_basic",
139
+ description: "getSignatureHelp returns signature for a known function",
140
+ run: function () {
141
+ var engine = make_engine();
142
+ var scopeMap = analyze([
143
+ "def greet(name, age):",
144
+ " return name",
145
+ "x = greet(1, 2)",
146
+ "pass",
147
+ ].join("\n"));
148
+
149
+ // Simulate cursor inside "greet(" at line 4 col 1
150
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "greet(");
151
+ assert.ok(help, "expected signature help");
152
+ assert.strictEqual(help.value.signatures.length, 1);
153
+ assert.ok(help.value.signatures[0].label.indexOf("name") !== -1, "label includes 'name'");
154
+ assert.ok(help.value.signatures[0].label.indexOf("age") !== -1, "label includes 'age'");
155
+ assert.strictEqual(help.value.activeParameter, 0);
156
+ assert.strictEqual(help.value.activeSignature, 0);
157
+ },
158
+ },
159
+
160
+ {
161
+ name: "help_second_param",
162
+ description: "getSignatureHelp highlights the second parameter after a comma",
163
+ run: function () {
164
+ var engine = make_engine();
165
+ var scopeMap = analyze([
166
+ "def greet(name, age):",
167
+ " return name",
168
+ "x = greet(1, 2)",
169
+ "pass",
170
+ ].join("\n"));
171
+
172
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "greet(x, ");
173
+ assert.ok(help, "expected signature help");
174
+ assert.strictEqual(help.value.activeParameter, 1);
175
+ },
176
+ },
177
+
178
+ {
179
+ name: "help_star_args",
180
+ description: "getSignatureHelp includes *args in signature label",
181
+ run: function () {
182
+ var engine = make_engine();
183
+ var scopeMap = analyze([
184
+ "def variadic(first, *rest):",
185
+ " return first",
186
+ "x = variadic(1)",
187
+ "pass",
188
+ ].join("\n"));
189
+
190
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "variadic(");
191
+ assert.ok(help, "expected signature help");
192
+ assert.ok(help.value.signatures[0].label.indexOf("*rest") !== -1,
193
+ "label should include *rest");
194
+ },
195
+ },
196
+
197
+ {
198
+ name: "help_kwargs",
199
+ description: "getSignatureHelp includes **kwargs in signature label",
200
+ run: function () {
201
+ var engine = make_engine();
202
+ var scopeMap = analyze([
203
+ "def configure(host, **opts):",
204
+ " return host",
205
+ "x = configure('localhost')",
206
+ "pass",
207
+ ].join("\n"));
208
+
209
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "configure(");
210
+ assert.ok(help, "expected signature help");
211
+ assert.ok(help.value.signatures[0].label.indexOf("**opts") !== -1,
212
+ "label should include **opts");
213
+ },
214
+ },
215
+
216
+ {
217
+ name: "help_param_objects",
218
+ description: "getSignatureHelp includes parameter objects matching the label",
219
+ run: function () {
220
+ var engine = make_engine();
221
+ var scopeMap = analyze([
222
+ "def add(x, y):",
223
+ " return x + y",
224
+ "z = add(1, 2)",
225
+ "pass",
226
+ ].join("\n"));
227
+
228
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "add(");
229
+ assert.ok(help, "expected signature help");
230
+ var params = help.value.signatures[0].parameters;
231
+ assert.strictEqual(params.length, 2, "should have 2 parameter objects");
232
+ assert.strictEqual(params[0].label, "x", "first param label");
233
+ assert.strictEqual(params[1].label, "y", "second param label");
234
+ },
235
+ },
236
+
237
+ {
238
+ name: "help_unknown_function",
239
+ description: "getSignatureHelp returns null for an unknown function",
240
+ run: function () {
241
+ var engine = make_engine();
242
+ var scopeMap = analyze("x = 1\npass");
243
+
244
+ var help = engine.getSignatureHelp(scopeMap, pos(2, 1), "unknown_func(");
245
+ assert.strictEqual(help, null, "unknown function → null");
246
+ },
247
+ },
248
+
249
+ {
250
+ name: "help_no_params",
251
+ description: "getSignatureHelp returns null for a function with no params",
252
+ run: function () {
253
+ var engine = make_engine();
254
+ var scopeMap = analyze([
255
+ "def noop():",
256
+ " pass",
257
+ "noop()",
258
+ "pass",
259
+ ].join("\n"));
260
+
261
+ // Query at line 4 col 1
262
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "noop(");
263
+ assert.strictEqual(help, null, "no-param function → null (nothing to show)");
264
+ },
265
+ },
266
+
267
+ {
268
+ name: "help_null_scopemap",
269
+ description: "getSignatureHelp returns null when scopeMap is null",
270
+ run: function () {
271
+ var engine = make_engine();
272
+ var help = engine.getSignatureHelp(null, pos(1, 5), "func(");
273
+ assert.strictEqual(help, null, "null scopeMap → null");
274
+ },
275
+ },
276
+
277
+ {
278
+ name: "help_not_in_call",
279
+ description: "getSignatureHelp returns null when cursor is not inside a call",
280
+ run: function () {
281
+ var engine = make_engine();
282
+ var scopeMap = analyze("x = 1\npass");
283
+
284
+ var help = engine.getSignatureHelp(scopeMap, pos(2, 1), "x = 1");
285
+ assert.strictEqual(help, null, "not in call → null");
286
+ },
287
+ },
288
+
289
+ {
290
+ name: "help_clamp_active_param",
291
+ description: "activeParameter is clamped to last param index when cursor is past all params",
292
+ run: function () {
293
+ var engine = make_engine();
294
+ var scopeMap = analyze([
295
+ "def two(a, b):",
296
+ " return a",
297
+ "z = two(1, 2)",
298
+ "pass",
299
+ ].join("\n"));
300
+
301
+ // Simulate cursor at a third arg slot, but function only has 2 params
302
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "two(x, y, ");
303
+ assert.ok(help, "expected signature help even past last param");
304
+ assert.strictEqual(help.value.activeParameter, 1,
305
+ "should clamp to last param index (1)");
306
+ },
307
+ },
308
+
309
+ {
310
+ name: "help_posonly_separator",
311
+ description: "Signature label includes '/' for positional-only parameters",
312
+ run: function () {
313
+ var engine = make_engine();
314
+ var scopeMap = analyze([
315
+ "def f(a, b, /, c):",
316
+ " return a",
317
+ "z = f(1, 2, 3)",
318
+ "pass",
319
+ ].join("\n"));
320
+
321
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "f(");
322
+ assert.ok(help, "expected signature help");
323
+ var label = help.value.signatures[0].label;
324
+ assert.ok(label.indexOf("/") !== -1, "label should contain '/'");
325
+ assert.ok(label.indexOf("a") !== -1, "label should contain 'a'");
326
+ assert.ok(label.indexOf("c") !== -1, "label should contain 'c'");
327
+ },
328
+ },
329
+
330
+ {
331
+ name: "help_kwonly_separator",
332
+ description: "Signature label includes '*' bare separator for keyword-only parameters",
333
+ run: function () {
334
+ var engine = make_engine();
335
+ var scopeMap = analyze([
336
+ "def g(a, *, b, c=1):",
337
+ " return a",
338
+ "z = g(1, b=2)",
339
+ "pass",
340
+ ].join("\n"));
341
+
342
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "g(");
343
+ assert.ok(help, "expected signature help");
344
+ var label = help.value.signatures[0].label;
345
+ assert.ok(label.indexOf("*") !== -1, "label should contain '*' separator");
346
+ assert.ok(label.indexOf("b") !== -1, "label should contain 'b'");
347
+ },
348
+ },
349
+
350
+ {
351
+ name: "help_posonly_and_kwonly",
352
+ description: "Signature label shows both '/' and '*' separators",
353
+ run: function () {
354
+ var engine = make_engine();
355
+ var scopeMap = analyze([
356
+ "def h(a, /, b, *, c):",
357
+ " return a",
358
+ "z = h(1, 2, c=3)",
359
+ "pass",
360
+ ].join("\n"));
361
+
362
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "h(");
363
+ assert.ok(help, "expected signature help");
364
+ var label = help.value.signatures[0].label;
365
+ assert.ok(label.indexOf("/") !== -1, "label should contain '/'");
366
+ assert.ok(label.indexOf("*") !== -1, "label should contain '*'");
367
+ },
368
+ },
369
+
370
+ {
371
+ name: "help_dispose_is_function",
372
+ description: "Returned help object has a dispose() function",
373
+ run: function () {
374
+ var engine = make_engine();
375
+ var scopeMap = analyze([
376
+ "def f(a):",
377
+ " return a",
378
+ "z = f(1)",
379
+ "pass",
380
+ ].join("\n"));
381
+
382
+ var help = engine.getSignatureHelp(scopeMap, pos(4, 1), "f(");
383
+ assert.ok(help, "expected help");
384
+ assert.strictEqual(typeof help.dispose, "function", "dispose should be a function");
385
+ },
386
+ },
387
+
388
+ ];
389
+
390
+ return TESTS;
391
+ }
392
+
393
+ // ---------------------------------------------------------------------------
394
+ // Runner
395
+ // ---------------------------------------------------------------------------
396
+
397
+ function run_tests(TESTS, filter) {
398
+ var tests = filter
399
+ ? TESTS.filter(function (t) { return t.name === filter; })
400
+ : TESTS;
401
+
402
+ if (tests.length === 0) {
403
+ console.error(colored("No test found: " + filter, "red"));
404
+ process.exit(1);
405
+ }
406
+
407
+ var failures = [];
408
+
409
+ tests.forEach(function (test) {
410
+ try {
411
+ test.run();
412
+ console.log(colored("PASS " + test.name, "green") +
413
+ " – " + test.description);
414
+ } catch (e) {
415
+ failures.push(test.name);
416
+ var msg = e.message || String(e);
417
+ console.log(colored("FAIL " + test.name, "red") +
418
+ "\n " + msg + "\n");
419
+ }
420
+ });
421
+
422
+ console.log("");
423
+ if (failures.length) {
424
+ console.log(colored(failures.length + " test(s) failed.", "red"));
425
+ } else {
426
+ console.log(colored("All " + tests.length + " language-service-signature tests passed!", "green"));
427
+ }
428
+ process.exit(failures.length ? 1 : 0);
429
+ }
430
+
431
+ // ---------------------------------------------------------------------------
432
+ // Entry point
433
+ // ---------------------------------------------------------------------------
434
+
435
+ var signature_path = url.pathToFileURL(
436
+ path.join(__dirname, "../../src/monaco-language-service/signature.js")
437
+ ).href;
438
+
439
+ var analyzer_path = url.pathToFileURL(
440
+ path.join(__dirname, "../../src/monaco-language-service/analyzer.js")
441
+ ).href;
442
+
443
+ var filter = process.argv[2] || null;
444
+
445
+ Promise.all([
446
+ import(signature_path),
447
+ import(analyzer_path),
448
+ ]).then(function (mods) {
449
+ var SignatureHelpEngine = mods[0].SignatureHelpEngine;
450
+ var detect_call_context = mods[0].detect_call_context;
451
+ var SourceAnalyzer = mods[1].SourceAnalyzer;
452
+ var RS = compiler_module.create_compiler();
453
+ var TESTS = make_tests(SignatureHelpEngine, detect_call_context, SourceAnalyzer, RS);
454
+ run_tests(TESTS, filter);
455
+ }).catch(function (e) {
456
+ console.error(colored("Failed to load signature module:", "red"), e);
457
+ process.exit(1);
458
+ });