@kabmo-labs/kabmo 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +336 -336
- package/dist/client/static/js/index-18xe7655.css +1 -0
- package/dist/client/static/js/{index-qwpvd9fv.js → index-nxpe7835.js} +933 -898
- package/package.json +11 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
- package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
- package/src/client/components/common/code-surface/documents.test.ts +122 -0
- package/src/client/components/common/code-surface/documents.ts +286 -0
- package/src/client/components/common/code-surface/extensions.test.ts +115 -0
- package/src/client/components/common/code-surface/extensions.ts +295 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
- package/src/client/components/common/code-surface/fold.test.ts +148 -0
- package/src/client/components/common/code-surface/fold.ts +118 -0
- package/src/client/components/common/code-surface/handle.ts +102 -0
- package/src/client/components/common/code-surface/indent-guide.ts +104 -0
- package/src/client/components/common/code-surface/indent.test.ts +239 -0
- package/src/client/components/common/code-surface/indent.ts +124 -0
- package/src/client/components/common/code-surface/index.tsx +283 -314
- package/src/client/components/common/code-surface/keymap.test.ts +133 -0
- package/src/client/components/common/code-surface/keymap.ts +256 -0
- package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
- package/src/client/components/common/code-surface/line-commands.ts +103 -0
- package/src/client/components/common/code-surface/marks.ts +74 -0
- package/src/client/components/common/code-surface/props.ts +87 -0
- package/src/client/components/common/code-surface/shiki.ts +234 -0
- package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
- package/src/client/components/common/code-surface/stream-language.ts +123 -0
- package/src/client/components/common/code-surface/sync.test.ts +185 -0
- package/src/client/components/common/code-surface/sync.ts +58 -0
- package/src/client/components/common/code-surface/theme.test.ts +237 -0
- package/src/client/components/common/code-surface/theme.ts +224 -0
- package/src/client/components/common/code-surface/typing.test.ts +97 -0
- package/src/client/components/common/code-surface/typing.ts +111 -0
- package/src/client/components/common/editor-view-buttons/index.test.tsx +148 -0
- package/src/client/components/common/editor-view-buttons/index.tsx +109 -0
- package/src/client/components/common/shell-update-button/Modal.tsx +163 -0
- package/src/client/components/common/shell-update-button/index.test.tsx +251 -0
- package/src/client/components/common/shell-update-button/index.tsx +125 -0
- package/src/client/components/common/toolbar-row/index.test.tsx +215 -0
- package/src/client/components/common/toolbar-row/index.tsx +260 -0
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +58 -78
- package/src/client/components/layout/desktop-layout/index.tsx +65 -67
- package/src/client/components/layout/desktop-layout/resizer/index.tsx +6 -3
- package/src/client/components/layout/session-sidebar/Footer.tsx +8 -15
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +98 -71
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.test.tsx +137 -0
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.tsx +14 -3
- package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/Footer.tsx +9 -21
- package/src/client/components/settings/Modal.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +9 -0
- package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +167 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +184 -0
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +8 -2
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +16 -8
- package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +9 -4
- package/src/client/components/workspace/chat-timeline/TaskResultContent.tsx +9 -7
- package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
- package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +132 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.test.tsx +319 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +285 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/hashline-patch/index.tsx +34 -29
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AstEdit.tsx +11 -9
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +10 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +25 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.tsx +8 -11
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.test.ts +114 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +7 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/SearchTool.tsx +9 -59
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactBody.tsx +2 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +43 -30
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +49 -32
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ExcerptCode.tsx +8 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/HighlightedCode.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock.tsx +4 -4
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +179 -0
- package/src/client/components/workspace/diff-panel/ThemedMergeDiffView.tsx +24 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +224 -186
- package/src/client/components/workspace/diff-panel/ToolbarSegments.tsx +98 -0
- package/src/client/components/workspace/diff-panel/index.tsx +76 -145
- package/src/client/components/workspace/diff-panel/merge.ts +315 -0
- package/src/client/components/workspace/editor/Body.tsx +28 -7
- package/src/client/components/workspace/editor/CommandPalette.tsx +6 -6
- package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
- package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
- package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
- package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +146 -63
- package/src/client/components/workspace/editor/FilePane.tsx +47 -7
- package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
- package/src/client/components/workspace/editor/FindWidget.tsx +36 -2
- package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
- package/src/client/components/workspace/editor/Notices.tsx +71 -0
- package/src/client/components/workspace/editor/Pane.tsx +118 -0
- package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
- package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
- package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
- package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
- package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
- package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
- package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
- package/src/client/components/workspace/editor/Tabs.tsx +195 -18
- package/src/client/components/workspace/editor/Toolbar.tsx +110 -140
- package/src/client/components/workspace/editor/index.tsx +201 -193
- package/src/client/components/workspace/editor/props.ts +64 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
- package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
- package/src/client/components/workspace/file-explorer/OutlineSection.test.tsx +18 -0
- package/src/client/components/workspace/file-explorer/OutlineSection.tsx +10 -3
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
- package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -48
- package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
- package/src/client/components/workspace/search-panel/Body.tsx +7 -2
- package/src/client/components/workspace/worktree-modal/index.test.tsx +118 -0
- package/src/client/hooks/chat/composer/file-drop.ts +22 -37
- package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
- package/src/client/hooks/chat/composer/pipeline.ts +12 -1
- package/src/client/hooks/chat/omp/reconnect.test.ts +338 -0
- package/src/client/hooks/chat/omp/reconnect.ts +187 -0
- package/src/client/hooks/chat/omp/run-liveness.test.ts +71 -0
- package/src/client/hooks/chat/omp/run-liveness.ts +65 -0
- package/src/client/hooks/chat/omp/session-list.activity.test.ts +114 -0
- package/src/client/hooks/chat/omp/session-list.test-util.ts +164 -0
- package/src/client/hooks/chat/omp/session-list.test.ts +30 -150
- package/src/client/hooks/chat/omp/session-list.tsx +69 -9
- package/src/client/hooks/chat/timeline/generating.ts +19 -2
- package/src/client/hooks/chat/timeline/index.ts +19 -24
- package/src/client/hooks/chat/timeline/lost-run.test.ts +329 -0
- package/src/client/hooks/chat/timeline/lost-run.ts +177 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +205 -0
- package/src/client/hooks/chat/timeline/session-load.test.ts +61 -162
- package/src/client/hooks/chat/timeline/session-load.ts +69 -37
- package/src/client/hooks/chat/timeline/session-switch.test.ts +65 -0
- package/src/client/hooks/chat/timeline/session-switch.ts +63 -0
- package/src/client/hooks/code/deferred-highlight.test.ts +182 -0
- package/src/client/hooks/code/deferred-highlight.ts +129 -0
- package/src/client/hooks/editor/caret-position.test.ts +58 -0
- package/src/client/hooks/editor/caret-position.ts +48 -0
- package/src/client/hooks/editor/file-editor-types.ts +200 -0
- package/src/client/hooks/editor/find-history.test.ts +132 -0
- package/src/client/hooks/editor/find-history.ts +46 -0
- package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
- package/src/client/hooks/editor/find-selection-range.ts +49 -0
- package/src/client/hooks/editor/find-state.ts +14 -1
- package/src/client/hooks/editor/font.test.ts +0 -93
- package/src/client/hooks/editor/indent-settings.test.ts +104 -0
- package/src/client/hooks/editor/indent-settings.ts +88 -0
- package/src/client/hooks/editor/quick-open.test.ts +141 -0
- package/src/client/hooks/editor/quick-open.ts +127 -0
- package/src/client/hooks/editor/save-as.test.ts +156 -0
- package/src/client/hooks/editor/save-as.ts +122 -0
- package/src/client/hooks/editor/save-file.test.ts +179 -0
- package/src/client/hooks/editor/save-file.ts +73 -28
- package/src/client/hooks/editor/theme.test.ts +206 -0
- package/src/client/hooks/editor/theme.ts +82 -0
- package/src/client/hooks/editor/typing-settings.test.ts +73 -0
- package/src/client/hooks/editor/typing-settings.ts +65 -0
- package/src/client/hooks/editor/use-close-guard.ts +98 -0
- package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
- package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +101 -0
- package/src/client/hooks/editor/use-editor-drop.ts +120 -77
- package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
- package/src/client/hooks/editor/use-editor-find.ts +45 -10
- package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
- package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
- package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
- package/src/client/hooks/editor/use-external-change.test.ts +88 -0
- package/src/client/hooks/editor/use-external-change.ts +146 -0
- package/src/client/hooks/editor/use-file-editor.ts +83 -116
- package/src/client/hooks/editor/use-file-read.ts +16 -8
- package/src/client/hooks/editor/use-file-writes.ts +28 -3
- package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
- package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
- package/src/client/hooks/editor/use-outline-view.test.ts +182 -0
- package/src/client/hooks/editor/use-outline-view.ts +94 -7
- package/src/client/hooks/editor/use-scroll-restore.test.ts +55 -2
- package/src/client/hooks/editor/use-scroll-restore.ts +124 -4
- package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
- package/src/client/hooks/editor/use-search-reveal.ts +1 -1
- package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
- package/src/client/hooks/editor/use-split-editor.ts +91 -0
- package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
- package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
- package/src/client/hooks/editor/use-write-conflict.ts +152 -0
- package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
- package/src/client/hooks/editor/wheel-zoom.ts +96 -0
- package/src/client/hooks/ui/drag-presence.test.ts +193 -0
- package/src/client/hooks/ui/drag-presence.ts +108 -0
- package/src/client/hooks/ui/settings-modal.test.ts +115 -0
- package/src/client/hooks/ui/settings-modal.ts +56 -0
- package/src/client/hooks/ui/updates/shell-download.test.ts +2 -0
- package/src/client/hooks/ui/updates/shell-download.ts +55 -14
- package/src/client/hooks/ui/updates/shell-offer.test.ts +26 -0
- package/src/client/hooks/ui/updates/shell-update.test.ts +140 -0
- package/src/client/hooks/ui/updates/shell-update.ts +119 -0
- package/src/client/hooks/workspace/diff-file.ts +29 -10
- package/src/client/hooks/workspace/diff-git-actions.ts +147 -0
- package/src/client/hooks/workspace/editor-view.ts +61 -0
- package/src/client/hooks/workspace/file-listing.ts +36 -24
- package/src/client/hooks/workspace/file-tabs.test.ts +152 -5
- package/src/client/hooks/workspace/file-tabs.ts +70 -11
- package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
- package/src/client/hooks/workspace/navbar-session-actions.ts +72 -0
- package/src/client/hooks/workspace/worktree/index.ts +20 -5
- package/src/client/lib/desktop/bridge.ts +45 -0
- package/src/client/lib/desktop/dropped-paths.ts +83 -0
- package/src/client/lib/editor/tab-menu.test.ts +127 -0
- package/src/client/lib/editor/tab-menu.ts +127 -0
- package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
- package/src/client/lib/editor-dirty-tabs.ts +103 -0
- package/src/client/lib/native/resume.test.ts +66 -0
- package/src/client/lib/native/resume.ts +42 -0
- package/src/client/lib/search-reveal.ts +1 -1
- package/src/client/main.tsx +13 -1
- package/src/client/tailwind.css +75 -8
- package/src/server/lib/auth/guard.test.ts +28 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/bundler/css.test.ts +31 -0
- package/src/server/lib/fs/listing.test.ts +81 -16
- package/src/server/lib/fs/listing.ts +72 -5
- package/src/server/lib/fs/worktree/create.ts +2 -3
- package/src/server/lib/fs/worktree/list.ts +13 -0
- package/src/server/lib/fs/worktree/remove.ts +3 -3
- package/src/server/lib/fs/write-conflict.test.ts +68 -0
- package/src/server/lib/fs/write-conflict.ts +84 -0
- package/src/server/lib/lifecycle/claim-port.test.ts +156 -0
- package/src/server/lib/lifecycle/port-guard.test.ts +20 -164
- package/src/server/lib/lifecycle/port-guard.ts +39 -7
- package/src/server/lib/lifecycle/probe-health.test.ts +166 -0
- package/src/server/lib/lifecycle/probe.test.ts +77 -164
- package/src/server/lib/lifecycle/probe.ts +121 -13
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +112 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +10 -5
- package/src/server/lib/omp/session/sidebar-activity.server.test.ts +162 -0
- package/src/server/lib/omp/session/sidebar-activity.server.ts +70 -0
- package/src/server/lib/omp/session/telemetry/compute.ts +13 -1
- package/src/server/lib/omp/session/telemetry.test.ts +33 -0
- package/src/server/lib/realtime/signals.server.ts +10 -0
- package/src/server/lib/realtime/topics/catalog.server.ts +4 -1
- package/src/server/lib/realtime/topics.server.ts +16 -0
- package/src/server/lib/updates/shell-assets.ts +94 -3
- package/src/server/lib/updates/shell-cache.ts +105 -0
- package/src/server/lib/updates/shell-pages.test.ts +33 -2
- package/src/server/lib/updates/shell-pages.ts +17 -5
- package/src/server/lib/updates/shell-release-desktop.test.ts +166 -0
- package/src/server/lib/updates/shell-release.test.ts +10 -27
- package/src/server/lib/updates/shell-release.ts +107 -111
- package/src/server/routes/fs/action-save-as.test.ts +82 -0
- package/src/server/routes/fs/action.test.ts +82 -0
- package/src/server/routes/fs/action.ts +54 -1
- package/src/server/routes/fs/exists.ts +11 -1
- package/src/server/routes/fs/git-merge.test.ts +11 -1
- package/src/server/routes/fs/read.test.ts +24 -7
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/fs/scope.test.ts +15 -10
- package/src/server/routes/fs/scope.ts +3 -14
- package/src/server/routes/updates/android.ts +6 -1
- package/src/server/routes/updates/desktop.ts +29 -7
- package/src/server/routes/updates/ios.ts +5 -1
- package/src/server/routes/worktrees/list.ts +11 -1
- package/src/server/routes/worktrees/routes.test.ts +17 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +36 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +18 -0
- package/src/shared/lib/chat/timeline/run-signals.test.ts +2 -0
- package/src/shared/lib/code/editor/comment-syntax.test.ts +37 -0
- package/src/shared/lib/code/editor/comment-syntax.ts +55 -0
- package/src/shared/lib/code/editor/find-replace.test.ts +134 -0
- package/src/shared/lib/code/editor/{find.ts → find-replace.ts} +23 -107
- package/src/shared/lib/code/editor/{find.test.ts → find-scan.test.ts} +20 -74
- package/src/shared/lib/code/editor/find-scan.ts +198 -0
- package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
- package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
- package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
- package/src/shared/lib/code/editor/indent-rules.ts +198 -0
- package/src/shared/lib/code/editor/keymap.test.ts +23 -0
- package/src/shared/lib/code/editor/keymap.ts +43 -6
- package/src/shared/lib/code/editor/lines.test.ts +7 -55
- package/src/shared/lib/code/editor/lines.ts +8 -48
- package/src/shared/lib/code/editor/marks.test.ts +4 -5
- package/src/shared/lib/code/editor/marks.ts +13 -25
- package/src/shared/lib/code/editor/palette.test.ts +25 -2
- package/src/shared/lib/code/editor/palette.ts +10 -0
- package/src/shared/lib/code/editor/stream-modes.ts +225 -0
- package/src/shared/lib/code/editor/theme-loader.ts +97 -0
- package/src/shared/lib/code/editor/themes.generated.ts +156 -0
- package/src/shared/lib/code/editor/themes.test.ts +165 -0
- package/src/shared/lib/code/editor/themes.ts +165 -0
- package/src/shared/lib/code/highlight-memo.test.ts +103 -0
- package/src/shared/lib/code/highlight-memo.ts +149 -0
- package/src/shared/lib/code/highlighter-warmup.ts +112 -0
- package/src/shared/lib/code/highlighter.ts +3 -1
- package/src/shared/lib/code/idle.ts +37 -0
- package/src/shared/lib/code/outline/rows.test.ts +96 -0
- package/src/shared/lib/code/outline/rows.ts +94 -0
- package/src/shared/lib/code/syntax-highlight.test.ts +2 -80
- package/src/shared/lib/code/syntax-highlight.ts +2 -3
- package/src/shared/lib/fs/file-kind-classify.test.ts +25 -11
- package/src/shared/lib/fs/file-kind.ts +47 -13
- package/src/shared/lib/fs/file-tree.test.ts +41 -0
- package/src/shared/lib/fs/file-tree.ts +126 -34
- package/src/shared/lib/fs/file-url.test.ts +52 -0
- package/src/shared/lib/fs/file-url.ts +37 -0
- package/src/shared/lib/fs/folder-chain.test.ts +87 -0
- package/src/shared/lib/fs/folder-chain.ts +91 -0
- package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
- package/src/shared/lib/fs/patch-sides.test.ts +114 -0
- package/src/shared/lib/fs/patch-sides.ts +139 -0
- package/src/shared/lib/realtime/connection.test.ts +5 -1
- package/src/shared/lib/realtime/connection.ts +25 -119
- package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
- package/src/shared/lib/realtime/protocol.ts +16 -0
- package/src/shared/lib/realtime/resume.ts +223 -0
- package/src/shared/lib/realtime/state.ts +22 -0
- package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
- package/src/shared/lib/realtime/watchdog.test.ts +99 -0
- package/src/shared/lib/realtime/watchdog.ts +72 -0
- package/src/shared/lib/ui/toolbar-overflow.test.ts +83 -0
- package/src/shared/lib/ui/toolbar-overflow.ts +86 -0
- package/src/shared/lib/updates/shell-arch.ts +54 -0
- package/src/shared/lib/updates/shell-ua.ts +4 -4
- package/src/shared/lib/workspace/editor-view-mode.test.ts +70 -0
- package/src/shared/lib/workspace/editor-view-mode.ts +48 -0
- package/src/shared/lib/workspace/panel-widths.test.ts +30 -0
- package/src/shared/lib/workspace/panel-widths.ts +25 -5
- package/src/shared/lib/workspace/session-state/cache.ts +159 -0
- package/src/shared/lib/workspace/session-state/harness.test-util.ts +55 -0
- package/src/shared/lib/workspace/session-state/merge.ts +100 -0
- package/src/shared/lib/workspace/session-state/store-load.test.ts +206 -0
- package/src/shared/lib/workspace/session-state/store.test.ts +17 -139
- package/src/shared/lib/workspace/session-state/store.ts +92 -130
- package/src/shared/lib/workspace/split-editor.test.ts +104 -0
- package/src/shared/lib/workspace/split-editor.ts +129 -0
- package/src/shared/lib/workspace/workspace-panel-widths.ts +124 -0
- package/src/shared/types/realtime.ts +29 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/test-support/file-explorer-disk.test-util.ts +30 -3
- package/src/test-support/loopback.ts +183 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-gtbpewr7.css +0 -1
- package/src/client/components/common/code-editor/handler.test.ts +0 -274
- package/src/client/components/common/code-editor/handler.ts +0 -175
- package/src/client/components/common/code-editor/index.tsx +0 -314
- package/src/client/components/common/code-surface/measure.ts +0 -148
- package/src/client/components/workspace/chat-timeline/target-picker/index.test.tsx +0 -227
- package/src/client/components/workspace/chat-timeline/target-picker/index.tsx +0 -260
- package/src/client/components/workspace/diff-panel/SplitView.tsx +0 -209
- package/src/client/components/workspace/diff-panel/UnifiedView.tsx +0 -150
- package/src/client/hooks/editor/scroll-container.test.ts +0 -102
- package/src/client/hooks/editor/scroll-container.ts +0 -26
- package/src/client/hooks/editor/use-code-window.ts +0 -100
- package/src/client/hooks/editor/use-editor-history.test.ts +0 -216
- package/src/client/hooks/editor/use-editor-history.ts +0 -134
- package/src/client/hooks/editor/use-occurrences.test.ts +0 -236
- package/src/client/hooks/editor/use-occurrences.ts +0 -98
- package/src/shared/lib/code/editor/commands.test.ts +0 -155
- package/src/shared/lib/code/editor/commands.ts +0 -260
- package/src/shared/lib/code/editor/edits.test.ts +0 -100
- package/src/shared/lib/code/editor/edits.ts +0 -122
- package/src/shared/lib/code/editor/history.test.ts +0 -118
- package/src/shared/lib/code/editor/history.ts +0 -101
- package/src/shared/lib/code/editor/layers.test.ts +0 -77
- package/src/shared/lib/code/editor/layers.ts +0 -67
- package/src/shared/lib/code/editor/line-edits.test.ts +0 -131
- package/src/shared/lib/code/editor/line-edits.ts +0 -159
- package/src/shared/lib/code/editor/occurrences.test.ts +0 -117
- package/src/shared/lib/code/editor/occurrences.ts +0 -111
- package/src/shared/lib/code/editor/reset-css.test.ts +0 -35
- package/src/shared/lib/code/editor/reset-css.ts +0 -32
- package/src/shared/lib/code/editor/text-commands.test.ts +0 -178
- package/src/shared/lib/code/editor/text-commands.ts +0 -154
- package/src/shared/lib/code/lazy-window.test.ts +0 -161
- package/src/shared/lib/code/lazy-window.ts +0 -156
- package/src/shared/lib/code/windowed-highlight.ts +0 -114
- package/src/shared/lib/fs/diff-parser.test.ts +0 -116
- package/src/shared/lib/fs/diff-parser.ts +0 -213
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The code surface's prop contract.
|
|
8
|
+
*
|
|
9
|
+
* Split out of `index.tsx` for the repository's per-file ceiling, and it belongs
|
|
10
|
+
* here anyway: the diff panel, the phone's editor and every test that mounts a
|
|
11
|
+
* surface name these, and importing a prop type from the component module couples
|
|
12
|
+
* them to the mount.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { CSSProperties } from 'preact';
|
|
16
|
+
|
|
17
|
+
import type { ShikiThemeNames } from '@/client/components/common/code-surface/shiki';
|
|
18
|
+
import type { MarkRange } from '@/client/components/common/code-surface/marks';
|
|
19
|
+
import type { EditorCommand } from '@/shared/lib/code/editor/keymap';
|
|
20
|
+
import type { EditorTypingOptions } from '@/client/components/common/code-surface/typing';
|
|
21
|
+
|
|
22
|
+
export interface CodeSurfaceProps {
|
|
23
|
+
value: string;
|
|
24
|
+
onValueChange: (value: string) => void;
|
|
25
|
+
/** Shiki language id, already resolved from the file name. */
|
|
26
|
+
language: string;
|
|
27
|
+
wordWrap: boolean;
|
|
28
|
+
/** Which cached `EditorState` this document owns — a tab switch applies another. */
|
|
29
|
+
documentKey: string;
|
|
30
|
+
/** Find matches (document offsets) to paint; the current one is marked. */
|
|
31
|
+
marks?: readonly MarkRange[];
|
|
32
|
+
currentMark?: number;
|
|
33
|
+
/** Commands the editor does not own (find bar chords, word wrap, save). */
|
|
34
|
+
onCommand?: (command: EditorCommand) => void;
|
|
35
|
+
/** A viewer: both `readOnly` and `editable(false)`, so nothing can write. */
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The editor THEME, as CSS custom properties (`editorThemeVars`).
|
|
39
|
+
*
|
|
40
|
+
* Written on the host element, so the chrome repaints through CSS and a theme
|
|
41
|
+
* switch costs one attribute write. Empty/absent means `auto`: every
|
|
42
|
+
* declaration in `theme.ts` falls back to the app palette.
|
|
43
|
+
*/
|
|
44
|
+
themeVars?: Record<string, string>;
|
|
45
|
+
/** The two Shiki theme names to tokenize with (the same theme twice when the
|
|
46
|
+
* editor theme is explicit). Defaults to the app's dual pair. */
|
|
47
|
+
themes?: ShikiThemeNames;
|
|
48
|
+
/**
|
|
49
|
+
* One indentation level, as a whitespace string (`' '`, `' '`, `'\t'`).
|
|
50
|
+
*
|
|
51
|
+
* The setting reaches the editor through the settings event, not through a prop
|
|
52
|
+
* captured at boot; this is what the owner resolved from it. Defaults to two
|
|
53
|
+
* spaces, which is what the surface hardcoded before the setting existed.
|
|
54
|
+
*/
|
|
55
|
+
indentUnitText?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Auto-close brackets and the document-words completer.
|
|
58
|
+
*
|
|
59
|
+
* Both change what TYPING does, so both are settings; the surface takes the resolved
|
|
60
|
+
* value and reconfigures a compartment when it moves, which keeps an open tab's undo
|
|
61
|
+
* history.
|
|
62
|
+
*/
|
|
63
|
+
typing?: EditorTypingOptions;
|
|
64
|
+
/** Font family / size / line height (the zoom control and the font setting). */
|
|
65
|
+
style?: CSSProperties;
|
|
66
|
+
/** Padding around the document, in px. */
|
|
67
|
+
padding?: number;
|
|
68
|
+
/** `data-testid` for the scroller, so the e2e layer can address it. */
|
|
69
|
+
scrollTestId?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The caret's line and column, reported whenever either moves.
|
|
72
|
+
*
|
|
73
|
+
* Separate from the state the surface caches: a status readout wants two numbers,
|
|
74
|
+
* and keeping an `EditorState` for them would pin a document snapshot in a
|
|
75
|
+
* component that prints its line number.
|
|
76
|
+
*/
|
|
77
|
+
onCaret?: (position: { line: number; column: number }) => void;
|
|
78
|
+
/**
|
|
79
|
+
* The element that actually scrolls, reported on mount and cleared on unmount.
|
|
80
|
+
*
|
|
81
|
+
* It exists only once the view does, and it is CodeMirror's (`view.scrollDOM`)
|
|
82
|
+
* — a caller that needs to remember the reader's position (`useScrollRestore`)
|
|
83
|
+
* cannot reach it through a `ref`, so the surface hands it over.
|
|
84
|
+
*/
|
|
85
|
+
onScroller?: (element: HTMLElement | null) => void;
|
|
86
|
+
className?: string;
|
|
87
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shiki colours for the CodeMirror surface, as a decoration plugin.
|
|
8
|
+
*
|
|
9
|
+
* The app has ONE tokenizer. The chat timeline, the diff views, the wiki reader
|
|
10
|
+
* and the markdown preview all render through `highlightCode`, and the editor
|
|
11
|
+
* must not disagree with them about what a keyword looks like — which is why
|
|
12
|
+
* this is Shiki over CM6's viewport rather than a lezer grammar. A lezer build
|
|
13
|
+
* would cover 48 of the 59 ids `shiki-langs` knows and paint a second palette.
|
|
14
|
+
*
|
|
15
|
+
* Two rules make it affordable on a large file:
|
|
16
|
+
*
|
|
17
|
+
* - **Only the viewport is tokenized**, plus `CONTEXT_LINES` above it so a
|
|
18
|
+
* window that opens inside a block comment or a template literal still
|
|
19
|
+
* tokenizes as one. Measured: 2.1 ms per keystroke at 20 000 lines, flat,
|
|
20
|
+
* because the window is ~100 lines whatever the document is.
|
|
21
|
+
* - **A line at or past `MAX_LINE_CHARS` is left plain.** A minified bundle is
|
|
22
|
+
* one line of hundreds of KB, and tokenizing it on every scroll is what makes
|
|
23
|
+
* an editor feel dead.
|
|
24
|
+
*
|
|
25
|
+
* The colours are NOT inline. Every token carries Shiki's two custom properties
|
|
26
|
+
* (`--shiki-light` / `--shiki-dark`) and `theme.ts` picks one through
|
|
27
|
+
* `[data-theme-variant]`, so a theme switch repaints with zero re-tokenizing —
|
|
28
|
+
* the same property every other surface relies on.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { RangeSetBuilder, type Extension } from '@codemirror/state';
|
|
32
|
+
import { Decoration, ViewPlugin, type DecorationSet, type EditorView, type ViewUpdate } from '@codemirror/view';
|
|
33
|
+
|
|
34
|
+
import { getHighlighterSync, onLanguageReady, onSyntaxReady, requestLanguage } from '@/shared/lib/code/highlighter';
|
|
35
|
+
import { loadEditorTheme, onEditorThemeReady } from '@/shared/lib/code/editor/theme-loader';
|
|
36
|
+
import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
|
|
37
|
+
|
|
38
|
+
/** Lines tokenized above the viewport, to seed the grammar's own state. */
|
|
39
|
+
const CONTEXT_LINES = 40;
|
|
40
|
+
|
|
41
|
+
/** Lines at or above this length render as plain text (see the module note). */
|
|
42
|
+
const MAX_LINE_CHARS = 12_000;
|
|
43
|
+
|
|
44
|
+
/** Marks are shared by their style string: a file has a few dozen distinct ones. */
|
|
45
|
+
const markCache = new Map<string, Decoration>();
|
|
46
|
+
|
|
47
|
+
/** Ceiling on cached marks; a pathological file cannot grow the map forever. */
|
|
48
|
+
const MARK_CACHE_LIMIT = 2_000;
|
|
49
|
+
|
|
50
|
+
function markFor(style: string): Decoration {
|
|
51
|
+
const cached = markCache.get(style);
|
|
52
|
+
if (cached) return cached;
|
|
53
|
+
const mark = Decoration.mark({ class: 'shiki-tok', attributes: { style } });
|
|
54
|
+
if (markCache.size >= MARK_CACHE_LIMIT) markCache.clear();
|
|
55
|
+
markCache.set(style, mark);
|
|
56
|
+
return mark;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `{ '--shiki-light': '#…', '--shiki-dark': '#…' }` as a declaration list. */
|
|
60
|
+
function styleOf(htmlStyle: Record<string, string> | undefined): string | null {
|
|
61
|
+
if (!htmlStyle) return null;
|
|
62
|
+
let style = '';
|
|
63
|
+
for (const key of Object.keys(htmlStyle)) {
|
|
64
|
+
const value = htmlStyle[key];
|
|
65
|
+
if (!value) continue;
|
|
66
|
+
style += `${style ? ';' : ''}${key}:${value}`;
|
|
67
|
+
}
|
|
68
|
+
return style || null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The two theme names a surface tokenizes with. */
|
|
72
|
+
export interface ShikiThemeNames {
|
|
73
|
+
light: string;
|
|
74
|
+
dark: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The app's dual pair, used when a caller names none. */
|
|
78
|
+
const APP_THEMES: ShikiThemeNames = SHIKI_THEMES;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Tokenize the viewport and emit one mark per coloured token.
|
|
82
|
+
*
|
|
83
|
+
* `RangeSetBuilder` requires ascending ranges, which the line walk gives for
|
|
84
|
+
* free: tokens arrive in document order because they are read line by line.
|
|
85
|
+
*/
|
|
86
|
+
function buildDecorations(
|
|
87
|
+
view: EditorView,
|
|
88
|
+
language: string,
|
|
89
|
+
themes: ShikiThemeNames,
|
|
90
|
+
): DecorationSet {
|
|
91
|
+
const highlighter = getHighlighterSync();
|
|
92
|
+
// Not booted yet, or the grammar is still in flight: plain text for this
|
|
93
|
+
// pass, and `subscribe` re-runs the moment either lands.
|
|
94
|
+
if (!highlighter || language === 'text' || !requestLanguage(language)) return Decoration.none;
|
|
95
|
+
|
|
96
|
+
const doc = view.state.doc;
|
|
97
|
+
const firstLine = doc.lineAt(view.viewport.from).number;
|
|
98
|
+
const lastLine = doc.lineAt(view.viewport.to).number;
|
|
99
|
+
const contextStart = Math.max(1, firstLine - CONTEXT_LINES);
|
|
100
|
+
|
|
101
|
+
const lines: string[] = [];
|
|
102
|
+
for (let number = contextStart; number <= lastLine; number++) lines.push(doc.line(number).text);
|
|
103
|
+
const source = lines.join('\n');
|
|
104
|
+
|
|
105
|
+
let tokenized: { content: string; htmlStyle?: Record<string, string> }[][];
|
|
106
|
+
try {
|
|
107
|
+
tokenized = highlighter.codeToTokens(source, {
|
|
108
|
+
lang: language,
|
|
109
|
+
// Shiki's own type is `Partial<Record<string, ThemeRegistrationAny|string>>`;
|
|
110
|
+
// the pair is a plain string map, which is what it accepts at runtime.
|
|
111
|
+
themes: themes as unknown as Record<string, string>,
|
|
112
|
+
defaultColor: false,
|
|
113
|
+
tokenizeMaxLineLength: MAX_LINE_CHARS,
|
|
114
|
+
}).tokens as typeof tokenized;
|
|
115
|
+
} catch {
|
|
116
|
+
// A grammar the engine refuses (or a Shiki internal): plain text is the
|
|
117
|
+
// honest fallback, never a crash that takes the editor down.
|
|
118
|
+
return Decoration.none;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
122
|
+
for (let index = 0; index < tokenized.length && index < lines.length; index++) {
|
|
123
|
+
const line = doc.line(contextStart + index);
|
|
124
|
+
if (line.length >= MAX_LINE_CHARS) continue;
|
|
125
|
+
let offset = 0;
|
|
126
|
+
for (const token of tokenized[index]) {
|
|
127
|
+
const length = token.content.length;
|
|
128
|
+
const style = styleOf(token.htmlStyle);
|
|
129
|
+
if (style && length > 0) {
|
|
130
|
+
const from = line.from + offset;
|
|
131
|
+
const to = Math.min(line.to, from + length);
|
|
132
|
+
if (to > from) builder.add(from, to, markFor(style));
|
|
133
|
+
}
|
|
134
|
+
offset += length;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return builder.finish();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Re-run when the highlighter boots, a grammar lands, or the theme's module
|
|
142
|
+
* arrives.
|
|
143
|
+
*
|
|
144
|
+
* The theme is the third case and it is not optional: an explicit editor theme
|
|
145
|
+
* is a module that is fetched on selection, and `codeToTokens` throws for a
|
|
146
|
+
* theme Shiki has not been given — which the catch below turns into plain text.
|
|
147
|
+
* Without this subscription a freshly picked theme would leave the surface
|
|
148
|
+
* uncoloured until something else forced a rebuild.
|
|
149
|
+
*/
|
|
150
|
+
function subscribe(themes: ShikiThemeNames, onReady: () => void): () => void {
|
|
151
|
+
const offBoot = onSyntaxReady(onReady);
|
|
152
|
+
const offLanguage = onLanguageReady(onReady);
|
|
153
|
+
const wanted = new Set([themes.light, themes.dark]);
|
|
154
|
+
const offTheme = onEditorThemeReady((id) => {
|
|
155
|
+
if (wanted.has(id)) onReady();
|
|
156
|
+
});
|
|
157
|
+
// A theme the app has never loaded: ask now, and the subscription above
|
|
158
|
+
// rebuilds once it lands.
|
|
159
|
+
for (const id of wanted) void loadEditorTheme(id);
|
|
160
|
+
return () => {
|
|
161
|
+
offBoot();
|
|
162
|
+
offLanguage();
|
|
163
|
+
offTheme();
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The decoration plugin for one language and theme.
|
|
169
|
+
*
|
|
170
|
+
* Both are baked in because neither changes under a live state: `documentKey`
|
|
171
|
+
* carries the language (a `.ts` tab and a `.py` tab are two cached states, and
|
|
172
|
+
* two states cannot share decorations built from different grammars), and a
|
|
173
|
+
* theme switch is a CSS repaint — the marks carry both palettes as custom
|
|
174
|
+
* properties, so the values are identical when one theme names both slots.
|
|
175
|
+
*
|
|
176
|
+
* `themes` is optional so a caller that has no editor-theme opinion (a diff
|
|
177
|
+
* card inside a chat message) keeps the app's dual pair.
|
|
178
|
+
*/
|
|
179
|
+
export function shikiHighlight(language: string, themes: ShikiThemeNames = APP_THEMES): Extension {
|
|
180
|
+
return ViewPlugin.fromClass(
|
|
181
|
+
class {
|
|
182
|
+
decorations: DecorationSet;
|
|
183
|
+
private readonly view: EditorView;
|
|
184
|
+
private dirty = false;
|
|
185
|
+
private destroyed = false;
|
|
186
|
+
private readonly unsubscribe: () => void;
|
|
187
|
+
|
|
188
|
+
constructor(view: EditorView) {
|
|
189
|
+
this.view = view;
|
|
190
|
+
this.decorations = buildDecorations(view, language, themes);
|
|
191
|
+
this.unsubscribe = subscribe(themes, () => this.invalidate());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
update(update: ViewUpdate): void {
|
|
195
|
+
// A composition is a document in flux: tokenizing mid-IME paints
|
|
196
|
+
// decorations over text the browser is still composing, and Chrome
|
|
197
|
+
// reacts by moving the caret out from under the user. The rebuild lands
|
|
198
|
+
// on the first update after it ends.
|
|
199
|
+
if (update.view.composing) {
|
|
200
|
+
this.dirty = true;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!update.docChanged && !update.viewportChanged && !this.dirty) return;
|
|
204
|
+
this.dirty = false;
|
|
205
|
+
this.decorations = buildDecorations(update.view, language, themes);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
destroy(): void {
|
|
209
|
+
this.destroyed = true;
|
|
210
|
+
this.unsubscribe();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* A grammar landed: force one rebuild.
|
|
215
|
+
*
|
|
216
|
+
* The empty transaction is the only way a plugin can ask for an update it
|
|
217
|
+
* did not get from a document change — and the `dirty` flag is what makes
|
|
218
|
+
* the rebuild happen even though neither `docChanged` nor
|
|
219
|
+
* `viewportChanged` is set. Guarded, because a chunk can land while the
|
|
220
|
+
* view is being torn down.
|
|
221
|
+
*/
|
|
222
|
+
private invalidate(): void {
|
|
223
|
+
if (this.destroyed) return;
|
|
224
|
+
this.dirty = true;
|
|
225
|
+
try {
|
|
226
|
+
this.view.dispatch({});
|
|
227
|
+
} catch {
|
|
228
|
+
// The view went away between the check and the dispatch.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{ decorations: (plugin) => plugin.decorations },
|
|
233
|
+
);
|
|
234
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Installing a stream language into a LIVE document.
|
|
8
|
+
*
|
|
9
|
+
* The mode is a lazy import, so every document is created without one and gets
|
|
10
|
+
* it later through a compartment reconfigure. Three things must survive that
|
|
11
|
+
* reconfigure, and each is a measured way it could break:
|
|
12
|
+
*
|
|
13
|
+
* - the document itself, or the user's edits are lost;
|
|
14
|
+
* - the undo HISTORY, which is why this is a compartment rather than a new
|
|
15
|
+
* state;
|
|
16
|
+
* - the comment-token PRECEDENCE: `languageDataAt` returns providers in order
|
|
17
|
+
* and the commands take the first, so a mode installed after the manual table
|
|
18
|
+
* would let the manual entry win.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { describe, expect, test } from 'bun:test';
|
|
22
|
+
import type { EditorState } from '@codemirror/state';
|
|
23
|
+
import { toggleComment, undo } from '@codemirror/commands';
|
|
24
|
+
import { StreamLanguage, syntaxTree } from '@codemirror/language';
|
|
25
|
+
import { rust } from '@codemirror/legacy-modes/mode/rust';
|
|
26
|
+
import { shell } from '@codemirror/legacy-modes/mode/shell';
|
|
27
|
+
|
|
28
|
+
import { createDocumentCache } from '@/client/components/common/code-surface/documents';
|
|
29
|
+
import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
|
|
30
|
+
|
|
31
|
+
function cache() {
|
|
32
|
+
return createDocumentCache({
|
|
33
|
+
wordWrap: false,
|
|
34
|
+
readOnly: false,
|
|
35
|
+
themes: SHIKI_THEMES,
|
|
36
|
+
indentUnitText: ' ',
|
|
37
|
+
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
38
|
+
onDocChange: () => {},
|
|
39
|
+
onState: () => {},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('languageEffects', () => {
|
|
44
|
+
test('installs the mode on a live document and leaves the text alone', () => {
|
|
45
|
+
const documents = cache();
|
|
46
|
+
const doc = 'fn f() {\n let s = "}";\n g();\n}\n';
|
|
47
|
+
const state = documents.stateFor('a.ts', 'rust', doc);
|
|
48
|
+
documents.remember('a.ts', state);
|
|
49
|
+
expect(syntaxTree(state).length).toBe(0);
|
|
50
|
+
|
|
51
|
+
const withMode = state.update({
|
|
52
|
+
effects: documents.languageEffects('a.ts', StreamLanguage.define(rust as never)),
|
|
53
|
+
}).state;
|
|
54
|
+
|
|
55
|
+
expect(withMode.doc.toString()).toBe(doc);
|
|
56
|
+
// The tree is what makes pairing token-aware; before the reconfigure there
|
|
57
|
+
// is none at all.
|
|
58
|
+
expect(syntaxTree(withMode).length).toBe(doc.length);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('the undo history survives the reconfigure', () => {
|
|
62
|
+
const documents = cache();
|
|
63
|
+
const state = documents.stateFor('b.ts', 'rust', 'fn f() {}\n');
|
|
64
|
+
documents.remember('b.ts', state);
|
|
65
|
+
|
|
66
|
+
let live = state.update({ changes: { from: 0, insert: '// hi\n' } }).state;
|
|
67
|
+
live = live.update({ effects: documents.languageEffects('b.ts', StreamLanguage.define(rust as never)) }).state;
|
|
68
|
+
expect(live.doc.toString()).toBe('// hi\nfn f() {}\n');
|
|
69
|
+
|
|
70
|
+
let undone = live;
|
|
71
|
+
// `undo` reads the history the state carries; the reconfigure must not have
|
|
72
|
+
// replaced it with an empty one.
|
|
73
|
+
undo({ state: live, dispatch: (transaction) => { undone = transaction.state; } });
|
|
74
|
+
expect(undone.doc.toString()).toBe('fn f() {}\n');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('a key the cache does not hold gets no effects', () => {
|
|
78
|
+
// A tab that closed while the mode was loading must not be resurrected.
|
|
79
|
+
const documents = cache();
|
|
80
|
+
documents.stateFor('open.ts', 'rust', 'x\n');
|
|
81
|
+
expect(documents.languageEffects('closed.ts', StreamLanguage.define(rust as never))).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('comment tokens with a mode installed', () => {
|
|
86
|
+
/** A state from the cache, with a mode reconfigured in. */
|
|
87
|
+
function stateWithMode(language: string, mode: ReturnType<typeof StreamLanguage.define>) {
|
|
88
|
+
const documents = cache();
|
|
89
|
+
const state = documents.stateFor('k.ts', language, 'let a = 1;\n');
|
|
90
|
+
documents.remember('k.ts', state);
|
|
91
|
+
return state.update({ effects: documents.languageEffects('k.ts', mode) }).state;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function toggled(state: EditorState): string {
|
|
95
|
+
let next = state;
|
|
96
|
+
toggleComment({ state, dispatch: (transaction) => { next = transaction.state; } });
|
|
97
|
+
return next.doc.toString();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
test('the mode’s own tokens win, because the compartment is installed first', () => {
|
|
101
|
+
// The manual table says `//` for a `typescript` path; the Rust mode says
|
|
102
|
+
// `//` too, so the assertion is on the DATA order rather than the output.
|
|
103
|
+
const state = stateWithMode('typescript', StreamLanguage.define(rust as never));
|
|
104
|
+
const tokens = state.languageDataAt('commentTokens', 0);
|
|
105
|
+
// Two providers, and the mode's is first — which is the ordering the
|
|
106
|
+
// commands rely on.
|
|
107
|
+
expect(tokens.length).toBe(2);
|
|
108
|
+
expect(tokens[0]).toEqual({ line: '//', block: { open: '/*', close: '*/' } });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('a shell mode comments with # rather than the path’s //', () => {
|
|
112
|
+
// `bash` maps to the shell mode, whose token is `#`. Before the mode is
|
|
113
|
+
// installed the manual table already says `#` for bash, so this pins that
|
|
114
|
+
// the two agree rather than which one won.
|
|
115
|
+
const state = stateWithMode('bash', StreamLanguage.define(shell as never));
|
|
116
|
+
expect(toggled(state)).toBe('# let a = 1;\n');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Loading a stream mode on demand, and telling the surface when it lands.
|
|
8
|
+
*
|
|
9
|
+
* The mode table is 49 entries but the modules behind them are lazy for the same
|
|
10
|
+
* reason `LANG_LOADERS` is: all 38 modes in one bundle is +85 KB gzip, and a tab
|
|
11
|
+
* opened on a README should pay for none of it. A mode is fetched the first time
|
|
12
|
+
* a document in that language is opened.
|
|
13
|
+
*
|
|
14
|
+
* The notification exists because a `StreamLanguage` is a COMPARTMENT payload:
|
|
15
|
+
* the surface mounts with none, and the tree (and therefore token-aware bracket
|
|
16
|
+
* matching) only exists after the reconfigure. Without the signal a file would
|
|
17
|
+
* keep the textual matcher for its whole life, with nothing on screen to say a
|
|
18
|
+
* better answer was available.
|
|
19
|
+
*
|
|
20
|
+
* Shaped after `theme-loader.ts`, deliberately: same per-process registry on a
|
|
21
|
+
* module-level map, same in-flight dedupe, same "never reject" contract — a mode
|
|
22
|
+
* that fails to load leaves the textual matcher, which is a worse answer rather
|
|
23
|
+
* than a broken editor.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { StreamLanguage } from '@codemirror/language';
|
|
27
|
+
import { streamModeLoader, STREAM_MODE_EXPORTS } from '@/shared/lib/code/editor/stream-modes';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A defined stream language — the CM6 extension a mode becomes.
|
|
31
|
+
*
|
|
32
|
+
* Named here rather than spelled `ReturnType<typeof StreamLanguage.define>`
|
|
33
|
+
* because the type argument is what a consumer holds; the alias keeps the
|
|
34
|
+
* generic out of every call site.
|
|
35
|
+
*/
|
|
36
|
+
export type StreamLanguageInstance = StreamLanguage<unknown>;
|
|
37
|
+
|
|
38
|
+
/** Ids whose mode is loaded and ready to install. */
|
|
39
|
+
const loaded = new Map<string, StreamLanguageInstance>();
|
|
40
|
+
/** In-flight loads, so two surfaces on one language share a fetch. */
|
|
41
|
+
const pending = new Map<string, Promise<StreamLanguageInstance | null>>();
|
|
42
|
+
const listeners = new Set<(language: string) => void>();
|
|
43
|
+
|
|
44
|
+
function notifyReady(language: string): void {
|
|
45
|
+
for (const listener of [...listeners]) {
|
|
46
|
+
try {
|
|
47
|
+
listener(language);
|
|
48
|
+
} catch {
|
|
49
|
+
// A listener must never break the others.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fires when a mode lands, so a surface that mounted without it can reconfigure.
|
|
56
|
+
*
|
|
57
|
+
* Keyed by SHIKI id, not by mode name: that is what the surface holds.
|
|
58
|
+
*/
|
|
59
|
+
export function onStreamModeReady(listener: (language: string) => void): () => void {
|
|
60
|
+
listeners.add(listener);
|
|
61
|
+
return () => {
|
|
62
|
+
listeners.delete(listener);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The mode for `language` if it is already loaded, else null. */
|
|
67
|
+
export function readyStreamMode(language: string): StreamLanguageInstance | null {
|
|
68
|
+
return loaded.get(language) ?? null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Load and register the mode for a Shiki id.
|
|
73
|
+
*
|
|
74
|
+
* Resolves `null` for a language this build has no mode for (the honest answer
|
|
75
|
+
* for markdown, html, graphql, …) and for one whose module fails to load. Never
|
|
76
|
+
* rejects: the caller keeps the textual matcher.
|
|
77
|
+
*/
|
|
78
|
+
export function loadStreamMode(language: string): Promise<StreamLanguageInstance | null> {
|
|
79
|
+
const ready = loaded.get(language);
|
|
80
|
+
if (ready) return Promise.resolve(ready);
|
|
81
|
+
|
|
82
|
+
const inFlight = pending.get(language);
|
|
83
|
+
if (inFlight) return inFlight;
|
|
84
|
+
|
|
85
|
+
const loader = streamModeLoader(language);
|
|
86
|
+
const exportName = STREAM_MODE_EXPORTS[language];
|
|
87
|
+
if (!loader || !exportName) return Promise.resolve(null);
|
|
88
|
+
|
|
89
|
+
const load = (async () => {
|
|
90
|
+
try {
|
|
91
|
+
const [module, languageModule] = await Promise.all([
|
|
92
|
+
// The LOADER, not a template specifier: a template literal builds but
|
|
93
|
+
// never resolves at runtime in the dev server (measured — the mode
|
|
94
|
+
// silently failed to load and the surface stayed textual).
|
|
95
|
+
loader(),
|
|
96
|
+
import('@codemirror/language'),
|
|
97
|
+
]);
|
|
98
|
+
const mode = (module as Record<string, unknown>)[exportName];
|
|
99
|
+
if (!mode) return null;
|
|
100
|
+
// `StreamLanguage.define` is the only constructor; the mode object alone is
|
|
101
|
+
// not an extension.
|
|
102
|
+
const instance = languageModule.StreamLanguage.define(mode as never);
|
|
103
|
+
loaded.set(language, instance);
|
|
104
|
+
notifyReady(language);
|
|
105
|
+
return instance;
|
|
106
|
+
} catch {
|
|
107
|
+
// Left out of `loaded`, so a later attempt can still succeed.
|
|
108
|
+
return null;
|
|
109
|
+
} finally {
|
|
110
|
+
pending.delete(language);
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
|
|
114
|
+
pending.set(language, load);
|
|
115
|
+
return load;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Test seam: forget every registration. */
|
|
119
|
+
export function resetStreamModes(): void {
|
|
120
|
+
loaded.clear();
|
|
121
|
+
pending.clear();
|
|
122
|
+
listeners.clear();
|
|
123
|
+
}
|