@fairyhunter13/opentui-core 0.1.91 → 0.1.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d/SpriteResourceManager.d.ts +74 -0
- package/3d/SpriteUtils.d.ts +13 -0
- package/3d/TextureUtils.d.ts +24 -0
- package/3d/ThreeRenderable.d.ts +40 -0
- package/3d/WGPURenderer.d.ts +61 -0
- package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
- package/3d/animation/SpriteAnimator.d.ts +124 -0
- package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
- package/3d/canvas.d.ts +44 -0
- package/3d/index.d.ts +12 -0
- package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
- package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
- package/3d/physics/physics-interface.d.ts +27 -0
- package/3d.d.ts +2 -0
- package/3d.js +34042 -0
- package/3d.js.map +155 -0
- package/LICENSE +21 -0
- package/NativeSpanFeed.d.ts +41 -0
- package/Renderable.d.ts +334 -0
- package/animation/Timeline.d.ts +126 -0
- package/ansi.d.ts +13 -0
- package/buffer.d.ts +107 -0
- package/console.d.ts +143 -0
- package/edit-buffer.d.ts +98 -0
- package/editor-view.d.ts +73 -0
- package/index-e6ec7apq.js +18415 -0
- package/index-e6ec7apq.js.map +64 -0
- package/index-h066zmrb.js +12619 -0
- package/index-h066zmrb.js.map +43 -0
- package/index-ynzawt3n.js +113 -0
- package/index-ynzawt3n.js.map +10 -0
- package/index.d.ts +21 -0
- package/index.js +430 -0
- package/index.js.map +9 -0
- package/lib/KeyHandler.d.ts +61 -0
- package/lib/RGBA.d.ts +25 -0
- package/lib/ascii.font.d.ts +508 -0
- package/lib/border.d.ts +49 -0
- package/lib/bunfs.d.ts +7 -0
- package/lib/clipboard.d.ts +17 -0
- package/lib/clock.d.ts +15 -0
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/detect-links.d.ts +6 -0
- package/lib/env.d.ts +42 -0
- package/lib/extmarks-history.d.ts +17 -0
- package/lib/extmarks.d.ts +89 -0
- package/lib/hast-styled-text.d.ts +17 -0
- package/lib/index.d.ts +21 -0
- package/lib/keymapping.d.ts +25 -0
- package/lib/objects-in-viewport.d.ts +24 -0
- package/lib/output.capture.d.ts +24 -0
- package/lib/parse.keypress-kitty.d.ts +2 -0
- package/lib/parse.keypress.d.ts +26 -0
- package/lib/parse.mouse.d.ts +30 -0
- package/lib/paste.d.ts +7 -0
- package/lib/queue.d.ts +15 -0
- package/lib/renderable.validations.d.ts +12 -0
- package/lib/scroll-acceleration.d.ts +43 -0
- package/lib/selection.d.ts +63 -0
- package/lib/singleton.d.ts +7 -0
- package/lib/stdin-parser.d.ts +76 -0
- package/lib/styled-text.d.ts +63 -0
- package/lib/terminal-capability-detection.d.ts +30 -0
- package/lib/terminal-palette.d.ts +50 -0
- package/lib/tree-sitter/assets/update.d.ts +11 -0
- package/lib/tree-sitter/client.d.ts +47 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +8 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/parsers-config.d.ts +38 -0
- package/lib/tree-sitter/resolve-ft.d.ts +2 -0
- package/lib/tree-sitter/types.d.ts +81 -0
- package/lib/tree-sitter-styled-text.d.ts +14 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/lib/yoga.options.d.ts +32 -0
- package/package.json +51 -63
- package/parser.worker.js +869 -0
- package/parser.worker.js.map +12 -0
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +38 -0
- package/plugins/types.d.ts +34 -0
- package/post/filters.d.ts +105 -0
- package/renderables/ASCIIFont.d.ts +52 -0
- package/renderables/Box.d.ts +72 -0
- package/renderables/Code.d.ts +78 -0
- package/renderables/Diff.d.ts +142 -0
- package/renderables/EditBufferRenderable.d.ts +162 -0
- package/renderables/FrameBuffer.d.ts +16 -0
- package/renderables/Input.d.ts +67 -0
- package/renderables/LineNumberRenderable.d.ts +74 -0
- package/renderables/Markdown.d.ts +173 -0
- package/renderables/ScrollBar.d.ts +77 -0
- package/renderables/ScrollBox.d.ts +124 -0
- package/renderables/Select.d.ts +115 -0
- package/renderables/Slider.d.ts +44 -0
- package/renderables/TabSelect.d.ts +96 -0
- package/renderables/Text.d.ts +36 -0
- package/renderables/TextBufferRenderable.d.ts +105 -0
- package/renderables/TextNode.d.ts +91 -0
- package/renderables/TextTable.d.ts +140 -0
- package/renderables/Textarea.d.ts +114 -0
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
- package/renderables/composition/VRenderable.d.ts +16 -0
- package/renderables/composition/constructs.d.ts +35 -0
- package/renderables/composition/vnode.d.ts +46 -0
- package/renderables/index.d.ts +22 -0
- package/renderables/markdown-parser.d.ts +10 -0
- package/renderer.d.ts +388 -0
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +29 -0
- package/runtime-plugin-support.js.map +10 -0
- package/runtime-plugin.d.ts +11 -0
- package/runtime-plugin.js +16 -0
- package/runtime-plugin.js.map +9 -0
- package/syntax-style.d.ts +54 -0
- package/testing/manual-clock.d.ts +16 -0
- package/testing/mock-keys.d.ts +81 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/mock-tree-sitter-client.d.ts +23 -0
- package/testing/spy.d.ts +7 -0
- package/testing/test-recorder.d.ts +61 -0
- package/testing/test-renderer.d.ts +23 -0
- package/testing.d.ts +6 -0
- package/testing.js +675 -0
- package/testing.js.map +15 -0
- package/text-buffer-view.d.ts +42 -0
- package/text-buffer.d.ts +67 -0
- package/types.d.ts +131 -0
- package/utils.d.ts +14 -0
- package/zig-structs.d.ts +155 -0
- package/zig.d.ts +351 -0
- package/dev/keypress-debug-renderer.ts +0 -148
- package/dev/keypress-debug.ts +0 -43
- package/dev/print-env-vars.ts +0 -32
- package/dev/test-tmux-graphics-334.sh +0 -68
- package/dev/thai-debug-test.ts +0 -68
- package/docs/development.md +0 -141
- package/docs/env-vars.md +0 -140
- package/docs/getting-started.md +0 -353
- package/docs/renderables-vs-constructs.md +0 -159
- package/docs/tree-sitter.md +0 -311
- package/scripts/build.ts +0 -400
- package/scripts/publish.ts +0 -60
- package/src/3d/SpriteResourceManager.ts +0 -286
- package/src/3d/SpriteUtils.ts +0 -71
- package/src/3d/TextureUtils.ts +0 -196
- package/src/3d/ThreeRenderable.ts +0 -197
- package/src/3d/WGPURenderer.ts +0 -294
- package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
- package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
- package/src/3d/animation/SpriteAnimator.ts +0 -633
- package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
- package/src/3d/canvas.ts +0 -464
- package/src/3d/index.ts +0 -12
- package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
- package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
- package/src/3d/physics/physics-interface.ts +0 -31
- package/src/3d/shaders/supersampling.wgsl +0 -201
- package/src/3d.ts +0 -3
- package/src/NativeSpanFeed.ts +0 -300
- package/src/Renderable.ts +0 -1698
- package/src/__snapshots__/buffer.test.ts.snap +0 -28
- package/src/animation/Timeline.test.ts +0 -2709
- package/src/animation/Timeline.ts +0 -598
- package/src/ansi.ts +0 -18
- package/src/benchmark/latest-all-bench-run.json +0 -707
- package/src/benchmark/latest-async-bench-run.json +0 -336
- package/src/benchmark/latest-default-bench-run.json +0 -657
- package/src/benchmark/latest-large-bench-run.json +0 -707
- package/src/benchmark/latest-quick-bench-run.json +0 -207
- package/src/benchmark/markdown-benchmark.ts +0 -1804
- package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
- package/src/benchmark/native-span-feed-benchmark.md +0 -56
- package/src/benchmark/native-span-feed-benchmark.ts +0 -596
- package/src/benchmark/native-span-feed-compare.ts +0 -280
- package/src/benchmark/renderer-benchmark.ts +0 -754
- package/src/benchmark/text-table-benchmark.ts +0 -947
- package/src/buffer.test.ts +0 -291
- package/src/buffer.ts +0 -519
- package/src/console.test.ts +0 -612
- package/src/console.ts +0 -1255
- package/src/edit-buffer.test.ts +0 -1769
- package/src/edit-buffer.ts +0 -411
- package/src/editor-view.test.ts +0 -1032
- package/src/editor-view.ts +0 -284
- package/src/examples/ascii-font-selection-demo.ts +0 -245
- package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
- package/src/examples/assets/concrete.png +0 -0
- package/src/examples/assets/crate.png +0 -0
- package/src/examples/assets/crate_emissive.png +0 -0
- package/src/examples/assets/forrest_background.png +0 -0
- package/src/examples/assets/hast-example.json +0 -1018
- package/src/examples/assets/heart.png +0 -0
- package/src/examples/assets/main_char_heavy_attack.png +0 -0
- package/src/examples/assets/main_char_idle.png +0 -0
- package/src/examples/assets/main_char_jump_end.png +0 -0
- package/src/examples/assets/main_char_jump_landing.png +0 -0
- package/src/examples/assets/main_char_jump_start.png +0 -0
- package/src/examples/assets/main_char_run_loop.png +0 -0
- package/src/examples/assets/roughness_map.jpg +0 -0
- package/src/examples/build.ts +0 -115
- package/src/examples/code-demo.ts +0 -584
- package/src/examples/console-demo.ts +0 -358
- package/src/examples/core-plugin-slots-demo.ts +0 -759
- package/src/examples/diff-demo.ts +0 -699
- package/src/examples/draggable-three-demo.ts +0 -259
- package/src/examples/editor-demo.ts +0 -322
- package/src/examples/extmarks-demo.ts +0 -204
- package/src/examples/focus-restore-demo.ts +0 -310
- package/src/examples/fonts.ts +0 -245
- package/src/examples/fractal-shader-demo.ts +0 -268
- package/src/examples/framebuffer-demo.ts +0 -674
- package/src/examples/full-unicode-demo.ts +0 -181
- package/src/examples/golden-star-demo.ts +0 -933
- package/src/examples/grayscale-buffer-demo.ts +0 -249
- package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
- package/src/examples/index.ts +0 -925
- package/src/examples/input-demo.ts +0 -377
- package/src/examples/input-select-layout-demo.ts +0 -425
- package/src/examples/install.sh +0 -143
- package/src/examples/keypress-debug-demo.ts +0 -452
- package/src/examples/lib/HexList.ts +0 -122
- package/src/examples/lib/PaletteGrid.ts +0 -125
- package/src/examples/lib/standalone-keys.ts +0 -25
- package/src/examples/lib/tab-controller.ts +0 -243
- package/src/examples/lights-phong-demo.ts +0 -290
- package/src/examples/link-demo.ts +0 -220
- package/src/examples/live-state-demo.ts +0 -480
- package/src/examples/markdown-demo.ts +0 -620
- package/src/examples/mouse-interaction-demo.ts +0 -428
- package/src/examples/nested-zindex-demo.ts +0 -357
- package/src/examples/opacity-example.ts +0 -235
- package/src/examples/opentui-demo.ts +0 -1057
- package/src/examples/physx-planck-2d-demo.ts +0 -507
- package/src/examples/physx-rapier-2d-demo.ts +0 -526
- package/src/examples/relative-positioning-demo.ts +0 -323
- package/src/examples/scroll-example.ts +0 -214
- package/src/examples/scrollbox-mouse-test.ts +0 -112
- package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
- package/src/examples/select-demo.ts +0 -237
- package/src/examples/shader-cube-demo.ts +0 -772
- package/src/examples/simple-layout-example.ts +0 -591
- package/src/examples/slider-demo.ts +0 -617
- package/src/examples/split-mode-demo.ts +0 -445
- package/src/examples/sprite-animation-demo.ts +0 -443
- package/src/examples/sprite-particle-generator-demo.ts +0 -486
- package/src/examples/static-sprite-demo.ts +0 -193
- package/src/examples/sticky-scroll-example.ts +0 -308
- package/src/examples/styled-text-demo.ts +0 -282
- package/src/examples/tab-select-demo.ts +0 -219
- package/src/examples/terminal-title.ts +0 -29
- package/src/examples/terminal.ts +0 -305
- package/src/examples/text-node-demo.ts +0 -416
- package/src/examples/text-selection-demo.ts +0 -377
- package/src/examples/text-table-demo.ts +0 -503
- package/src/examples/text-truncation-demo.ts +0 -481
- package/src/examples/text-wrap.ts +0 -757
- package/src/examples/texture-loading-demo.ts +0 -259
- package/src/examples/timeline-example.ts +0 -670
- package/src/examples/transparency-demo.ts +0 -241
- package/src/examples/vnode-composition-demo.ts +0 -404
- package/src/index.ts +0 -22
- package/src/lib/KeyHandler.integration.test.ts +0 -292
- package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
- package/src/lib/KeyHandler.test.ts +0 -662
- package/src/lib/KeyHandler.ts +0 -222
- package/src/lib/RGBA.test.ts +0 -984
- package/src/lib/RGBA.ts +0 -204
- package/src/lib/ascii.font.ts +0 -330
- package/src/lib/border.test.ts +0 -83
- package/src/lib/border.ts +0 -168
- package/src/lib/bunfs.test.ts +0 -27
- package/src/lib/bunfs.ts +0 -18
- package/src/lib/clipboard.test.ts +0 -41
- package/src/lib/clipboard.ts +0 -47
- package/src/lib/clock.ts +0 -31
- package/src/lib/data-paths.test.ts +0 -133
- package/src/lib/data-paths.ts +0 -109
- package/src/lib/debounce.ts +0 -106
- package/src/lib/detect-links.test.ts +0 -98
- package/src/lib/detect-links.ts +0 -56
- package/src/lib/env.test.ts +0 -228
- package/src/lib/env.ts +0 -209
- package/src/lib/extmarks-history.ts +0 -51
- package/src/lib/extmarks-multiwidth.test.ts +0 -322
- package/src/lib/extmarks.test.ts +0 -3457
- package/src/lib/extmarks.ts +0 -843
- package/src/lib/fonts/block.json +0 -405
- package/src/lib/fonts/grid.json +0 -265
- package/src/lib/fonts/huge.json +0 -741
- package/src/lib/fonts/pallet.json +0 -314
- package/src/lib/fonts/shade.json +0 -591
- package/src/lib/fonts/slick.json +0 -321
- package/src/lib/fonts/tiny.json +0 -69
- package/src/lib/hast-styled-text.ts +0 -59
- package/src/lib/index.ts +0 -21
- package/src/lib/keymapping.test.ts +0 -280
- package/src/lib/keymapping.ts +0 -87
- package/src/lib/objects-in-viewport.test.ts +0 -787
- package/src/lib/objects-in-viewport.ts +0 -153
- package/src/lib/output.capture.ts +0 -58
- package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
- package/src/lib/parse.keypress-kitty.test.ts +0 -663
- package/src/lib/parse.keypress-kitty.ts +0 -439
- package/src/lib/parse.keypress.test.ts +0 -1849
- package/src/lib/parse.keypress.ts +0 -397
- package/src/lib/parse.mouse.test.ts +0 -552
- package/src/lib/parse.mouse.ts +0 -232
- package/src/lib/paste.ts +0 -16
- package/src/lib/queue.ts +0 -65
- package/src/lib/renderable.validations.test.ts +0 -87
- package/src/lib/renderable.validations.ts +0 -83
- package/src/lib/scroll-acceleration.ts +0 -98
- package/src/lib/selection.ts +0 -240
- package/src/lib/singleton.ts +0 -28
- package/src/lib/stdin-parser.test.ts +0 -1676
- package/src/lib/stdin-parser.ts +0 -1248
- package/src/lib/styled-text.ts +0 -178
- package/src/lib/terminal-capability-detection.test.ts +0 -202
- package/src/lib/terminal-capability-detection.ts +0 -79
- package/src/lib/terminal-palette.test.ts +0 -878
- package/src/lib/terminal-palette.ts +0 -383
- package/src/lib/tree-sitter/assets/README.md +0 -118
- package/src/lib/tree-sitter/assets/update.ts +0 -331
- package/src/lib/tree-sitter/assets.d.ts +0 -9
- package/src/lib/tree-sitter/cache.test.ts +0 -270
- package/src/lib/tree-sitter/client.test.ts +0 -1061
- package/src/lib/tree-sitter/client.ts +0 -615
- package/src/lib/tree-sitter/default-parsers.ts +0 -80
- package/src/lib/tree-sitter/download-utils.ts +0 -148
- package/src/lib/tree-sitter/index.ts +0 -28
- package/src/lib/tree-sitter/parser.worker.ts +0 -1001
- package/src/lib/tree-sitter/parsers-config.ts +0 -75
- package/src/lib/tree-sitter/resolve-ft.ts +0 -62
- package/src/lib/tree-sitter/types.ts +0 -81
- package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
- package/src/lib/tree-sitter-styled-text.ts +0 -306
- package/src/lib/validate-dir-name.ts +0 -55
- package/src/lib/yoga.options.test.ts +0 -628
- package/src/lib/yoga.options.ts +0 -346
- package/src/plugins/core-slot.ts +0 -579
- package/src/plugins/registry.ts +0 -377
- package/src/plugins/types.ts +0 -46
- package/src/post/filters.ts +0 -888
- package/src/renderables/ASCIIFont.ts +0 -219
- package/src/renderables/Box.test.ts +0 -160
- package/src/renderables/Box.ts +0 -295
- package/src/renderables/Code.test.ts +0 -2062
- package/src/renderables/Code.ts +0 -357
- package/src/renderables/Diff.regression.test.ts +0 -226
- package/src/renderables/Diff.test.ts +0 -3027
- package/src/renderables/Diff.ts +0 -1209
- package/src/renderables/EditBufferRenderable.ts +0 -764
- package/src/renderables/FrameBuffer.ts +0 -47
- package/src/renderables/Input.test.ts +0 -1228
- package/src/renderables/Input.ts +0 -245
- package/src/renderables/LineNumberRenderable.ts +0 -675
- package/src/renderables/Markdown.ts +0 -1106
- package/src/renderables/ScrollBar.ts +0 -422
- package/src/renderables/ScrollBox.ts +0 -883
- package/src/renderables/Select.test.ts +0 -1010
- package/src/renderables/Select.ts +0 -523
- package/src/renderables/Slider.test.ts +0 -456
- package/src/renderables/Slider.ts +0 -347
- package/src/renderables/TabSelect.test.ts +0 -197
- package/src/renderables/TabSelect.ts +0 -455
- package/src/renderables/Text.selection-buffer.test.ts +0 -123
- package/src/renderables/Text.test.ts +0 -2660
- package/src/renderables/Text.ts +0 -147
- package/src/renderables/TextBufferRenderable.ts +0 -518
- package/src/renderables/TextNode.test.ts +0 -1058
- package/src/renderables/TextNode.ts +0 -325
- package/src/renderables/TextTable.test.ts +0 -1421
- package/src/renderables/TextTable.ts +0 -1344
- package/src/renderables/Textarea.ts +0 -732
- package/src/renderables/TimeToFirstDraw.ts +0 -89
- package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
- package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
- package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1787
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
- package/src/renderables/__tests__/Markdown.test.ts +0 -2287
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
- package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
- package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
- package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
- package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
- package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
- package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1864
- package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
- package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
- package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
- package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
- package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
- package/src/renderables/composition/README.md +0 -8
- package/src/renderables/composition/VRenderable.ts +0 -32
- package/src/renderables/composition/constructs.ts +0 -127
- package/src/renderables/composition/vnode.ts +0 -289
- package/src/renderables/index.ts +0 -22
- package/src/renderables/markdown-parser.ts +0 -66
- package/src/renderer.ts +0 -2363
- package/src/runtime-plugin-support.ts +0 -39
- package/src/runtime-plugin.ts +0 -144
- package/src/syntax-style.test.ts +0 -841
- package/src/syntax-style.ts +0 -264
- package/src/testing/README.md +0 -210
- package/src/testing/capture-spans.test.ts +0 -194
- package/src/testing/integration.test.ts +0 -276
- package/src/testing/manual-clock.ts +0 -106
- package/src/testing/mock-keys.test.ts +0 -1356
- package/src/testing/mock-keys.ts +0 -449
- package/src/testing/mock-mouse.test.ts +0 -218
- package/src/testing/mock-mouse.ts +0 -247
- package/src/testing/mock-tree-sitter-client.ts +0 -73
- package/src/testing/spy.ts +0 -13
- package/src/testing/test-recorder.test.ts +0 -415
- package/src/testing/test-recorder.ts +0 -145
- package/src/testing/test-renderer.ts +0 -116
- package/src/testing.ts +0 -7
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
- package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
- package/src/tests/allocator-stats.test.ts +0 -38
- package/src/tests/destroy-during-render.test.ts +0 -200
- package/src/tests/hover-cursor.test.ts +0 -98
- package/src/tests/native-span-feed-async.test.ts +0 -173
- package/src/tests/native-span-feed-close.test.ts +0 -120
- package/src/tests/native-span-feed-coverage.test.ts +0 -227
- package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
- package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
- package/src/tests/opacity.test.ts +0 -123
- package/src/tests/renderable.snapshot.test.ts +0 -524
- package/src/tests/renderable.test.ts +0 -1281
- package/src/tests/renderer.console-startup.test.ts +0 -65
- package/src/tests/renderer.control.test.ts +0 -364
- package/src/tests/renderer.core-slot-binding.test.ts +0 -952
- package/src/tests/renderer.cursor.test.ts +0 -26
- package/src/tests/renderer.destroy-during-render.test.ts +0 -110
- package/src/tests/renderer.focus-restore.test.ts +0 -228
- package/src/tests/renderer.focus.test.ts +0 -251
- package/src/tests/renderer.idle.test.ts +0 -219
- package/src/tests/renderer.input.test.ts +0 -2145
- package/src/tests/renderer.kitty-flags.test.ts +0 -195
- package/src/tests/renderer.mouse.test.ts +0 -1269
- package/src/tests/renderer.palette.test.ts +0 -629
- package/src/tests/renderer.selection.test.ts +0 -49
- package/src/tests/renderer.slot-registry.test.ts +0 -649
- package/src/tests/renderer.useMouse.test.ts +0 -50
- package/src/tests/runtime-plugin-support.fixture.ts +0 -11
- package/src/tests/runtime-plugin-support.test.ts +0 -28
- package/src/tests/runtime-plugin.fixture.ts +0 -40
- package/src/tests/runtime-plugin.test.ts +0 -190
- package/src/tests/scrollbox-culling-bug.test.ts +0 -114
- package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
- package/src/tests/scrollbox-hitgrid.test.ts +0 -909
- package/src/tests/scrollbox.test.ts +0 -1530
- package/src/tests/wrap-resize-perf.test.ts +0 -229
- package/src/tests/yoga-setters.test.ts +0 -921
- package/src/text-buffer-view.test.ts +0 -705
- package/src/text-buffer-view.ts +0 -189
- package/src/text-buffer.test.ts +0 -347
- package/src/text-buffer.ts +0 -250
- package/src/types.ts +0 -152
- package/src/utils.ts +0 -88
- package/src/zig/ansi.zig +0 -268
- package/src/zig/bench/README.md +0 -50
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
- package/src/zig/bench/edit-buffer_bench.zig +0 -476
- package/src/zig/bench/native-span-feed_bench.zig +0 -100
- package/src/zig/bench/rope-markers_bench.zig +0 -713
- package/src/zig/bench/rope_bench.zig +0 -514
- package/src/zig/bench/styled-text_bench.zig +0 -470
- package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
- package/src/zig/bench/text-buffer-view_bench.zig +0 -459
- package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
- package/src/zig/bench/utf8_bench.zig +0 -799
- package/src/zig/bench-utils.zig +0 -431
- package/src/zig/bench.zig +0 -217
- package/src/zig/buffer.zig +0 -2223
- package/src/zig/build.zig +0 -289
- package/src/zig/build.zig.zon +0 -16
- package/src/zig/edit-buffer.zig +0 -825
- package/src/zig/editor-view.zig +0 -802
- package/src/zig/event-bus.zig +0 -13
- package/src/zig/event-emitter.zig +0 -65
- package/src/zig/file-logger.zig +0 -92
- package/src/zig/grapheme.zig +0 -599
- package/src/zig/lib.zig +0 -1834
- package/src/zig/link.zig +0 -333
- package/src/zig/logger.zig +0 -43
- package/src/zig/mem-registry.zig +0 -125
- package/src/zig/native-span-feed-bench-lib.zig +0 -7
- package/src/zig/native-span-feed.zig +0 -708
- package/src/zig/renderer.zig +0 -1386
- package/src/zig/rope.zig +0 -1220
- package/src/zig/syntax-style.zig +0 -161
- package/src/zig/terminal.zig +0 -975
- package/src/zig/test.zig +0 -70
- package/src/zig/tests/README.md +0 -18
- package/src/zig/tests/buffer_test.zig +0 -2526
- package/src/zig/tests/edit-buffer-history_test.zig +0 -271
- package/src/zig/tests/edit-buffer_test.zig +0 -1689
- package/src/zig/tests/editor-view_test.zig +0 -3299
- package/src/zig/tests/event-emitter_test.zig +0 -249
- package/src/zig/tests/grapheme_test.zig +0 -1304
- package/src/zig/tests/link_test.zig +0 -190
- package/src/zig/tests/mem-registry_test.zig +0 -473
- package/src/zig/tests/memory_leak_regression_test.zig +0 -159
- package/src/zig/tests/native-span-feed_test.zig +0 -1264
- package/src/zig/tests/renderer_test.zig +0 -1010
- package/src/zig/tests/rope-nested_test.zig +0 -712
- package/src/zig/tests/rope_fuzz_test.zig +0 -238
- package/src/zig/tests/rope_test.zig +0 -2362
- package/src/zig/tests/segment-merge.test.zig +0 -148
- package/src/zig/tests/syntax-style_test.zig +0 -557
- package/src/zig/tests/terminal_test.zig +0 -719
- package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
- package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
- package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
- package/src/zig/tests/text-buffer-segment_test.zig +0 -320
- package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
- package/src/zig/tests/text-buffer-view_test.zig +0 -3649
- package/src/zig/tests/text-buffer_test.zig +0 -2191
- package/src/zig/tests/unicode-width-map.zon +0 -3909
- package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
- package/src/zig/tests/utf8_test.zig +0 -4057
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
- package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
- package/src/zig/tests/word-wrap-editing_test.zig +0 -498
- package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
- package/src/zig/text-buffer-iterators.zig +0 -499
- package/src/zig/text-buffer-segment.zig +0 -404
- package/src/zig/text-buffer-view.zig +0 -1371
- package/src/zig/text-buffer.zig +0 -1180
- package/src/zig/utf8.zig +0 -1948
- package/src/zig/utils.zig +0 -9
- package/src/zig-structs.ts +0 -261
- package/src/zig.ts +0 -3843
- package/tsconfig.build.json +0 -22
- package/tsconfig.json +0 -28
- /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
|
@@ -1,1061 +0,0 @@
|
|
|
1
|
-
import { test, expect, beforeEach, afterEach, beforeAll, describe } from "bun:test"
|
|
2
|
-
import { TreeSitterClient } from "./client.js"
|
|
3
|
-
import { tmpdir } from "os"
|
|
4
|
-
import { join } from "path"
|
|
5
|
-
import { mkdir, writeFile, unlink } from "fs/promises"
|
|
6
|
-
import { getDataPaths } from "../data-paths.js"
|
|
7
|
-
import { getTreeSitterClient } from "./index.js"
|
|
8
|
-
|
|
9
|
-
describe("TreeSitterClient", () => {
|
|
10
|
-
let client: TreeSitterClient
|
|
11
|
-
let dataPath: string
|
|
12
|
-
|
|
13
|
-
const sharedDataPath = join(tmpdir(), "tree-sitter-shared-test-data")
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
await mkdir(sharedDataPath, { recursive: true })
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
dataPath = sharedDataPath
|
|
21
|
-
client = new TreeSitterClient({
|
|
22
|
-
dataPath,
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterEach(async () => {
|
|
27
|
-
if (client) {
|
|
28
|
-
await client.destroy()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test("should initialize successfully", async () => {
|
|
33
|
-
await client.initialize()
|
|
34
|
-
expect(client.isInitialized()).toBe(true)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test("should preload parsers for supported filetypes", async () => {
|
|
38
|
-
await client.initialize()
|
|
39
|
-
|
|
40
|
-
const hasJavaScript = await client.preloadParser("javascript")
|
|
41
|
-
expect(hasJavaScript).toBe(true)
|
|
42
|
-
|
|
43
|
-
const hasTypeScript = await client.preloadParser("typescript")
|
|
44
|
-
expect(hasTypeScript).toBe(true)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test("should return false for unsupported filetypes", async () => {
|
|
48
|
-
await client.initialize()
|
|
49
|
-
|
|
50
|
-
const hasUnsupported = await client.preloadParser("unsupported-language")
|
|
51
|
-
expect(hasUnsupported).toBe(false)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test("should create buffer with supported filetype", async () => {
|
|
55
|
-
await client.initialize()
|
|
56
|
-
|
|
57
|
-
const jsCode = 'const hello = "world";'
|
|
58
|
-
const hasParser = await client.createBuffer(1, jsCode, "javascript")
|
|
59
|
-
|
|
60
|
-
expect(hasParser).toBe(true)
|
|
61
|
-
|
|
62
|
-
const buffer = client.getBuffer(1)
|
|
63
|
-
expect(buffer).toBeDefined()
|
|
64
|
-
expect(buffer?.hasParser).toBe(true)
|
|
65
|
-
expect(buffer?.content).toBe(jsCode)
|
|
66
|
-
expect(buffer?.filetype).toBe("javascript")
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test("should create buffer without parser for unsupported filetype", async () => {
|
|
70
|
-
await client.initialize()
|
|
71
|
-
|
|
72
|
-
const content = "some random content"
|
|
73
|
-
const hasParser = await client.createBuffer(1, content, "unsupported")
|
|
74
|
-
|
|
75
|
-
expect(hasParser).toBe(false)
|
|
76
|
-
|
|
77
|
-
const buffer = client.getBuffer(1)
|
|
78
|
-
expect(buffer).toBeDefined()
|
|
79
|
-
expect(buffer?.hasParser).toBe(false)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test("should emit highlights:response event when buffer is updated", async () => {
|
|
83
|
-
await client.initialize()
|
|
84
|
-
|
|
85
|
-
const jsCode = 'const hello = "world";'
|
|
86
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
87
|
-
|
|
88
|
-
let highlightReceived = false
|
|
89
|
-
let receivedBufferId: number | undefined
|
|
90
|
-
let receivedVersion: number | undefined
|
|
91
|
-
|
|
92
|
-
client.on("highlights:response", (bufferId, version, highlights) => {
|
|
93
|
-
highlightReceived = true
|
|
94
|
-
receivedBufferId = bufferId
|
|
95
|
-
receivedVersion = version
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
99
|
-
|
|
100
|
-
const newCode = 'const hello = "world";\nconst foo = 42;'
|
|
101
|
-
const edits = [
|
|
102
|
-
{
|
|
103
|
-
startIndex: jsCode.length,
|
|
104
|
-
oldEndIndex: jsCode.length,
|
|
105
|
-
newEndIndex: newCode.length,
|
|
106
|
-
startPosition: { row: 0, column: jsCode.length },
|
|
107
|
-
oldEndPosition: { row: 0, column: jsCode.length },
|
|
108
|
-
newEndPosition: { row: 1, column: 14 },
|
|
109
|
-
},
|
|
110
|
-
]
|
|
111
|
-
|
|
112
|
-
await client.updateBuffer(1, edits, newCode, 2)
|
|
113
|
-
|
|
114
|
-
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
115
|
-
|
|
116
|
-
expect(highlightReceived).toBe(true)
|
|
117
|
-
expect(receivedBufferId).toBe(1)
|
|
118
|
-
expect(receivedVersion).toBe(2)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test("should handle buffer removal", async () => {
|
|
122
|
-
await client.initialize()
|
|
123
|
-
|
|
124
|
-
const jsCode = 'const hello = "world";'
|
|
125
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
126
|
-
|
|
127
|
-
let bufferDisposed = false
|
|
128
|
-
client.on("buffer:disposed", (bufferId) => {
|
|
129
|
-
if (bufferId === 1) {
|
|
130
|
-
bufferDisposed = true
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
await client.removeBuffer(1)
|
|
135
|
-
|
|
136
|
-
expect(bufferDisposed).toBe(true)
|
|
137
|
-
expect(client.getBuffer(1)).toBeUndefined()
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
test("should handle multiple buffers", async () => {
|
|
141
|
-
await client.initialize()
|
|
142
|
-
|
|
143
|
-
const jsCode = 'const hello = "world";'
|
|
144
|
-
const tsCode = "interface Test { value: string }"
|
|
145
|
-
|
|
146
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
147
|
-
await client.createBuffer(2, tsCode, "typescript")
|
|
148
|
-
|
|
149
|
-
const buffers = client.getAllBuffers()
|
|
150
|
-
expect(buffers).toHaveLength(2)
|
|
151
|
-
|
|
152
|
-
const jsBuffer = client.getBuffer(1)
|
|
153
|
-
const tsBuffer = client.getBuffer(2)
|
|
154
|
-
|
|
155
|
-
expect(jsBuffer?.filetype).toBe("javascript")
|
|
156
|
-
expect(tsBuffer?.filetype).toBe("typescript")
|
|
157
|
-
expect(jsBuffer?.hasParser).toBe(true)
|
|
158
|
-
expect(tsBuffer?.hasParser).toBe(true)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test("should handle buffer reset", async () => {
|
|
162
|
-
await client.initialize()
|
|
163
|
-
|
|
164
|
-
const jsCode = 'const hello = "world";'
|
|
165
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
166
|
-
|
|
167
|
-
const newContent = "function test() { return 42; }"
|
|
168
|
-
await client.resetBuffer(1, 2, newContent)
|
|
169
|
-
|
|
170
|
-
const buffer = client.getBuffer(1)
|
|
171
|
-
expect(buffer?.content).toBe(newContent)
|
|
172
|
-
expect(buffer?.version).toBe(2)
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
test("should emit error events for invalid operations", async () => {
|
|
176
|
-
await client.initialize()
|
|
177
|
-
|
|
178
|
-
let errorReceived = false
|
|
179
|
-
let errorMessage = ""
|
|
180
|
-
|
|
181
|
-
client.on("error", (error, bufferId) => {
|
|
182
|
-
errorReceived = true
|
|
183
|
-
errorMessage = error
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
await client.resetBuffer(999, 1, "test")
|
|
187
|
-
|
|
188
|
-
expect(errorReceived).toBe(true)
|
|
189
|
-
expect(errorMessage).toContain("Cannot reset buffer with no parser")
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
test("should prevent duplicate buffer creation", async () => {
|
|
193
|
-
await client.initialize()
|
|
194
|
-
|
|
195
|
-
const jsCode = 'const hello = "world";'
|
|
196
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
197
|
-
|
|
198
|
-
await expect(client.createBuffer(1, "other code", "javascript")).rejects.toThrow("Buffer with id 1 already exists")
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test("should handle performance metrics", async () => {
|
|
202
|
-
await client.initialize()
|
|
203
|
-
|
|
204
|
-
const performance = await client.getPerformance()
|
|
205
|
-
expect(performance).toBeDefined()
|
|
206
|
-
expect(typeof performance.averageParseTime).toBe("number")
|
|
207
|
-
expect(typeof performance.averageQueryTime).toBe("number")
|
|
208
|
-
expect(Array.isArray(performance.parseTimes)).toBe(true)
|
|
209
|
-
expect(Array.isArray(performance.queryTimes)).toBe(true)
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
test("should handle concurrent buffer operations", async () => {
|
|
213
|
-
await client.initialize()
|
|
214
|
-
|
|
215
|
-
const promises = []
|
|
216
|
-
|
|
217
|
-
for (let i = 0; i < 5; i++) {
|
|
218
|
-
const code = `const var${i} = ${i};`
|
|
219
|
-
promises.push(client.createBuffer(i, code, "javascript"))
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const results = await Promise.all(promises)
|
|
223
|
-
expect(results.every((result) => result === true)).toBe(true)
|
|
224
|
-
|
|
225
|
-
const buffers = client.getAllBuffers()
|
|
226
|
-
expect(buffers).toHaveLength(5)
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
test("should clean up resources on destroy", async () => {
|
|
230
|
-
await client.initialize()
|
|
231
|
-
|
|
232
|
-
const jsCode = 'const hello = "world";'
|
|
233
|
-
await client.createBuffer(1, jsCode, "javascript")
|
|
234
|
-
|
|
235
|
-
expect(client.getAllBuffers()).toHaveLength(1)
|
|
236
|
-
|
|
237
|
-
await client.destroy()
|
|
238
|
-
|
|
239
|
-
expect(client.isInitialized()).toBe(false)
|
|
240
|
-
expect(client.getAllBuffers()).toHaveLength(0)
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
test("should perform one-shot highlighting", async () => {
|
|
244
|
-
await client.initialize()
|
|
245
|
-
|
|
246
|
-
const jsCode = 'const hello = "world";\nfunction test() { return 42; }'
|
|
247
|
-
const result = await client.highlightOnce(jsCode, "javascript")
|
|
248
|
-
|
|
249
|
-
expect(result.highlights).toBeDefined()
|
|
250
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
251
|
-
|
|
252
|
-
const firstHighlight = result.highlights![0]
|
|
253
|
-
expect(Array.isArray(firstHighlight)).toBe(true)
|
|
254
|
-
expect(firstHighlight).toHaveLength(3)
|
|
255
|
-
expect(typeof firstHighlight[0]).toBe("number")
|
|
256
|
-
expect(typeof firstHighlight[1]).toBe("number")
|
|
257
|
-
expect(typeof firstHighlight[2]).toBe("string")
|
|
258
|
-
|
|
259
|
-
const groups = result.highlights!.map((hl) => hl[2])
|
|
260
|
-
expect(groups.length).toBeGreaterThan(0)
|
|
261
|
-
expect(groups).toContain("keyword")
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
test("should handle one-shot highlighting for unsupported filetype", async () => {
|
|
265
|
-
await client.initialize()
|
|
266
|
-
|
|
267
|
-
const result = await client.highlightOnce("some content", "unsupported-lang")
|
|
268
|
-
|
|
269
|
-
expect(result.highlights).toBeUndefined()
|
|
270
|
-
expect(result.warning).toContain("No parser available for filetype unsupported-lang")
|
|
271
|
-
}, 5000)
|
|
272
|
-
|
|
273
|
-
test("should perform multiple one-shot highlights independently", async () => {
|
|
274
|
-
await client.initialize()
|
|
275
|
-
|
|
276
|
-
const jsCode = 'const hello = "world";'
|
|
277
|
-
const tsCode = "interface Test { value: string }"
|
|
278
|
-
|
|
279
|
-
const [jsResult, tsResult] = await Promise.all([
|
|
280
|
-
client.highlightOnce(jsCode, "javascript"),
|
|
281
|
-
client.highlightOnce(tsCode, "typescript"),
|
|
282
|
-
])
|
|
283
|
-
|
|
284
|
-
expect(jsResult.highlights).toBeDefined()
|
|
285
|
-
expect(tsResult.highlights).toBeDefined()
|
|
286
|
-
expect(jsResult.highlights!.length).toBeGreaterThan(0)
|
|
287
|
-
expect(tsResult.highlights!.length).toBeGreaterThan(0)
|
|
288
|
-
|
|
289
|
-
jsResult.highlights!.forEach((hl) => {
|
|
290
|
-
expect(Array.isArray(hl)).toBe(true)
|
|
291
|
-
expect(hl).toHaveLength(3)
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
tsResult.highlights!.forEach((hl) => {
|
|
295
|
-
expect(Array.isArray(hl)).toBe(true)
|
|
296
|
-
expect(hl).toHaveLength(3)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
expect(client.getAllBuffers()).toHaveLength(0)
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
test("should handle Devanagari characters and highlight ranges after them correctly", async () => {
|
|
303
|
-
await client.initialize()
|
|
304
|
-
|
|
305
|
-
const jsCode = 'const greeting = "नमस्ते";\nconst x = 42;'
|
|
306
|
-
const result = await client.highlightOnce(jsCode, "javascript")
|
|
307
|
-
|
|
308
|
-
expect(result.highlights).toBeDefined()
|
|
309
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
310
|
-
|
|
311
|
-
const keywordHighlights = result.highlights!.filter((hl) => hl[2] === "keyword")
|
|
312
|
-
expect(keywordHighlights.length).toBeGreaterThanOrEqual(2)
|
|
313
|
-
|
|
314
|
-
const constHighlights = keywordHighlights.filter((hl) => {
|
|
315
|
-
const text = jsCode.substring(hl[0], hl[1])
|
|
316
|
-
return text === "const"
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
expect(constHighlights).toHaveLength(2)
|
|
320
|
-
|
|
321
|
-
const firstConst = constHighlights[0]
|
|
322
|
-
const secondConst = constHighlights[1]
|
|
323
|
-
|
|
324
|
-
expect(jsCode.substring(firstConst[0], firstConst[1])).toBe("const")
|
|
325
|
-
expect(jsCode.substring(secondConst[0], secondConst[1])).toBe("const")
|
|
326
|
-
|
|
327
|
-
expect(firstConst[0]).toBe(0)
|
|
328
|
-
expect(firstConst[1]).toBe(5)
|
|
329
|
-
|
|
330
|
-
expect(secondConst[0]).toBeGreaterThan(firstConst[1])
|
|
331
|
-
const textBetween = jsCode.substring(firstConst[1], secondConst[0])
|
|
332
|
-
expect(textBetween).toContain("नमस्ते")
|
|
333
|
-
|
|
334
|
-
const numberHighlight = result.highlights!.find((hl) => {
|
|
335
|
-
const text = jsCode.substring(hl[0], hl[1])
|
|
336
|
-
return text === "42" && hl[2] === "number"
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
expect(numberHighlight).toBeDefined()
|
|
340
|
-
if (numberHighlight) {
|
|
341
|
-
const [start, end] = numberHighlight
|
|
342
|
-
const actualText = jsCode.substring(start, end)
|
|
343
|
-
expect(actualText).toBe("42")
|
|
344
|
-
|
|
345
|
-
const secondLine = jsCode.split("\n")[1]
|
|
346
|
-
const secondLineStart = jsCode.indexOf(secondLine)
|
|
347
|
-
const expectedStart = secondLineStart + secondLine.indexOf("42")
|
|
348
|
-
expect(start).toBe(expectedStart)
|
|
349
|
-
}
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
test("should support local file paths for parser configuration", async () => {
|
|
353
|
-
const testQueryPath = join(dataPath, `test-highlights-${Date.now()}.scm`)
|
|
354
|
-
const simpleQuery = "(identifier) @variable"
|
|
355
|
-
await writeFile(testQueryPath, simpleQuery, "utf8")
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
client.addFiletypeParser({
|
|
359
|
-
filetype: "test-lang",
|
|
360
|
-
queries: {
|
|
361
|
-
highlights: [testQueryPath],
|
|
362
|
-
},
|
|
363
|
-
wasm: "https://github.com/tree-sitter/tree-sitter-javascript/releases/download/v0.23.1/tree-sitter-javascript.wasm",
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
await client.initialize()
|
|
367
|
-
|
|
368
|
-
const hasParser = await client.preloadParser("test-lang")
|
|
369
|
-
expect(hasParser).toBe(true)
|
|
370
|
-
|
|
371
|
-
const testCode = "const myVariable = 42;"
|
|
372
|
-
const result = await client.highlightOnce(testCode, "test-lang")
|
|
373
|
-
|
|
374
|
-
expect(result.highlights).toBeDefined()
|
|
375
|
-
expect(result.error).toBeUndefined()
|
|
376
|
-
expect(result.warning).toBeUndefined()
|
|
377
|
-
} finally {
|
|
378
|
-
try {
|
|
379
|
-
await unlink(testQueryPath)
|
|
380
|
-
} catch (e) {
|
|
381
|
-
// Ignore cleanup errors
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
test("should handle concurrent highlightOnce calls efficiently (no duplicate parser loading)", async () => {
|
|
387
|
-
const freshClient = new TreeSitterClient({ dataPath })
|
|
388
|
-
const workerLogs: string[] = []
|
|
389
|
-
|
|
390
|
-
freshClient.on("worker:log", (logType, message) => {
|
|
391
|
-
if (message.includes("Loading from local path:")) {
|
|
392
|
-
workerLogs.push(message)
|
|
393
|
-
}
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
try {
|
|
397
|
-
await freshClient.initialize()
|
|
398
|
-
|
|
399
|
-
const jsCode = 'const hello = "world"; function test() { return 42; }'
|
|
400
|
-
const promises = Array.from({ length: 5 }, () => freshClient.highlightOnce(jsCode, "javascript"))
|
|
401
|
-
|
|
402
|
-
const results = await Promise.all(promises)
|
|
403
|
-
|
|
404
|
-
for (const result of results) {
|
|
405
|
-
expect(result.highlights).toBeDefined()
|
|
406
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
407
|
-
expect(result.error).toBeUndefined()
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const firstResult = results[0]
|
|
411
|
-
for (let i = 1; i < results.length; i++) {
|
|
412
|
-
expect(results[i].highlights).toEqual(firstResult.highlights)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
416
|
-
|
|
417
|
-
const languageLoadLogs = workerLogs.filter((log) => log.includes("tree-sitter-javascript.wasm"))
|
|
418
|
-
const queryLoadLogs = workerLogs.filter((log) => log.includes("highlights.scm"))
|
|
419
|
-
|
|
420
|
-
expect(languageLoadLogs.length).toBeLessThanOrEqual(1)
|
|
421
|
-
expect(queryLoadLogs.length).toBeLessThanOrEqual(1)
|
|
422
|
-
} finally {
|
|
423
|
-
await freshClient.destroy()
|
|
424
|
-
}
|
|
425
|
-
})
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
describe("TreeSitterClient Injections", () => {
|
|
429
|
-
let dataPath: string
|
|
430
|
-
|
|
431
|
-
const injectionsDataPath = join(tmpdir(), "tree-sitter-injections-test-data")
|
|
432
|
-
|
|
433
|
-
beforeAll(async () => {
|
|
434
|
-
await mkdir(injectionsDataPath, { recursive: true })
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
beforeEach(async () => {
|
|
438
|
-
dataPath = injectionsDataPath
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
test("should highlight inline code in markdown using markdown_inline injection", async () => {
|
|
442
|
-
const client = new TreeSitterClient({ dataPath })
|
|
443
|
-
|
|
444
|
-
try {
|
|
445
|
-
await client.initialize()
|
|
446
|
-
|
|
447
|
-
const markdownCode = `# Hello World
|
|
448
|
-
|
|
449
|
-
The \`CodeRenderable\` component provides syntax highlighting.
|
|
450
|
-
|
|
451
|
-
You can use \`const x = 42\` in your code.`
|
|
452
|
-
|
|
453
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
454
|
-
|
|
455
|
-
expect(result.highlights).toBeDefined()
|
|
456
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
457
|
-
|
|
458
|
-
const groups = result.highlights!.map((hl) => hl[2])
|
|
459
|
-
const hasInlineCodeHighlights = groups.some((g) => g.includes("markup.raw"))
|
|
460
|
-
|
|
461
|
-
expect(hasInlineCodeHighlights).toBe(true)
|
|
462
|
-
} finally {
|
|
463
|
-
await client.destroy()
|
|
464
|
-
}
|
|
465
|
-
}, 10000)
|
|
466
|
-
|
|
467
|
-
test("should highlight code blocks in markdown using language-specific injection", async () => {
|
|
468
|
-
const client = new TreeSitterClient({ dataPath })
|
|
469
|
-
|
|
470
|
-
try {
|
|
471
|
-
await client.initialize()
|
|
472
|
-
|
|
473
|
-
const markdownCode = `# Code Example
|
|
474
|
-
|
|
475
|
-
\`\`\`typescript
|
|
476
|
-
const hello: string = "world";
|
|
477
|
-
function test() { return 42; }
|
|
478
|
-
\`\`\`
|
|
479
|
-
|
|
480
|
-
Some text here.`
|
|
481
|
-
|
|
482
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
483
|
-
|
|
484
|
-
expect(result.highlights).toBeDefined()
|
|
485
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
486
|
-
|
|
487
|
-
const groups = result.highlights!.map((hl) => hl[2])
|
|
488
|
-
const hasTypeScriptHighlights = groups.some((g) => g === "keyword" || g === "type" || g === "function")
|
|
489
|
-
|
|
490
|
-
expect(hasTypeScriptHighlights).toBe(true)
|
|
491
|
-
} finally {
|
|
492
|
-
await client.destroy()
|
|
493
|
-
}
|
|
494
|
-
}, 10000)
|
|
495
|
-
|
|
496
|
-
test("should return correct offsets for injected code in markdown code blocks", async () => {
|
|
497
|
-
const client = new TreeSitterClient({ dataPath })
|
|
498
|
-
|
|
499
|
-
try {
|
|
500
|
-
await client.initialize()
|
|
501
|
-
|
|
502
|
-
const markdownCode = `# Title\n\n\`\`\`typescript\nconst x = 42;\n\`\`\``
|
|
503
|
-
|
|
504
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
505
|
-
|
|
506
|
-
expect(result.highlights).toBeDefined()
|
|
507
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
508
|
-
|
|
509
|
-
const constHighlight = result.highlights!.find((hl) => {
|
|
510
|
-
const text = markdownCode.substring(hl[0], hl[1])
|
|
511
|
-
return text === "const" && hl[2] === "keyword"
|
|
512
|
-
})
|
|
513
|
-
|
|
514
|
-
expect(constHighlight).toBeDefined()
|
|
515
|
-
if (constHighlight) {
|
|
516
|
-
const [start, end, group] = constHighlight
|
|
517
|
-
const text = markdownCode.substring(start, end)
|
|
518
|
-
|
|
519
|
-
expect(text).toBe("const")
|
|
520
|
-
expect(group).toBe("keyword")
|
|
521
|
-
expect(start).toBe(23)
|
|
522
|
-
expect(end).toBe(28)
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
const numberHighlight = result.highlights!.find((hl) => {
|
|
526
|
-
const text = markdownCode.substring(hl[0], hl[1])
|
|
527
|
-
return text === "42" && hl[2] === "number"
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
expect(numberHighlight).toBeDefined()
|
|
531
|
-
if (numberHighlight) {
|
|
532
|
-
const [start, end, group] = numberHighlight
|
|
533
|
-
const text = markdownCode.substring(start, end)
|
|
534
|
-
|
|
535
|
-
expect(text).toBe("42")
|
|
536
|
-
expect(group).toBe("number")
|
|
537
|
-
expect(start).toBe(33)
|
|
538
|
-
expect(end).toBe(35)
|
|
539
|
-
}
|
|
540
|
-
} finally {
|
|
541
|
-
await client.destroy()
|
|
542
|
-
}
|
|
543
|
-
}, 10000)
|
|
544
|
-
|
|
545
|
-
test("should return highlights sorted by start offset for injected code", async () => {
|
|
546
|
-
const client = new TreeSitterClient({ dataPath })
|
|
547
|
-
|
|
548
|
-
try {
|
|
549
|
-
await client.initialize()
|
|
550
|
-
|
|
551
|
-
const markdownCode = `# Documentation
|
|
552
|
-
|
|
553
|
-
Some text with \`inline code\` here.
|
|
554
|
-
|
|
555
|
-
\`\`\`typescript
|
|
556
|
-
const first = 1;
|
|
557
|
-
const second = 2;
|
|
558
|
-
\`\`\`
|
|
559
|
-
|
|
560
|
-
More text with \`another inline\` code.
|
|
561
|
-
|
|
562
|
-
\`\`\`javascript
|
|
563
|
-
function test() {
|
|
564
|
-
return 42;
|
|
565
|
-
}
|
|
566
|
-
\`\`\``
|
|
567
|
-
|
|
568
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
569
|
-
|
|
570
|
-
expect(result.highlights).toBeDefined()
|
|
571
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
572
|
-
|
|
573
|
-
for (let i = 1; i < result.highlights!.length; i++) {
|
|
574
|
-
const prevStart = result.highlights![i - 1][0]
|
|
575
|
-
const currStart = result.highlights![i][0]
|
|
576
|
-
expect(currStart).toBeGreaterThanOrEqual(prevStart)
|
|
577
|
-
}
|
|
578
|
-
} finally {
|
|
579
|
-
await client.destroy()
|
|
580
|
-
}
|
|
581
|
-
}, 10000)
|
|
582
|
-
|
|
583
|
-
test("should handle markdown with injections and return valid highlights", async () => {
|
|
584
|
-
const client = new TreeSitterClient({ dataPath })
|
|
585
|
-
|
|
586
|
-
try {
|
|
587
|
-
await client.initialize()
|
|
588
|
-
|
|
589
|
-
const markdownCode = `# Heading
|
|
590
|
-
|
|
591
|
-
Some **bold** text with \`inline code\`.
|
|
592
|
-
|
|
593
|
-
\`\`\`typescript
|
|
594
|
-
const x: string = "hello";
|
|
595
|
-
\`\`\`
|
|
596
|
-
|
|
597
|
-
[Link text](https://example.com)`
|
|
598
|
-
|
|
599
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
600
|
-
|
|
601
|
-
expect(result.highlights).toBeDefined()
|
|
602
|
-
expect(result.highlights!.length).toBeGreaterThan(0)
|
|
603
|
-
|
|
604
|
-
const overlaps: Array<[number, number]> = []
|
|
605
|
-
for (let i = 0; i < result.highlights!.length; i++) {
|
|
606
|
-
for (let j = i + 1; j < result.highlights!.length; j++) {
|
|
607
|
-
const [start1, end1] = result.highlights![i]
|
|
608
|
-
const [start2, end2] = result.highlights![j]
|
|
609
|
-
|
|
610
|
-
if (start2 < end1) {
|
|
611
|
-
overlaps.push([i, j])
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
expect(overlaps.length).toBeGreaterThanOrEqual(0)
|
|
617
|
-
|
|
618
|
-
const injectionHighlights = result.highlights!.filter((hl) => hl[2].includes("injection"))
|
|
619
|
-
expect(injectionHighlights).toBeDefined()
|
|
620
|
-
|
|
621
|
-
const concealHighlights = result.highlights!.filter((hl) => hl[2] === "conceal")
|
|
622
|
-
expect(concealHighlights).toBeDefined()
|
|
623
|
-
|
|
624
|
-
const blockHighlights = result.highlights!.filter((hl) => hl[2] === "markup.raw.block")
|
|
625
|
-
expect(blockHighlights).toBeDefined()
|
|
626
|
-
} finally {
|
|
627
|
-
await client.destroy()
|
|
628
|
-
}
|
|
629
|
-
}, 10000)
|
|
630
|
-
|
|
631
|
-
test("should handle fast concurrent markdown highlighting requests with injections", async () => {
|
|
632
|
-
const client = new TreeSitterClient({ dataPath })
|
|
633
|
-
|
|
634
|
-
const errors: string[] = []
|
|
635
|
-
client.on("error", (error) => {
|
|
636
|
-
errors.push(error)
|
|
637
|
-
})
|
|
638
|
-
|
|
639
|
-
client.on("worker:log", (logType, message) => {
|
|
640
|
-
if (logType === "error") {
|
|
641
|
-
errors.push(message)
|
|
642
|
-
}
|
|
643
|
-
})
|
|
644
|
-
|
|
645
|
-
try {
|
|
646
|
-
await client.initialize()
|
|
647
|
-
|
|
648
|
-
const markdownCode = `# OpenTUI Documentation
|
|
649
|
-
|
|
650
|
-
## Getting Started
|
|
651
|
-
|
|
652
|
-
OpenTUI is a modern terminal UI framework built on **tree-sitter** and WebGPU.
|
|
653
|
-
|
|
654
|
-
### Installation
|
|
655
|
-
|
|
656
|
-
\`\`\`bash
|
|
657
|
-
bun install opentui
|
|
658
|
-
\`\`\`
|
|
659
|
-
|
|
660
|
-
### Quick Example
|
|
661
|
-
|
|
662
|
-
\`\`\`typescript
|
|
663
|
-
import { createCliRenderer, BoxRenderable } from 'opentui';
|
|
664
|
-
|
|
665
|
-
const renderer = await createCliRenderer();
|
|
666
|
-
const box = new BoxRenderable(renderer, {
|
|
667
|
-
border: true,
|
|
668
|
-
title: "Hello World"
|
|
669
|
-
});
|
|
670
|
-
renderer.root.add(box);
|
|
671
|
-
\`\`\`
|
|
672
|
-
|
|
673
|
-
The \`CodeRenderable\` component provides syntax highlighting.
|
|
674
|
-
|
|
675
|
-
| Property | Type | Description |
|
|
676
|
-
|----------|------|-------------|
|
|
677
|
-
| content | string | Code to display |
|
|
678
|
-
| filetype | string | Language type |`
|
|
679
|
-
|
|
680
|
-
const jsCode = `function test() {
|
|
681
|
-
const hello = "world";
|
|
682
|
-
return hello;
|
|
683
|
-
}`
|
|
684
|
-
|
|
685
|
-
const tsCode = `interface User {
|
|
686
|
-
name: string;
|
|
687
|
-
age: number;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
const user: User = { name: "Alice", age: 25 };`
|
|
691
|
-
|
|
692
|
-
const promises = []
|
|
693
|
-
for (let i = 0; i < 5; i++) {
|
|
694
|
-
promises.push(client.highlightOnce(markdownCode, "markdown"))
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
const results = await Promise.allSettled(promises)
|
|
698
|
-
|
|
699
|
-
for (let i = 0; i < results.length; i++) {
|
|
700
|
-
const result = results[i]
|
|
701
|
-
if (result.status === "fulfilled") {
|
|
702
|
-
expect(result.value.error).toBeUndefined()
|
|
703
|
-
expect(result.value.highlights).toBeDefined()
|
|
704
|
-
} else {
|
|
705
|
-
throw new Error(`Request ${i} was rejected: ${result.reason}`)
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
710
|
-
|
|
711
|
-
const hasMemoryErrors = errors.some((err) => err.includes("Out of bounds memory access"))
|
|
712
|
-
expect(hasMemoryErrors).toBe(false)
|
|
713
|
-
} finally {
|
|
714
|
-
await client.destroy()
|
|
715
|
-
}
|
|
716
|
-
}, 15000)
|
|
717
|
-
})
|
|
718
|
-
|
|
719
|
-
describe("TreeSitterClient Conceal Values", () => {
|
|
720
|
-
let dataPath: string
|
|
721
|
-
|
|
722
|
-
const concealDataPath = join(tmpdir(), "tree-sitter-conceal-test-data")
|
|
723
|
-
|
|
724
|
-
beforeAll(async () => {
|
|
725
|
-
await mkdir(concealDataPath, { recursive: true })
|
|
726
|
-
})
|
|
727
|
-
|
|
728
|
-
beforeEach(async () => {
|
|
729
|
-
dataPath = concealDataPath
|
|
730
|
-
})
|
|
731
|
-
|
|
732
|
-
test("should return conceal values from normal (non-injected) queries", async () => {
|
|
733
|
-
const client = new TreeSitterClient({ dataPath })
|
|
734
|
-
|
|
735
|
-
try {
|
|
736
|
-
await client.initialize()
|
|
737
|
-
|
|
738
|
-
const markdownCode = ``
|
|
739
|
-
|
|
740
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
741
|
-
|
|
742
|
-
expect(result.highlights).toBeDefined()
|
|
743
|
-
expect(result.error).toBeUndefined()
|
|
744
|
-
|
|
745
|
-
const concealedHighlights = result.highlights!.filter((hl) => {
|
|
746
|
-
const meta = (hl as any)[3]
|
|
747
|
-
return meta && meta.conceal !== undefined
|
|
748
|
-
})
|
|
749
|
-
|
|
750
|
-
expect(concealedHighlights.length).toBeGreaterThan(0)
|
|
751
|
-
|
|
752
|
-
concealedHighlights.forEach((hl) => {
|
|
753
|
-
const meta = (hl as any)[3]
|
|
754
|
-
expect(meta.conceal).toBeDefined()
|
|
755
|
-
})
|
|
756
|
-
} finally {
|
|
757
|
-
await client.destroy()
|
|
758
|
-
}
|
|
759
|
-
}, 10000)
|
|
760
|
-
|
|
761
|
-
test("should return conceal values from injected queries (markdown_inline)", async () => {
|
|
762
|
-
const client = new TreeSitterClient({ dataPath })
|
|
763
|
-
|
|
764
|
-
try {
|
|
765
|
-
await client.initialize()
|
|
766
|
-
|
|
767
|
-
const markdownCode = `Here is a [link](https://example.com) in text.`
|
|
768
|
-
|
|
769
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
770
|
-
|
|
771
|
-
expect(result.highlights).toBeDefined()
|
|
772
|
-
expect(result.error).toBeUndefined()
|
|
773
|
-
|
|
774
|
-
const concealedHighlights = result.highlights!.filter((hl) => {
|
|
775
|
-
const meta = (hl as any)[3]
|
|
776
|
-
return meta && meta.conceal !== undefined
|
|
777
|
-
})
|
|
778
|
-
|
|
779
|
-
expect(concealedHighlights.length).toBeGreaterThan(0)
|
|
780
|
-
|
|
781
|
-
concealedHighlights.forEach((hl) => {
|
|
782
|
-
const meta = (hl as any)[3]
|
|
783
|
-
expect(meta.conceal).toBeDefined()
|
|
784
|
-
expect(meta.isInjection).toBeDefined()
|
|
785
|
-
})
|
|
786
|
-
|
|
787
|
-
const closingBracketHighlight = concealedHighlights.find((hl) => {
|
|
788
|
-
const text = markdownCode.substring(hl[0], hl[1])
|
|
789
|
-
const meta = (hl as any)[3]
|
|
790
|
-
return text === "]" && meta.conceal !== ""
|
|
791
|
-
})
|
|
792
|
-
|
|
793
|
-
if (closingBracketHighlight) {
|
|
794
|
-
const meta = (closingBracketHighlight as any)[3]
|
|
795
|
-
expect(meta.conceal).toBeDefined()
|
|
796
|
-
}
|
|
797
|
-
} finally {
|
|
798
|
-
await client.destroy()
|
|
799
|
-
}
|
|
800
|
-
}, 10000)
|
|
801
|
-
|
|
802
|
-
test("should distinguish conceal values between normal and injected queries", async () => {
|
|
803
|
-
const client = new TreeSitterClient({ dataPath })
|
|
804
|
-
|
|
805
|
-
try {
|
|
806
|
-
await client.initialize()
|
|
807
|
-
|
|
808
|
-
const markdownCode = `Here is a [link](https://example.com) and .`
|
|
809
|
-
|
|
810
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
811
|
-
|
|
812
|
-
expect(result.highlights).toBeDefined()
|
|
813
|
-
expect(result.error).toBeUndefined()
|
|
814
|
-
|
|
815
|
-
const concealedHighlights = result.highlights!.filter((hl) => {
|
|
816
|
-
const meta = (hl as any)[3]
|
|
817
|
-
return meta && meta.conceal !== undefined
|
|
818
|
-
})
|
|
819
|
-
|
|
820
|
-
expect(concealedHighlights.length).toBeGreaterThan(0)
|
|
821
|
-
|
|
822
|
-
const normalConceal = concealedHighlights.filter((hl) => {
|
|
823
|
-
const meta = (hl as any)[3]
|
|
824
|
-
return !meta.isInjection
|
|
825
|
-
})
|
|
826
|
-
|
|
827
|
-
const injectedConceal = concealedHighlights.filter((hl) => {
|
|
828
|
-
const meta = (hl as any)[3]
|
|
829
|
-
return meta.isInjection
|
|
830
|
-
})
|
|
831
|
-
|
|
832
|
-
expect(injectedConceal.length).toBeGreaterThan(0)
|
|
833
|
-
|
|
834
|
-
injectedConceal.forEach((hl) => {
|
|
835
|
-
const meta = (hl as any)[3]
|
|
836
|
-
expect(meta.conceal).toBeDefined()
|
|
837
|
-
expect(meta.isInjection).toBe(true)
|
|
838
|
-
})
|
|
839
|
-
|
|
840
|
-
concealedHighlights.forEach((hl) => {
|
|
841
|
-
const meta = (hl as any)[3]
|
|
842
|
-
expect(meta.conceal).toBeDefined()
|
|
843
|
-
expect(typeof meta.isInjection).toBe("boolean")
|
|
844
|
-
})
|
|
845
|
-
} finally {
|
|
846
|
-
await client.destroy()
|
|
847
|
-
}
|
|
848
|
-
}, 10000)
|
|
849
|
-
|
|
850
|
-
test("should handle pattern index lookups correctly for injections", async () => {
|
|
851
|
-
const client = new TreeSitterClient({ dataPath })
|
|
852
|
-
|
|
853
|
-
try {
|
|
854
|
-
await client.initialize()
|
|
855
|
-
|
|
856
|
-
const markdownCode = `A [link](url) here.`
|
|
857
|
-
|
|
858
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
859
|
-
|
|
860
|
-
expect(result.highlights).toBeDefined()
|
|
861
|
-
expect(result.error).toBeUndefined()
|
|
862
|
-
|
|
863
|
-
const concealedHighlights = result.highlights!.filter((hl) => {
|
|
864
|
-
const meta = (hl as any)[3]
|
|
865
|
-
return meta && meta.conceal !== undefined
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
expect(concealedHighlights.length).toBeGreaterThan(0)
|
|
869
|
-
|
|
870
|
-
concealedHighlights.forEach((hl) => {
|
|
871
|
-
const meta = (hl as any)[3]
|
|
872
|
-
expect(meta.conceal).toBeDefined()
|
|
873
|
-
})
|
|
874
|
-
} finally {
|
|
875
|
-
await client.destroy()
|
|
876
|
-
}
|
|
877
|
-
}, 10000)
|
|
878
|
-
|
|
879
|
-
test("should handle multiple injected languages with different conceal patterns", async () => {
|
|
880
|
-
const client = new TreeSitterClient({ dataPath })
|
|
881
|
-
|
|
882
|
-
try {
|
|
883
|
-
await client.initialize()
|
|
884
|
-
|
|
885
|
-
const markdownCode = `# Title
|
|
886
|
-
|
|
887
|
-
Inline \`code\` and a [link](url) here.
|
|
888
|
-
|
|
889
|
-
\`\`\`typescript
|
|
890
|
-
const x = 42;
|
|
891
|
-
\`\`\`
|
|
892
|
-
|
|
893
|
-
More text with  and **bold**.`
|
|
894
|
-
|
|
895
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
896
|
-
|
|
897
|
-
expect(result.highlights).toBeDefined()
|
|
898
|
-
expect(result.error).toBeUndefined()
|
|
899
|
-
|
|
900
|
-
const concealedHighlights = result.highlights!.filter((hl) => {
|
|
901
|
-
const meta = (hl as any)[3]
|
|
902
|
-
return meta && meta.conceal !== undefined
|
|
903
|
-
})
|
|
904
|
-
|
|
905
|
-
expect(concealedHighlights.length).toBeGreaterThan(0)
|
|
906
|
-
|
|
907
|
-
const byLang = new Map<string, any[]>()
|
|
908
|
-
concealedHighlights.forEach((hl) => {
|
|
909
|
-
const meta = (hl as any)[3]
|
|
910
|
-
const lang = meta.isInjection ? meta.injectionLang || "injected" : "normal"
|
|
911
|
-
if (!byLang.has(lang)) {
|
|
912
|
-
byLang.set(lang, [])
|
|
913
|
-
}
|
|
914
|
-
byLang.get(lang)!.push(hl)
|
|
915
|
-
})
|
|
916
|
-
|
|
917
|
-
expect(byLang.size).toBeGreaterThan(0)
|
|
918
|
-
|
|
919
|
-
byLang.forEach((highlights) => {
|
|
920
|
-
expect(highlights.length).toBeGreaterThan(0)
|
|
921
|
-
highlights.forEach((hl: any) => {
|
|
922
|
-
const meta = hl[3]
|
|
923
|
-
expect(meta.conceal).toBeDefined()
|
|
924
|
-
})
|
|
925
|
-
})
|
|
926
|
-
} finally {
|
|
927
|
-
await client.destroy()
|
|
928
|
-
}
|
|
929
|
-
}, 10000)
|
|
930
|
-
|
|
931
|
-
test("should preserve non-empty conceal replacements like space character", async () => {
|
|
932
|
-
const client = new TreeSitterClient({ dataPath })
|
|
933
|
-
|
|
934
|
-
try {
|
|
935
|
-
await client.initialize()
|
|
936
|
-
|
|
937
|
-
const markdownCode = `Check [this link](https://example.com) out!`
|
|
938
|
-
|
|
939
|
-
const result = await client.highlightOnce(markdownCode, "markdown")
|
|
940
|
-
|
|
941
|
-
expect(result.highlights).toBeDefined()
|
|
942
|
-
expect(result.error).toBeUndefined()
|
|
943
|
-
|
|
944
|
-
const closingBracket = result.highlights!.find((hl) => {
|
|
945
|
-
const text = markdownCode.substring(hl[0], hl[1])
|
|
946
|
-
const meta = (hl as any)[3]
|
|
947
|
-
return text === "]" && hl[2] === "conceal" && meta?.conceal !== undefined
|
|
948
|
-
})
|
|
949
|
-
|
|
950
|
-
if (closingBracket) {
|
|
951
|
-
const meta = (closingBracket as any)[3]
|
|
952
|
-
expect(meta).toBeDefined()
|
|
953
|
-
expect(meta.conceal).toBeDefined()
|
|
954
|
-
expect(meta.conceal).toBe(" ")
|
|
955
|
-
expect(meta.conceal.length).toBeGreaterThan(0)
|
|
956
|
-
}
|
|
957
|
-
} finally {
|
|
958
|
-
await client.destroy()
|
|
959
|
-
}
|
|
960
|
-
}, 10000)
|
|
961
|
-
})
|
|
962
|
-
|
|
963
|
-
describe("TreeSitterClient Edge Cases", () => {
|
|
964
|
-
let dataPath: string
|
|
965
|
-
|
|
966
|
-
const edgeCaseDataPath = join(tmpdir(), "tree-sitter-edge-case-test-data")
|
|
967
|
-
|
|
968
|
-
beforeAll(async () => {
|
|
969
|
-
await mkdir(edgeCaseDataPath, { recursive: true })
|
|
970
|
-
})
|
|
971
|
-
|
|
972
|
-
beforeEach(async () => {
|
|
973
|
-
dataPath = edgeCaseDataPath
|
|
974
|
-
})
|
|
975
|
-
|
|
976
|
-
test("should handle initialization timeout", async () => {
|
|
977
|
-
const client = new TreeSitterClient({
|
|
978
|
-
dataPath,
|
|
979
|
-
workerPath: "invalid-path",
|
|
980
|
-
initTimeout: 500,
|
|
981
|
-
})
|
|
982
|
-
|
|
983
|
-
await expect(client.initialize()).rejects.toThrow(/Worker error|Worker initialization timed out/)
|
|
984
|
-
|
|
985
|
-
await client.destroy()
|
|
986
|
-
})
|
|
987
|
-
|
|
988
|
-
test("should handle operations before initialization", async () => {
|
|
989
|
-
const client = new TreeSitterClient({ dataPath })
|
|
990
|
-
|
|
991
|
-
expect(client.isInitialized()).toBe(false)
|
|
992
|
-
expect(client.getAllBuffers()).toHaveLength(0)
|
|
993
|
-
expect(client.getBuffer(1)).toBeUndefined()
|
|
994
|
-
|
|
995
|
-
await client.destroy()
|
|
996
|
-
})
|
|
997
|
-
|
|
998
|
-
test("should handle destroy() during pending initialization", async () => {
|
|
999
|
-
const client = new TreeSitterClient({ dataPath })
|
|
1000
|
-
|
|
1001
|
-
// Start init but don't await
|
|
1002
|
-
const initPromise = client.initialize()
|
|
1003
|
-
|
|
1004
|
-
// Immediately destroy
|
|
1005
|
-
await client.destroy()
|
|
1006
|
-
|
|
1007
|
-
// Init promise should reject with specific error
|
|
1008
|
-
await expect(initPromise).rejects.toThrow("Client destroyed during initialization")
|
|
1009
|
-
|
|
1010
|
-
expect(client.isInitialized()).toBe(false)
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
test("should handle worker errors gracefully", async () => {
|
|
1014
|
-
const client = new TreeSitterClient({ dataPath })
|
|
1015
|
-
|
|
1016
|
-
let errorReceived = false
|
|
1017
|
-
client.on("error", () => {
|
|
1018
|
-
errorReceived = true
|
|
1019
|
-
})
|
|
1020
|
-
|
|
1021
|
-
const hasParser = await client.createBuffer(1, "test", "javascript", 1, false)
|
|
1022
|
-
expect(hasParser).toBe(false)
|
|
1023
|
-
expect(errorReceived).toBe(true)
|
|
1024
|
-
|
|
1025
|
-
await client.destroy()
|
|
1026
|
-
})
|
|
1027
|
-
|
|
1028
|
-
test("should handle data path changes with reactive getTreeSitterClient", async () => {
|
|
1029
|
-
const dataPathsManager = getDataPaths()
|
|
1030
|
-
const originalAppName = dataPathsManager.appName
|
|
1031
|
-
let client: any
|
|
1032
|
-
|
|
1033
|
-
try {
|
|
1034
|
-
client = getTreeSitterClient()
|
|
1035
|
-
await client.initialize()
|
|
1036
|
-
|
|
1037
|
-
const initialDataPath = dataPathsManager.globalDataPath
|
|
1038
|
-
|
|
1039
|
-
dataPathsManager.appName = "test-app-changed"
|
|
1040
|
-
|
|
1041
|
-
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
1042
|
-
|
|
1043
|
-
const newDataPath = dataPathsManager.globalDataPath
|
|
1044
|
-
expect(newDataPath).not.toBe(initialDataPath)
|
|
1045
|
-
expect(newDataPath).toContain("test-app-changed")
|
|
1046
|
-
|
|
1047
|
-
if (!client.isInitialized()) {
|
|
1048
|
-
await client.initialize()
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
const hasParser = await client.preloadParser("javascript")
|
|
1052
|
-
expect(hasParser).toBe(true)
|
|
1053
|
-
} finally {
|
|
1054
|
-
if (client) {
|
|
1055
|
-
await client.destroy()
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
dataPathsManager.appName = originalAppName
|
|
1059
|
-
}
|
|
1060
|
-
})
|
|
1061
|
-
})
|