@kabmo-labs/kabmo 0.11.1 → 0.12.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 +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Merge-conflict markers, painted where the reader actually meets them.
|
|
8
|
+
*
|
|
9
|
+
* The diff panel has known about conflicts since `ConflictBanner`, but the
|
|
10
|
+
* EDITOR — where a conflict is resolved by hand — showed `<<<<<<< HEAD` as an
|
|
11
|
+
* ordinary line of text. A reader scrolling a conflicted file had no signal that
|
|
12
|
+
* the block under the caret was two versions of the same code.
|
|
13
|
+
*
|
|
14
|
+
* ## `=======` is deliberately not painted
|
|
15
|
+
*
|
|
16
|
+
* A bare seven-`=` line is also a Markdown setext underline and appears in ASCII
|
|
17
|
+
* banners — including this repository's own comment headers. Painting every one
|
|
18
|
+
* of them would put a conflict band in files that have no conflict, which is
|
|
19
|
+
* worse than painting nothing: the three markers below are unambiguous, and a
|
|
20
|
+
* block is still legible without its separator.
|
|
21
|
+
*
|
|
22
|
+
* ## A viewport walk, not `MatchDecorator`
|
|
23
|
+
*
|
|
24
|
+
* The band has to be a LINE decoration, and a line decoration must be added at
|
|
25
|
+
* `line.from` with an EMPTY range. `MatchDecorator` adds whatever its callback
|
|
26
|
+
* returns over the MATCHED RANGE, so a `Decoration.line` coming out of it is
|
|
27
|
+
* placed over `<<<<<<< HEAD`'s seven-to-twelve characters — measured in a real
|
|
28
|
+
* browser: the marker lines rendered as blank rows (`<br>`) while the document
|
|
29
|
+
* still held their text, i.e. the line's content was swallowed by a decoration
|
|
30
|
+
* that should not have covered it.
|
|
31
|
+
*
|
|
32
|
+
* The walk below is the shape `indent-guide.ts` uses: visible lines only,
|
|
33
|
+
* rebuilt on scroll and on edit, so a 20 MB file costs the viewport.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import type { Range } from '@codemirror/state';
|
|
37
|
+
import { Decoration, EditorView, ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
|
|
38
|
+
|
|
39
|
+
/** The marker that opens a block. Its count is the file's conflict count. */
|
|
40
|
+
export const OURS_MARK = '<<<<<<<';
|
|
41
|
+
|
|
42
|
+
/** diff3's base section header. */
|
|
43
|
+
export const BASE_MARK = '|||||||';
|
|
44
|
+
|
|
45
|
+
/** The marker that closes a block. */
|
|
46
|
+
export const THEIRS_MARK = '>>>>>>>';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* One of the three unambiguous markers, alone on its line apart from an optional
|
|
50
|
+
* label (`<<<<<<< HEAD`, `>>>>>>> feature/x`).
|
|
51
|
+
*/
|
|
52
|
+
const MARKER_LINE = /^(?:<{7}|\|{7}|>{7})(?: .*)?$/;
|
|
53
|
+
|
|
54
|
+
const OURS_LINE = Decoration.line({ class: 'cm-conflict-ours' });
|
|
55
|
+
const BASE_LINE = Decoration.line({ class: 'cm-conflict-base' });
|
|
56
|
+
const THEIRS_LINE = Decoration.line({ class: 'cm-conflict-theirs' });
|
|
57
|
+
|
|
58
|
+
/** The band a line's text calls for, or null for every other line. */
|
|
59
|
+
function markerDecorationFor(text: string): Decoration | null {
|
|
60
|
+
if (!MARKER_LINE.test(text)) return null;
|
|
61
|
+
if (text.startsWith(BASE_MARK)) return BASE_LINE;
|
|
62
|
+
if (text.startsWith(THEIRS_MARK)) return THEIRS_LINE;
|
|
63
|
+
return OURS_LINE;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The bands for the lines currently rendered. */
|
|
67
|
+
function buildMarkers(view: EditorView): DecorationSet {
|
|
68
|
+
const ranges: Range<Decoration>[] = [];
|
|
69
|
+
for (const { from, to } of view.visibleRanges) {
|
|
70
|
+
let position = from;
|
|
71
|
+
while (position <= to) {
|
|
72
|
+
const line = view.state.doc.lineAt(position);
|
|
73
|
+
const decoration = markerDecorationFor(line.text);
|
|
74
|
+
// `Decoration.line` is a LINE decoration: one per line, at its own start,
|
|
75
|
+
// and the set must be sorted — which walking the document already gives.
|
|
76
|
+
if (decoration) ranges.push(decoration.range(line.from));
|
|
77
|
+
if (line.to === position && line.to === view.state.doc.length) break;
|
|
78
|
+
position = line.to + 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return Decoration.set(ranges, true);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The marker bands, as a view plugin.
|
|
86
|
+
*
|
|
87
|
+
* A plugin rather than a state field for the same reason `indentGuides` is: the
|
|
88
|
+
* bands are derived from what is RENDERED, so a scroll has to rebuild them, and
|
|
89
|
+
* a field would hold a decoration set the document does not own.
|
|
90
|
+
*/
|
|
91
|
+
export function conflictMarkers() {
|
|
92
|
+
return ViewPlugin.fromClass(
|
|
93
|
+
class {
|
|
94
|
+
decorations: DecorationSet;
|
|
95
|
+
|
|
96
|
+
constructor(view: EditorView) {
|
|
97
|
+
this.decorations = buildMarkers(view);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
update(update: ViewUpdate) {
|
|
101
|
+
if (update.docChanged || update.viewportChanged) {
|
|
102
|
+
this.decorations = buildMarkers(update.view);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{ decorations: (plugin) => plugin.decorations },
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether the text holds at least one opening conflict marker at a line start.
|
|
112
|
+
*
|
|
113
|
+
* One scan with `indexOf`, stopping at the first hit: this runs before every
|
|
114
|
+
* parse of a config file, so the common case — a file with no conflict — has to
|
|
115
|
+
* be one native search rather than a pattern match over the whole buffer.
|
|
116
|
+
*/
|
|
117
|
+
export function hasConflictMarker(text: string): boolean {
|
|
118
|
+
let index = text.indexOf(OURS_MARK);
|
|
119
|
+
while (index !== -1) {
|
|
120
|
+
if (index === 0 || text.charCodeAt(index - 1) === 10) return true;
|
|
121
|
+
index = text.indexOf(OURS_MARK, index + OURS_MARK.length);
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* How many conflict blocks the text holds.
|
|
128
|
+
*
|
|
129
|
+
* Counted with `indexOf` rather than a regex because this runs from a status
|
|
130
|
+
* readout on every render, and the honest answer for the common case — a file
|
|
131
|
+
* with no conflict at all — has to be one native scan, not a pattern match over
|
|
132
|
+
* the whole buffer.
|
|
133
|
+
*/
|
|
134
|
+
export function countConflicts(text: string): number {
|
|
135
|
+
let count = 0;
|
|
136
|
+
let index = text.indexOf(OURS_MARK);
|
|
137
|
+
while (index !== -1) {
|
|
138
|
+
// A marker is a LINE start, not any occurrence: `"a <<<<<<< b"` is a string
|
|
139
|
+
// literal, not a conflict.
|
|
140
|
+
if (index === 0 || text.charCodeAt(index - 1) === 10) count++;
|
|
141
|
+
index = text.indexOf(OURS_MARK, index + OURS_MARK.length);
|
|
142
|
+
}
|
|
143
|
+
return count;
|
|
144
|
+
}
|
|
@@ -39,6 +39,14 @@ const MAX_CACHED = 12;
|
|
|
39
39
|
export interface SurfaceOptions {
|
|
40
40
|
wordWrap: boolean;
|
|
41
41
|
readOnly: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The blame extension, or null when the panel has it off.
|
|
44
|
+
*
|
|
45
|
+
* Part of the live options because the toggle can be pressed while a
|
|
46
|
+
* document is open: a re-mount would drop the tab's undo history for a
|
|
47
|
+
* reading aid. Absent and `null` both mean off.
|
|
48
|
+
*/
|
|
49
|
+
blame?: Extension | null;
|
|
42
50
|
/**
|
|
43
51
|
* One indentation level, as a whitespace string.
|
|
44
52
|
*
|
|
@@ -64,6 +72,14 @@ export interface SurfaceOptions {
|
|
|
64
72
|
* per theme would throw away every open tab's undo history on a colour change.
|
|
65
73
|
*/
|
|
66
74
|
themes: ShikiThemeNames;
|
|
75
|
+
/**
|
|
76
|
+
* Text drawn while a document is empty, or absent for none.
|
|
77
|
+
*
|
|
78
|
+
* Creation-time rather than a compartment: it is a constant per call site
|
|
79
|
+
* ("This file is empty"), so a reconfigure path for it would be a transaction
|
|
80
|
+
* nobody dispatches.
|
|
81
|
+
*/
|
|
82
|
+
placeholder?: string;
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
export interface DocumentCacheDeps extends SurfaceOptions {
|
|
@@ -121,11 +137,14 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
121
137
|
const options: SurfaceOptions = {
|
|
122
138
|
wordWrap: deps.wordWrap,
|
|
123
139
|
readOnly: deps.readOnly,
|
|
140
|
+
blame: deps.blame ?? null,
|
|
124
141
|
themes: deps.themes,
|
|
125
142
|
indentUnitText: deps.indentUnitText,
|
|
126
143
|
typing: deps.typing,
|
|
144
|
+
placeholder: deps.placeholder,
|
|
127
145
|
};
|
|
128
146
|
const wordWrapCompartment = new Compartment();
|
|
147
|
+
const blameCompartment = new Compartment();
|
|
129
148
|
const readOnlyCompartment = new Compartment();
|
|
130
149
|
const indentCompartment = new Compartment();
|
|
131
150
|
const typingCompartment = new Compartment();
|
|
@@ -159,6 +178,15 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
159
178
|
* for nothing on a file with a large gutter.
|
|
160
179
|
*/
|
|
161
180
|
const indentByKey = new Map<string, string>();
|
|
181
|
+
/**
|
|
182
|
+
* The blame extension each cached state currently holds.
|
|
183
|
+
*
|
|
184
|
+
* Tracked for the same reason as `themesByKey`: `currentEffects` runs on every
|
|
185
|
+
* tab switch, and reconfiguring a compartment with the value it already has
|
|
186
|
+
* costs a transaction for nothing — here it would also re-create the label
|
|
187
|
+
* plugin, which rebuilds every decoration on the viewport.
|
|
188
|
+
*/
|
|
189
|
+
const blameByKey = new Map<string, Extension | null>();
|
|
162
190
|
|
|
163
191
|
const extensionsFor = (language: string): Extension[] =>
|
|
164
192
|
surfaceExtensions({
|
|
@@ -169,6 +197,8 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
169
197
|
languageCompartment,
|
|
170
198
|
indentCompartment,
|
|
171
199
|
typingCompartment,
|
|
200
|
+
blameCompartment,
|
|
201
|
+
blame: options.blame ?? null,
|
|
172
202
|
onCommand: deps.onCommand,
|
|
173
203
|
onDocChange: deps.onDocChange,
|
|
174
204
|
onState: deps.onState,
|
|
@@ -202,6 +232,7 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
202
232
|
languages.set(key, language);
|
|
203
233
|
themesByKey.set(key, options.themes);
|
|
204
234
|
indentByKey.set(key, options.indentUnitText);
|
|
235
|
+
blameByKey.set(key, options.blame ?? null);
|
|
205
236
|
evict();
|
|
206
237
|
return state;
|
|
207
238
|
},
|
|
@@ -215,11 +246,14 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
215
246
|
languages.delete(key);
|
|
216
247
|
themesByKey.delete(key);
|
|
217
248
|
indentByKey.delete(key);
|
|
249
|
+
blameByKey.delete(key);
|
|
218
250
|
},
|
|
219
251
|
|
|
220
252
|
optionsEffects(next, key) {
|
|
221
253
|
const wrapChanged = next.wordWrap !== options.wordWrap;
|
|
222
254
|
const readOnlyChanged = next.readOnly !== options.readOnly;
|
|
255
|
+
const nextBlame = next.blame ?? null;
|
|
256
|
+
const blameChanged = nextBlame !== options.blame;
|
|
223
257
|
const indentChanged = next.indentUnitText !== options.indentUnitText;
|
|
224
258
|
const typingChanged =
|
|
225
259
|
next.typing.autoCloseBrackets !== options.typing.autoCloseBrackets ||
|
|
@@ -227,11 +261,17 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
227
261
|
const themeChanged = next.themes.light !== options.themes.light || next.themes.dark !== options.themes.dark;
|
|
228
262
|
options.wordWrap = next.wordWrap;
|
|
229
263
|
options.readOnly = next.readOnly;
|
|
264
|
+
options.blame = nextBlame;
|
|
230
265
|
options.themes = next.themes;
|
|
231
266
|
options.indentUnitText = next.indentUnitText;
|
|
232
267
|
options.typing = next.typing;
|
|
233
268
|
const effects: StateEffect<unknown>[] = [];
|
|
234
269
|
if (wrapChanged) effects.push(wordWrapCompartment.reconfigure(wrapExtension(options.wordWrap)));
|
|
270
|
+
// A reading aid, so the same rule as wrap: reconfigure, never re-mount.
|
|
271
|
+
if (blameChanged) {
|
|
272
|
+
effects.push(blameCompartment.reconfigure(options.blame ?? []));
|
|
273
|
+
if (key) blameByKey.set(key, options.blame ?? null);
|
|
274
|
+
}
|
|
235
275
|
if (readOnlyChanged) effects.push(readOnlyCompartment.reconfigure(readOnlyExtension(options.readOnly)));
|
|
236
276
|
// The indent unit AND the tab size move together: a tab-indented setting is
|
|
237
277
|
// one column wide as a unit, and `getIndentUnit` reads `tabSize` to measure
|
|
@@ -258,8 +298,15 @@ export function createDocumentCache(deps: DocumentCacheDeps): DocumentCache {
|
|
|
258
298
|
const effects: StateEffect<unknown>[] = [
|
|
259
299
|
wordWrapCompartment.reconfigure(wrapExtension(options.wordWrap)),
|
|
260
300
|
readOnlyCompartment.reconfigure(readOnlyExtension(options.readOnly)),
|
|
261
|
-
|
|
262
301
|
];
|
|
302
|
+
// A cached state carries the configuration it was CREATED with, so a tab
|
|
303
|
+
// opened before the toggle was pressed would come back with the other
|
|
304
|
+
// answer for its whole life.
|
|
305
|
+
const blame = options.blame ?? null;
|
|
306
|
+
if (key && blameByKey.get(key) !== blame) {
|
|
307
|
+
effects.push(blameCompartment.reconfigure(blame ?? []));
|
|
308
|
+
blameByKey.set(key, blame);
|
|
309
|
+
}
|
|
263
310
|
const language = key ? languages.get(key) : undefined;
|
|
264
311
|
// A cached state carries the unit it was CREATED with, so a tab opened before
|
|
265
312
|
// the setting changed would indent by the old width for its whole life.
|
|
@@ -34,6 +34,10 @@ function stateFor(language: string, doc = 'const alpha = 1;\n') {
|
|
|
34
34
|
languageCompartment: new Compartment(),
|
|
35
35
|
indentCompartment: new Compartment(),
|
|
36
36
|
typingCompartment: new Compartment(),
|
|
37
|
+
// This stack is about folding/indent, not blame: the option is `null` so the
|
|
38
|
+
// compartment is present and off, which is what the surface ships by default.
|
|
39
|
+
blameCompartment: new Compartment(),
|
|
40
|
+
blame: null,
|
|
37
41
|
indentUnitText: ' ',
|
|
38
42
|
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
39
43
|
wordWrap: false,
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
highlightActiveLineGutter,
|
|
43
43
|
highlightSpecialChars,
|
|
44
44
|
lineNumbers,
|
|
45
|
+
placeholder as placeholderExtension,
|
|
45
46
|
rectangularSelection,
|
|
46
47
|
scrollPastEnd,
|
|
47
48
|
} from '@codemirror/view';
|
|
@@ -60,6 +61,9 @@ import { findMarksField } from '@/client/components/common/code-surface/marks';
|
|
|
60
61
|
import { surfaceKeymap } from '@/client/components/common/code-surface/keymap';
|
|
61
62
|
import { shikiHighlight, type ShikiThemeNames } from '@/client/components/common/code-surface/shiki';
|
|
62
63
|
import { surfaceTheme } from '@/client/components/common/code-surface/theme';
|
|
64
|
+
import { conflictMarkers } from '@/client/components/common/code-surface/conflict-markers';
|
|
65
|
+
import { lintExtensions } from '@/client/components/common/code-surface/lint';
|
|
66
|
+
import { reportEditorError } from '@/client/lib/editor-errors';
|
|
63
67
|
|
|
64
68
|
/**
|
|
65
69
|
* The indentation facets, in one extension.
|
|
@@ -151,6 +155,17 @@ export interface SurfaceExtensionsOptions {
|
|
|
151
155
|
indentUnitText: string;
|
|
152
156
|
/** Panel-owned commands the editor delegates instead of running. */
|
|
153
157
|
onCommand?: (command: EditorCommand) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Line blame: the labels, the field they read and the card — or null.
|
|
160
|
+
*
|
|
161
|
+
* One extension value rather than a set of options, because the three are one
|
|
162
|
+
* feature and the surface has nothing to decide about them. `null` is "off",
|
|
163
|
+
* which is the default: the blame costs a server read per file, so it is
|
|
164
|
+
* opt-in.
|
|
165
|
+
*/
|
|
166
|
+
blame?: Extension | null;
|
|
167
|
+
/** Compartment holding the blame extension, so the toggle is a reconfigure. */
|
|
168
|
+
blameCompartment: Compartment;
|
|
154
169
|
/** Fired for every user edit, with the whole new document. */
|
|
155
170
|
onDocChange: (value: string) => void;
|
|
156
171
|
/** Fired on every state that must be remembered (an edit or a selection move). */
|
|
@@ -164,6 +179,14 @@ export interface SurfaceExtensionsOptions {
|
|
|
164
179
|
* would pin a whole document snapshot in a component that prints its line number.
|
|
165
180
|
*/
|
|
166
181
|
onCaret?: (position: { line: number; column: number }) => void;
|
|
182
|
+
/**
|
|
183
|
+
* Text shown while the document is empty, or absent for none.
|
|
184
|
+
*
|
|
185
|
+
* A file that exists and holds nothing is a different fact from "no file is
|
|
186
|
+
* open" (which the panel's `EmptyEditor` draws), and a blank surface said
|
|
187
|
+
* neither: it looked like a read that had not finished.
|
|
188
|
+
*/
|
|
189
|
+
placeholder?: string;
|
|
167
190
|
}
|
|
168
191
|
|
|
169
192
|
/** Everything the editor needs, built once per document state. */
|
|
@@ -180,10 +203,13 @@ export function surfaceExtensions({
|
|
|
180
203
|
themes,
|
|
181
204
|
typing,
|
|
182
205
|
indentUnitText,
|
|
206
|
+
blame,
|
|
207
|
+
blameCompartment,
|
|
183
208
|
onCommand,
|
|
184
209
|
onDocChange,
|
|
185
210
|
onState,
|
|
186
211
|
onCaret,
|
|
212
|
+
placeholder,
|
|
187
213
|
}: SurfaceExtensionsOptions): Extension[] {
|
|
188
214
|
return [
|
|
189
215
|
lineNumbers(),
|
|
@@ -240,6 +266,13 @@ export function surfaceExtensions({
|
|
|
240
266
|
// Auto-close brackets and the completer. Empty when both settings are off, which is
|
|
241
267
|
// why this is a spread rather than a condition at the call site.
|
|
242
268
|
typingCompartment.of(typingExtensions(typing)),
|
|
269
|
+
// The parser's verdict for a config format, and the gutter that marks it.
|
|
270
|
+
// Empty for every other language, which is why this is a spread.
|
|
271
|
+
...lintExtensions(language),
|
|
272
|
+
// Merge-conflict markers, painted where a reader resolving one by hand
|
|
273
|
+
// meets them. Viewport-scoped, so an unconflicted file pays one scan of the
|
|
274
|
+
// visible lines and nothing else.
|
|
275
|
+
conflictMarkers(),
|
|
243
276
|
findMarksField,
|
|
244
277
|
// Bracket matching, plus the vertical guide from the caret's brace to its
|
|
245
278
|
// pair. With a stream language loaded the pairing is token-aware; without
|
|
@@ -257,6 +290,11 @@ export function surfaceExtensions({
|
|
|
257
290
|
foldGutter(),
|
|
258
291
|
themeCompartment.of(shikiHighlight(language, themes)),
|
|
259
292
|
surfaceTheme(),
|
|
293
|
+
// Line blame, when the panel turned it on: the labels, the state field they
|
|
294
|
+
// read, and the card. In a compartment because the toggle can be pressed
|
|
295
|
+
// while a document is open, and a reconfigure keeps its undo history —
|
|
296
|
+
// `null` is the off state, and CM6 wants an empty list for it.
|
|
297
|
+
blameCompartment.of(blame ?? []),
|
|
260
298
|
wordWrapCompartment.of(wrapExtension(wordWrap)),
|
|
261
299
|
readOnlyCompartment.of(readOnlyExtension(readOnly)),
|
|
262
300
|
// The browser's own spellchecker underlines every identifier and offers to
|
|
@@ -291,5 +329,11 @@ export function surfaceExtensions({
|
|
|
291
329
|
}
|
|
292
330
|
}),
|
|
293
331
|
surfaceKeymap(onCommand, readOnly),
|
|
332
|
+
// An empty document says so, rather than looking like a read still running.
|
|
333
|
+
placeholder ? placeholderExtension(placeholder) : [],
|
|
334
|
+
// A plugin that throws is caught by CodeMirror and, by default, only reaches
|
|
335
|
+
// the console — which in a diagnostic workbench is a feature that silently
|
|
336
|
+
// stopped drawing. `reportEditorError` dedupes and raises a toast.
|
|
337
|
+
EditorView.exceptionSink.of((error) => reportEditorError(error)),
|
|
294
338
|
];
|
|
295
339
|
}
|
|
@@ -72,6 +72,10 @@ function stateFor(language: string, doc: string, readOnly = false): EditorState
|
|
|
72
72
|
languageCompartment: new Compartment(),
|
|
73
73
|
indentCompartment: new Compartment(),
|
|
74
74
|
typingCompartment: new Compartment(),
|
|
75
|
+
// This stack is about folding/indent, not blame: the option is `null` so the
|
|
76
|
+
// compartment is present and off, which is what the surface ships by default.
|
|
77
|
+
blameCompartment: new Compartment(),
|
|
78
|
+
blame: null,
|
|
75
79
|
indentUnitText: ' ',
|
|
76
80
|
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
77
81
|
wordWrap: false,
|
|
@@ -38,6 +38,7 @@ interface SurfaceCompartments {
|
|
|
38
38
|
languageCompartment: Compartment;
|
|
39
39
|
indentCompartment: Compartment;
|
|
40
40
|
typingCompartment: Compartment;
|
|
41
|
+
blameCompartment: Compartment;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
interface Built {
|
|
@@ -54,10 +55,14 @@ async function build(language: string): Promise<Built> {
|
|
|
54
55
|
languageCompartment: new Compartment(),
|
|
55
56
|
indentCompartment: new Compartment(),
|
|
56
57
|
typingCompartment: new Compartment(),
|
|
58
|
+
blameCompartment: new Compartment(),
|
|
57
59
|
};
|
|
58
60
|
const extensions: Extension[] = surfaceExtensions({
|
|
59
61
|
language,
|
|
60
62
|
...compartments,
|
|
63
|
+
// This stack is about indent, not blame: the compartment is present and
|
|
64
|
+
// off, which is what the surface ships by default.
|
|
65
|
+
blame: null,
|
|
61
66
|
wordWrap: true,
|
|
62
67
|
readOnly: false,
|
|
63
68
|
themes: SHIKI_THEMES,
|
|
@@ -33,6 +33,7 @@ import { useImperativeHandle, useLayoutEffect, useRef } from 'preact/hooks';
|
|
|
33
33
|
import { forwardRef } from 'preact/compat';
|
|
34
34
|
import type { CSSProperties } from 'preact';
|
|
35
35
|
import { EditorView } from '@codemirror/view';
|
|
36
|
+
import type { Extension } from '@codemirror/state';
|
|
36
37
|
|
|
37
38
|
import { createDocumentCache, type DocumentCache } from '@/client/components/common/code-surface/documents';
|
|
38
39
|
import type { ShikiThemeNames } from '@/client/components/common/code-surface/shiki';
|
|
@@ -62,9 +63,11 @@ export const CodeSurface = forwardRef<CodeSurfaceHandle, CodeSurfaceProps>(funct
|
|
|
62
63
|
themes,
|
|
63
64
|
indentUnitText = ' ',
|
|
64
65
|
typing = DEFAULT_EDITOR_TYPING,
|
|
66
|
+
blame = null,
|
|
65
67
|
style,
|
|
66
68
|
padding = 16,
|
|
67
69
|
onCaret,
|
|
70
|
+
placeholder,
|
|
68
71
|
scrollTestId,
|
|
69
72
|
onScroller,
|
|
70
73
|
className,
|
|
@@ -124,6 +127,15 @@ export const CodeSurface = forwardRef<CodeSurfaceHandle, CodeSurfaceProps>(funct
|
|
|
124
127
|
indentRef.current = indentUnitText;
|
|
125
128
|
const typingRef = useRef(typing);
|
|
126
129
|
typingRef.current = typing;
|
|
130
|
+
/**
|
|
131
|
+
* The blame extension, mirrored for the cache's first build.
|
|
132
|
+
*
|
|
133
|
+
* Its IDENTITY is the toggle: the owner builds it with `useMemo`, so pressing
|
|
134
|
+
* the button hands over a different value and the effect below reconfigures
|
|
135
|
+
* the compartment instead of re-mounting the view.
|
|
136
|
+
*/
|
|
137
|
+
const blameRef = useRef<Extension | null>(blame);
|
|
138
|
+
blameRef.current = blame;
|
|
127
139
|
|
|
128
140
|
// One cache for the component's life: it owns the per-document states.
|
|
129
141
|
const cacheRef = useRef<DocumentCache | null>(null);
|
|
@@ -134,6 +146,8 @@ export const CodeSurface = forwardRef<CodeSurfaceHandle, CodeSurfaceProps>(funct
|
|
|
134
146
|
themes: themesRef.current,
|
|
135
147
|
indentUnitText: indentRef.current,
|
|
136
148
|
typing: typingRef.current,
|
|
149
|
+
blame: blameRef.current,
|
|
150
|
+
placeholder,
|
|
137
151
|
onDocChange: (next) => {
|
|
138
152
|
// Recorded BEFORE the writing guard: this is what the document holds,
|
|
139
153
|
// whether or not the change came from the user.
|
|
@@ -235,11 +249,11 @@ export const CodeSurface = forwardRef<CodeSurfaceHandle, CodeSurfaceProps>(funct
|
|
|
235
249
|
const cache = cacheRef.current;
|
|
236
250
|
if (!view || !cache) return;
|
|
237
251
|
const effects = cache.optionsEffects(
|
|
238
|
-
{ wordWrap, readOnly, themes: activeThemes, indentUnitText, typing },
|
|
252
|
+
{ wordWrap, readOnly, themes: activeThemes, indentUnitText, typing, blame },
|
|
239
253
|
docKeyRef.current,
|
|
240
254
|
);
|
|
241
255
|
if (effects.length > 0) view.dispatch({ effects });
|
|
242
|
-
}, [wordWrap, readOnly, activeThemes.light, activeThemes.dark, indentUnitText, typing]);
|
|
256
|
+
}, [wordWrap, readOnly, activeThemes.light, activeThemes.dark, indentUnitText, typing, blame]);
|
|
243
257
|
|
|
244
258
|
/**
|
|
245
259
|
* The stream language: fetched for this document's language, installed when it
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Lint parsers: the range each format's error actually points at.
|
|
8
|
+
*
|
|
9
|
+
* The value of this feature is the POSITION — a squiggle on line 1 for a
|
|
10
|
+
* trailing comma on line 40 is the "your JSON is broken somewhere" message the
|
|
11
|
+
* editor already gave by doing nothing. Each format reports differently
|
|
12
|
+
* (jsonc-parser speaks offsets, YAML speaks `[start, end]`, TOML speaks a 1-based
|
|
13
|
+
* line and column), so the conversion is what these cases pin.
|
|
14
|
+
*
|
|
15
|
+
* The parsers load through `import()`, so every case is async.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, expect, test } from 'bun:test';
|
|
19
|
+
|
|
20
|
+
import { parseProblems, parserKindFor } from '@/client/components/common/code-surface/lint-parsers';
|
|
21
|
+
|
|
22
|
+
describe('parserKindFor', () => {
|
|
23
|
+
test('the three config formats are linted', () => {
|
|
24
|
+
expect(parserKindFor('json')).toBe('json');
|
|
25
|
+
expect(parserKindFor('yaml')).toBe('yaml');
|
|
26
|
+
expect(parserKindFor('toml')).toBe('toml');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('everything else is not', () => {
|
|
30
|
+
// `json5` is deliberately absent: it accepts what strict JSON rejects, so a
|
|
31
|
+
// diagnostic there would accuse a valid file.
|
|
32
|
+
for (const language of ['typescript', 'json5', 'markdown', 'yamlx', '']) {
|
|
33
|
+
expect(parserKindFor(language)).toBeNull();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('json', () => {
|
|
39
|
+
test('valid JSON has no problems', async () => {
|
|
40
|
+
expect(await parseProblems('json', '{"a": 1, "b": [true, null]}')).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a trailing comma points at the closing brace, once', async () => {
|
|
44
|
+
const text = '{\n "a": 1,\n}\n';
|
|
45
|
+
const problems = await parseProblems('json', text);
|
|
46
|
+
// The parser recovers and reports two errors at the same offset; one
|
|
47
|
+
// squiggle per position is the rule, and this pins it.
|
|
48
|
+
expect(problems).toHaveLength(1);
|
|
49
|
+
expect(text.slice(problems[0].from, problems[0].to)).toBe('}');
|
|
50
|
+
expect(problems[0].severity).toBe('error');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a comment is refused, because strict JSON refuses it', async () => {
|
|
54
|
+
const problems = await parseProblems('json', '{\n // note\n "a": 1\n}');
|
|
55
|
+
expect(problems).toHaveLength(1);
|
|
56
|
+
expect(problems[0].message.length).toBeGreaterThan(0);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('an empty document is not an error', async () => {
|
|
60
|
+
// A file the user just created is empty; accusing it before they type is
|
|
61
|
+
// noise, not a diagnostic.
|
|
62
|
+
expect(await parseProblems('json', '')).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('the range is at least one character', async () => {
|
|
66
|
+
const problems = await parseProblems('json', '{"a": }');
|
|
67
|
+
expect(problems.length).toBeGreaterThan(0);
|
|
68
|
+
for (const problem of problems) expect(problem.to).toBeGreaterThan(problem.from);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('yaml', () => {
|
|
73
|
+
test('valid YAML has no problems', async () => {
|
|
74
|
+
expect(await parseProblems('yaml', 'model: gpt\nroles:\n chat: gpt\n')).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('an unclosed flow sequence points inside the document', async () => {
|
|
78
|
+
const text = 'a: 1\nb: [1, 2\nc: 3\n';
|
|
79
|
+
const problems = await parseProblems('yaml', text);
|
|
80
|
+
expect(problems.length).toBeGreaterThan(0);
|
|
81
|
+
expect(problems[0].severity).toBe('error');
|
|
82
|
+
expect(problems[0].from).toBeGreaterThanOrEqual(0);
|
|
83
|
+
expect(problems[0].to).toBeLessThanOrEqual(text.length);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('toml', () => {
|
|
88
|
+
test('valid TOML has no problems', async () => {
|
|
89
|
+
expect(await parseProblems('toml', '[tool]\nname = "x"\n')).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('the line and column become a document offset', async () => {
|
|
93
|
+
// Line 2, after `[tool]\n`, and the bad token is on that line.
|
|
94
|
+
const text = '[tool]\nname = \nversion = "1"\n';
|
|
95
|
+
const problems = await parseProblems('toml', text);
|
|
96
|
+
expect(problems).toHaveLength(1);
|
|
97
|
+
expect(problems[0].from).toBeGreaterThan('[tool]\n'.length - 1);
|
|
98
|
+
// The message is the first line only: a tooltip cannot lay out the code
|
|
99
|
+
// block the parser appends.
|
|
100
|
+
expect(problems[0].message).not.toContain('\n');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('an error on the first line lands on the first line', async () => {
|
|
104
|
+
const text = '= broken\n';
|
|
105
|
+
const problems = await parseProblems('toml', text);
|
|
106
|
+
expect(problems).toHaveLength(1);
|
|
107
|
+
expect(problems[0].from).toBe(0);
|
|
108
|
+
});
|
|
109
|
+
});
|