@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,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The parsers behind the editor's lint, loaded per language.
|
|
8
|
+
*
|
|
9
|
+
* Three formats, three parsers, and none of them is in the main bundle.
|
|
10
|
+
*
|
|
11
|
+
* **Why these are `import()` and not static imports**, which is the exception
|
|
12
|
+
* this file takes to the usual rule: a static import puts every parser in the
|
|
13
|
+
* main bundle, and all three measure ~46 KB gzip together (yaml 32.3,
|
|
14
|
+
* jsonc-parser 6.8, smol-toml 6.9) — in a repository that rejected a lezer
|
|
15
|
+
* grammar at 39 KB for exactly this reason (`stream-modes.ts`). A tab opened on
|
|
16
|
+
* a README must not pay for a TOML parser, so each arrives the first time a
|
|
17
|
+
* document in its language is linted. The specifier is known at author time;
|
|
18
|
+
* the TIMING is what is deferred, and only a call site can defer it.
|
|
19
|
+
*
|
|
20
|
+
* **Literal specifiers only.** A template-literal specifier builds fine and
|
|
21
|
+
* never resolves in the dev server (the same trap `stream-modes.ts` documents),
|
|
22
|
+
* so the switch below is spelled out per kind.
|
|
23
|
+
*
|
|
24
|
+
* Every parser reports a range in DOCUMENT OFFSETS, which is what a
|
|
25
|
+
* `Diagnostic` needs. Each one answers that differently — jsonc-parser already
|
|
26
|
+
* speaks offsets, YAML gives `[start, end]`, TOML gives a 1-based line and
|
|
27
|
+
* column — and the conversion lives here so `lint.ts` has one shape to read.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import type { ParseError } from 'jsonc-parser';
|
|
31
|
+
|
|
32
|
+
import { lineStartOffset } from '@/shared/lib/code/editor/lines';
|
|
33
|
+
|
|
34
|
+
/** The formats this build can lint. */
|
|
35
|
+
export type ParserKind = 'json' | 'yaml' | 'toml';
|
|
36
|
+
|
|
37
|
+
/** One problem, as a half-open document range and the sentence to show. */
|
|
38
|
+
export interface ParseProblem {
|
|
39
|
+
from: number;
|
|
40
|
+
to: number;
|
|
41
|
+
message: string;
|
|
42
|
+
severity: 'error' | 'warning';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Which parser answers for a Shiki language id, or null when none does. */
|
|
46
|
+
export function parserKindFor(language: string): ParserKind | null {
|
|
47
|
+
if (language === 'json') return 'json';
|
|
48
|
+
if (language === 'yaml') return 'yaml';
|
|
49
|
+
if (language === 'toml') return 'toml';
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** JSON, through `jsonc-parser` so the range is the offending token, not "line 1". */
|
|
54
|
+
async function jsonProblems(text: string): Promise<ParseProblem[]> {
|
|
55
|
+
const { parse, printParseErrorCode } = await import('jsonc-parser');
|
|
56
|
+
const errors: ParseError[] = [];
|
|
57
|
+
// Strict JSON on purpose: a `tsconfig` is read by tools that reject comments,
|
|
58
|
+
// and a lint that accepts them would bless a file the toolchain refuses.
|
|
59
|
+
parse(text, errors, { disallowComments: true, allowTrailingComma: false, allowEmptyContent: true });
|
|
60
|
+
// ONE diagnostic per position. The parser recovers and reports a second,
|
|
61
|
+
// less specific error at the same offset (a trailing comma is both
|
|
62
|
+
// `PropertyNameExpected` and `ValueExpected`), and two squiggles on one
|
|
63
|
+
// character read as two problems. The first is the specific one.
|
|
64
|
+
const seen = new Set<number>();
|
|
65
|
+
const problems: ParseProblem[] = [];
|
|
66
|
+
for (const error of errors) {
|
|
67
|
+
if (seen.has(error.offset)) continue;
|
|
68
|
+
seen.add(error.offset);
|
|
69
|
+
problems.push({
|
|
70
|
+
from: error.offset,
|
|
71
|
+
// A zero-length range draws nothing in the editor, so the minimum is one
|
|
72
|
+
// character — the one the parser pointed at.
|
|
73
|
+
to: error.offset + Math.max(error.length, 1),
|
|
74
|
+
message: printParseErrorCode(error.error),
|
|
75
|
+
severity: 'error',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return problems;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** YAML, through the same `yaml` package the server already parses config with. */
|
|
82
|
+
async function yamlProblems(text: string): Promise<ParseProblem[]> {
|
|
83
|
+
const { parseDocument } = await import('yaml');
|
|
84
|
+
// `prettyErrors: false` because the editor shows the message in a tooltip,
|
|
85
|
+
// where a multi-line excerpt with carets is unreadable.
|
|
86
|
+
const doc = parseDocument(text, { prettyErrors: false });
|
|
87
|
+
const problems: ParseProblem[] = doc.errors.map((error) => ({
|
|
88
|
+
from: error.pos[0],
|
|
89
|
+
to: Math.max(error.pos[1], error.pos[0] + 1),
|
|
90
|
+
message: error.message,
|
|
91
|
+
severity: 'error' as const,
|
|
92
|
+
}));
|
|
93
|
+
for (const warning of doc.warnings) {
|
|
94
|
+
problems.push({
|
|
95
|
+
from: warning.pos[0],
|
|
96
|
+
to: Math.max(warning.pos[1], warning.pos[0] + 1),
|
|
97
|
+
message: warning.message,
|
|
98
|
+
severity: 'warning',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return problems;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** TOML, through `smol-toml` — its error carries a 1-based line and column. */
|
|
105
|
+
async function tomlProblems(text: string): Promise<ParseProblem[]> {
|
|
106
|
+
const { parse, TomlError } = await import('smol-toml');
|
|
107
|
+
try {
|
|
108
|
+
parse(text);
|
|
109
|
+
return [];
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (!(error instanceof TomlError)) throw error;
|
|
112
|
+
const from = lineStartOffset(text, error.line - 1) + Math.max(error.column - 1, 0);
|
|
113
|
+
// The message's first line is the sentence; the rest is a code block with a
|
|
114
|
+
// caret, which a tooltip cannot lay out.
|
|
115
|
+
return [{ from, to: from + 1, message: error.message.split('\n')[0], severity: 'error' }];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const PARSERS: Record<ParserKind, (text: string) => Promise<ParseProblem[]>> = {
|
|
120
|
+
json: jsonProblems,
|
|
121
|
+
yaml: yamlProblems,
|
|
122
|
+
toml: tomlProblems,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The problems in `text`, or an empty list when the parser module could not load.
|
|
127
|
+
*
|
|
128
|
+
* A failed import is reported as "no diagnostics" rather than thrown: the editor
|
|
129
|
+
* must keep working on a format whose parser is missing, and the surface already
|
|
130
|
+
* has an `exceptionSink` for anything that does throw.
|
|
131
|
+
*/
|
|
132
|
+
export async function parseProblems(kind: ParserKind, text: string): Promise<ParseProblem[]> {
|
|
133
|
+
return PARSERS[kind](text);
|
|
134
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The lint extension: which languages get it, and what a document reports.
|
|
8
|
+
*
|
|
9
|
+
* The wiring is the part that fails silently. `linter()` alone registers a
|
|
10
|
+
* source nobody can see; `lintGutter()` alone draws a gutter with no markers.
|
|
11
|
+
* And a language with no parser must add NEITHER — an empty linter would still
|
|
12
|
+
* put a gutter beside every file in the repository.
|
|
13
|
+
*
|
|
14
|
+
* The diagnostics are asserted through `lintDiagnostics`, not through a mounted
|
|
15
|
+
* view: `linter()` schedules its own run on a timer, and a test that waited for
|
|
16
|
+
* it would be guessing at a duration rather than asserting a behaviour.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, expect, test } from 'bun:test';
|
|
20
|
+
|
|
21
|
+
import { LINT_MAX_CHARS, lintDiagnostics, lintExtensions } from '@/client/components/common/code-surface/lint';
|
|
22
|
+
|
|
23
|
+
describe('lintExtensions', () => {
|
|
24
|
+
test('the three config formats get a linter and a gutter', () => {
|
|
25
|
+
for (const language of ['json', 'yaml', 'toml']) {
|
|
26
|
+
expect(lintExtensions(language)).toHaveLength(2);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('every other language gets nothing at all', () => {
|
|
31
|
+
// Not "an empty linter": a gutter beside every TypeScript file would be a
|
|
32
|
+
// permanent 4px column reporting nothing.
|
|
33
|
+
for (const language of ['typescript', 'json5', 'markdown', 'python', '']) {
|
|
34
|
+
expect(lintExtensions(language)).toEqual([]);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('lintDiagnostics', () => {
|
|
40
|
+
test('a JSON trailing comma is one diagnostic, at the closing brace', async () => {
|
|
41
|
+
const text = '{\n "a": 1,\n}\n';
|
|
42
|
+
const diagnostics = await lintDiagnostics('json', text);
|
|
43
|
+
expect(diagnostics).toHaveLength(1);
|
|
44
|
+
expect(text.slice(diagnostics[0].from, diagnostics[0].to)).toBe('}');
|
|
45
|
+
expect(diagnostics[0].severity).toBe('error');
|
|
46
|
+
expect(diagnostics[0].message).toBe('PropertyNameExpected');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('valid JSON reports none', async () => {
|
|
50
|
+
expect(await lintDiagnostics('json', '{"a": 1}')).toEqual([]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a YAML document with an unclosed sequence reports one', async () => {
|
|
54
|
+
const diagnostics = await lintDiagnostics('yaml', 'a: [1, 2\n');
|
|
55
|
+
expect(diagnostics.length).toBeGreaterThan(0);
|
|
56
|
+
expect(diagnostics[0].severity).toBe('error');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('a TOML document with a bad assignment reports one', async () => {
|
|
60
|
+
const diagnostics = await lintDiagnostics('toml', '[tool]\nname = \n');
|
|
61
|
+
expect(diagnostics).toHaveLength(1);
|
|
62
|
+
// A tooltip cannot lay out the code block the parser appends.
|
|
63
|
+
expect(diagnostics[0].message).not.toContain('\n');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('a language with no parser reports nothing, whatever the text', async () => {
|
|
67
|
+
expect(await lintDiagnostics('typescript', 'const = ;')).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a document past the ceiling is not parsed', async () => {
|
|
71
|
+
// A generated 2 MB manifest must not be re-parsed on every idle moment.
|
|
72
|
+
expect(LINT_MAX_CHARS).toBe(2 * 1024 * 1024);
|
|
73
|
+
const huge = `{"a": "${'x'.repeat(LINT_MAX_CHARS)}"`;
|
|
74
|
+
expect(await lintDiagnostics('json', huge)).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('a conflicted config file reports no parse errors', async () => {
|
|
78
|
+
// Every error below a marker is a consequence of the merge, and the conflict
|
|
79
|
+
// band plus the status strip already say so. Measured before this rule: four
|
|
80
|
+
// gutter markers on a one-conflict JSON file.
|
|
81
|
+
const conflicted = ['{', '<<<<<<< HEAD', ' "a": 1,', '=======', ' "a": 2,', '>>>>>>> x', '}'].join('\n');
|
|
82
|
+
expect(await lintDiagnostics('json', conflicted)).toEqual([]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('a document that merely mentions the marker is still linted', async () => {
|
|
86
|
+
const text = '{"note": "<<<<<<< HEAD"}';
|
|
87
|
+
expect(await lintDiagnostics('json', text)).toEqual([]);
|
|
88
|
+
// And a real error in such a document is still reported.
|
|
89
|
+
const broken = '{"note": "<<<<<<< HEAD",}';
|
|
90
|
+
expect((await lintDiagnostics('json', broken)).length).toBeGreaterThan(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('every range is inside the document and non-empty', async () => {
|
|
94
|
+
const text = '{\n "a": 1,\n}\n';
|
|
95
|
+
for (const diagnostic of await lintDiagnostics('json', text)) {
|
|
96
|
+
expect(diagnostic.from).toBeGreaterThanOrEqual(0);
|
|
97
|
+
expect(diagnostic.to).toBeGreaterThan(diagnostic.from);
|
|
98
|
+
expect(diagnostic.to).toBeLessThanOrEqual(text.length);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's lint: a parser's verdict, painted where the problem is.
|
|
8
|
+
*
|
|
9
|
+
* ## The parsers are the only honest source here
|
|
10
|
+
*
|
|
11
|
+
* There is no language server behind this, and there will not be one: the
|
|
12
|
+
* editor is a file viewer, not an IDE. What a parser can answer is exactly what
|
|
13
|
+
* a reader of a config file needs — "this document is not valid JSON/YAML/TOML,
|
|
14
|
+
* and here is the byte" — and nothing more. A linter that also offered style
|
|
15
|
+
* opinions would be inventing rules the repository does not have.
|
|
16
|
+
*
|
|
17
|
+
* ## Which formats, and why not more
|
|
18
|
+
*
|
|
19
|
+
* JSON, YAML and TOML, because those are the three formats this app edits as
|
|
20
|
+
* CONFIG (omp settings are YAML, `bunfig`/`pyproject` are TOML, every manifest
|
|
21
|
+
* is JSON) and all three have a parser that is already a dependency or is
|
|
22
|
+
* measured small. `json5` is deliberately excluded: it accepts what strict JSON
|
|
23
|
+
* rejects, so a diagnostic there would be a false accusation.
|
|
24
|
+
*
|
|
25
|
+
* ## The parsers arrive lazily
|
|
26
|
+
*
|
|
27
|
+
* See `lint-parsers.ts`. This module is in the main bundle and holds no parser.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import type { Extension } from '@codemirror/state';
|
|
31
|
+
import { linter, lintGutter, type Diagnostic, type LintSource } from '@codemirror/lint';
|
|
32
|
+
|
|
33
|
+
import { parseProblems, parserKindFor } from '@/client/components/common/code-surface/lint-parsers';
|
|
34
|
+
import { hasConflictMarker } from '@/client/components/common/code-surface/conflict-markers';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Documents above this are not linted.
|
|
38
|
+
*
|
|
39
|
+
* A 2 MB manifest is a generated file, and re-parsing it on every idle moment
|
|
40
|
+
* costs more than the diagnostics are worth. The number is the same ceiling the
|
|
41
|
+
* highlighter refuses to tokenize past, for the same reason.
|
|
42
|
+
*/
|
|
43
|
+
export const LINT_MAX_CHARS = 2 * 1024 * 1024;
|
|
44
|
+
|
|
45
|
+
/** How long the editor waits after the last keystroke. */
|
|
46
|
+
const LINT_DELAY_MS = 600;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A parser's problems as CodeMirror diagnostics, clamped to the document.
|
|
50
|
+
*
|
|
51
|
+
* Exported because it is the unit that can be tested without a timer: the
|
|
52
|
+
* mounted path is `linter()`'s own async scheduling, and a test that waited for
|
|
53
|
+
* it would be guessing at a duration rather than asserting a behaviour.
|
|
54
|
+
*/
|
|
55
|
+
export async function lintDiagnostics(language: string, text: string): Promise<Diagnostic[]> {
|
|
56
|
+
const kind = parserKindFor(language);
|
|
57
|
+
if (!kind || text.length > LINT_MAX_CHARS) return [];
|
|
58
|
+
// A file mid-merge is not a broken JSON/YAML/TOML document — it is two
|
|
59
|
+
// documents with markers between them, and every parse error below the first
|
|
60
|
+
// marker is a CONSEQUENCE of that. Measured on a one-conflict JSON file: four
|
|
61
|
+
// gutter markers and four squiggles, none of which told the reader anything
|
|
62
|
+
// the conflict band and the status strip's `⚠ 1 conflict` do not already say.
|
|
63
|
+
// The conflict is the problem; the parser is not the right tool to report it.
|
|
64
|
+
if (hasConflictMarker(text)) return [];
|
|
65
|
+
const problems = await parseProblems(kind, text);
|
|
66
|
+
return problems.map((problem) => ({
|
|
67
|
+
from: Math.max(0, Math.min(problem.from, text.length)),
|
|
68
|
+
to: Math.max(0, Math.min(problem.to, text.length)),
|
|
69
|
+
severity: problem.severity,
|
|
70
|
+
message: problem.message,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The lint extension for one language, or an empty list for every other.
|
|
76
|
+
*
|
|
77
|
+
* `lintGutter` is part of the same value: a diagnostic with no gutter marker is
|
|
78
|
+
* a squiggle the reader has to find by scrolling, and the two extensions share
|
|
79
|
+
* the diagnostics field they read.
|
|
80
|
+
*/
|
|
81
|
+
export function lintExtensions(language: string): Extension[] {
|
|
82
|
+
if (!parserKindFor(language)) return [];
|
|
83
|
+
const source: LintSource = (view) => lintDiagnostics(language, view.state.doc.toString());
|
|
84
|
+
return [linter(source, { delay: LINT_DELAY_MS }), lintGutter()];
|
|
85
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { CSSProperties } from 'preact';
|
|
16
|
+
import type { Extension } from '@codemirror/state';
|
|
16
17
|
|
|
17
18
|
import type { ShikiThemeNames } from '@/client/components/common/code-surface/shiki';
|
|
18
19
|
import type { MarkRange } from '@/client/components/common/code-surface/marks';
|
|
@@ -61,6 +62,15 @@ export interface CodeSurfaceProps {
|
|
|
61
62
|
* history.
|
|
62
63
|
*/
|
|
63
64
|
typing?: EditorTypingOptions;
|
|
65
|
+
/**
|
|
66
|
+
* Line blame: the labels, the card and the state they read — or `null`.
|
|
67
|
+
*
|
|
68
|
+
* Built by the owner (`blameExtensions`) because the controller behind it
|
|
69
|
+
* needs the file's identity, which the surface does not have. `null` is off,
|
|
70
|
+
* and the surface reconfigures a compartment when it moves, so pressing the
|
|
71
|
+
* toggle does not cost an open tab its undo history.
|
|
72
|
+
*/
|
|
73
|
+
blame?: Extension | null;
|
|
64
74
|
/** Font family / size / line height (the zoom control and the font setting). */
|
|
65
75
|
style?: CSSProperties;
|
|
66
76
|
/** Padding around the document, in px. */
|
|
@@ -83,5 +93,12 @@ export interface CodeSurfaceProps {
|
|
|
83
93
|
* cannot reach it through a `ref`, so the surface hands it over.
|
|
84
94
|
*/
|
|
85
95
|
onScroller?: (element: HTMLElement | null) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Text drawn while the document is empty.
|
|
98
|
+
*
|
|
99
|
+
* An open file with no bytes is a fact the panel should state: an unlabelled
|
|
100
|
+
* blank surface reads as a read that has not finished.
|
|
101
|
+
*/
|
|
102
|
+
placeholder?: string;
|
|
86
103
|
className?: string;
|
|
87
104
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Two facts the surface states about itself: an empty document says so, and a
|
|
8
|
+
* plugin that throws is reported rather than swallowed.
|
|
9
|
+
*
|
|
10
|
+
* Both are wiring, and both fail invisibly — a `placeholder` that never reaches
|
|
11
|
+
* the extension list looks exactly like a file with one blank line, and
|
|
12
|
+
* CodeMirror's own `exceptionSink` default (`console.error`) is indistinguishable
|
|
13
|
+
* from an editor that simply has nothing to draw.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { Compartment, EditorState } from '@codemirror/state';
|
|
19
|
+
import { EditorView, ViewPlugin } from '@codemirror/view';
|
|
20
|
+
|
|
21
|
+
import { surfaceExtensions } from '@/client/components/common/code-surface/extensions';
|
|
22
|
+
import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
|
|
23
|
+
import { EDITOR_ERROR_EVENT, resetEditorErrorReports } from '@/client/lib/editor-errors';
|
|
24
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
25
|
+
|
|
26
|
+
const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame'] as const;
|
|
27
|
+
const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
|
|
28
|
+
|
|
29
|
+
let host: HTMLElement;
|
|
30
|
+
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
const win = new Window({ url: 'http://localhost' });
|
|
33
|
+
installDomGlobals(win);
|
|
34
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
35
|
+
for (const key of EXTRA_GLOBALS) {
|
|
36
|
+
native[key] = target[key];
|
|
37
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
38
|
+
}
|
|
39
|
+
host = document.body.appendChild(document.createElement('div'));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
44
|
+
for (const key of EXTRA_GLOBALS) {
|
|
45
|
+
if (native[key] === undefined) delete target[key];
|
|
46
|
+
else target[key] = native[key];
|
|
47
|
+
}
|
|
48
|
+
restoreDomGlobals();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** The component's own stack, with the two options under test. */
|
|
52
|
+
function extensionsFor(options: { placeholder?: string; extra?: unknown[] } = {}) {
|
|
53
|
+
return [
|
|
54
|
+
...surfaceExtensions({
|
|
55
|
+
language: 'typescript',
|
|
56
|
+
wordWrapCompartment: new Compartment(),
|
|
57
|
+
readOnlyCompartment: new Compartment(),
|
|
58
|
+
themeCompartment: new Compartment(),
|
|
59
|
+
languageCompartment: new Compartment(),
|
|
60
|
+
indentCompartment: new Compartment(),
|
|
61
|
+
typingCompartment: new Compartment(),
|
|
62
|
+
blameCompartment: new Compartment(),
|
|
63
|
+
blame: null,
|
|
64
|
+
indentUnitText: ' ',
|
|
65
|
+
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
66
|
+
wordWrap: false,
|
|
67
|
+
readOnly: false,
|
|
68
|
+
themes: SHIKI_THEMES,
|
|
69
|
+
onDocChange: () => {},
|
|
70
|
+
onState: () => {},
|
|
71
|
+
placeholder: options.placeholder,
|
|
72
|
+
}),
|
|
73
|
+
...(options.extra ?? []),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function mount(doc: string, options: { placeholder?: string; extra?: unknown[] } = {}): EditorView {
|
|
78
|
+
return new EditorView({
|
|
79
|
+
parent: host,
|
|
80
|
+
state: EditorState.create({ doc, extensions: extensionsFor(options) as never }),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('placeholder', () => {
|
|
85
|
+
test('an empty document draws the sentence', () => {
|
|
86
|
+
const view = mount('', { placeholder: 'This file is empty' });
|
|
87
|
+
const node = view.contentDOM.querySelector('.cm-placeholder');
|
|
88
|
+
expect(node?.textContent).toBe('This file is empty');
|
|
89
|
+
view.destroy();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a document with text draws nothing', () => {
|
|
93
|
+
const view = mount('a\n', { placeholder: 'This file is empty' });
|
|
94
|
+
expect(view.contentDOM.querySelector('.cm-placeholder')).toBeNull();
|
|
95
|
+
view.destroy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('no placeholder configured draws nothing, even when empty', () => {
|
|
99
|
+
// The diff panel mounts the surface with no placeholder: an empty side of a
|
|
100
|
+
// diff is a fact the panel states itself.
|
|
101
|
+
const view = mount('');
|
|
102
|
+
expect(view.contentDOM.querySelector('.cm-placeholder')).toBeNull();
|
|
103
|
+
view.destroy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('exceptionSink', () => {
|
|
108
|
+
test('a plugin that throws on construction is reported as an editor error', () => {
|
|
109
|
+
resetEditorErrorReports();
|
|
110
|
+
const seen: string[] = [];
|
|
111
|
+
const listener = (event: Event) => {
|
|
112
|
+
const detail = (event as CustomEvent<{ message: string }>).detail;
|
|
113
|
+
seen.push(detail.message);
|
|
114
|
+
};
|
|
115
|
+
window.addEventListener(EDITOR_ERROR_EVENT, listener);
|
|
116
|
+
|
|
117
|
+
const throwing = ViewPlugin.define(() => {
|
|
118
|
+
throw new Error('viewport plugin exploded');
|
|
119
|
+
});
|
|
120
|
+
// Construction happens on mount, which is where a real plugin fails.
|
|
121
|
+
let view: EditorView | null = null;
|
|
122
|
+
try {
|
|
123
|
+
view = mount('a\n', { extra: [throwing] });
|
|
124
|
+
} catch {
|
|
125
|
+
// CodeMirror may rethrow after reporting; the assertion is the report.
|
|
126
|
+
}
|
|
127
|
+
view?.destroy();
|
|
128
|
+
window.removeEventListener(EDITOR_ERROR_EVENT, listener);
|
|
129
|
+
|
|
130
|
+
expect(seen).toContain('viewport plugin exploded');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -224,11 +224,82 @@ export function surfaceTheme(): Extension {
|
|
|
224
224
|
backgroundSize: '1px 100%',
|
|
225
225
|
backgroundPosition: 'calc(var(--indent-guide-col, 2ch) - 1px) 0',
|
|
226
226
|
},
|
|
227
|
+
// The line-blame label at the end of a run's first line.
|
|
228
|
+
//
|
|
229
|
+
// A WIDGET, so it is drawn beside the text rather than inside it — and it
|
|
230
|
+
// is deliberately the faintest thing on the surface: it is a hint that the
|
|
231
|
+
// line has an answer, not information being read. `user-select: none`
|
|
232
|
+
// because a drag that selected it would put an author's name into a copied
|
|
233
|
+
// snippet of code, and `pointer-events: auto` because it is the hover
|
|
234
|
+
// target the card opens from.
|
|
235
|
+
'.cm-blame-label': {
|
|
236
|
+
marginLeft: '2.5ch',
|
|
237
|
+
color: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 30%, transparent)',
|
|
238
|
+
fontStyle: 'normal',
|
|
239
|
+
whiteSpace: 'nowrap',
|
|
240
|
+
userSelect: 'none',
|
|
241
|
+
cursor: 'help',
|
|
242
|
+
pointerEvents: 'auto',
|
|
243
|
+
},
|
|
244
|
+
'.cm-blame-label:hover': {
|
|
245
|
+
color: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 60%, transparent)',
|
|
246
|
+
},
|
|
227
247
|
// Other occurrences of the selection. Deliberately SUBTLER than a find match:
|
|
228
248
|
// this is a hint about the word under the caret, and on a common identifier it
|
|
229
249
|
// paints a lot of the viewport.
|
|
230
250
|
'.cm-selectionMatch': {
|
|
231
251
|
backgroundColor: 'var(--editor-selection-match, color-mix(in srgb, var(--theme-info) 14%, transparent))',
|
|
232
252
|
},
|
|
253
|
+
// Merge-conflict markers (`conflict-markers.ts`). A LINE decoration, so the
|
|
254
|
+
// whole line is banded rather than the seven characters — the reader is
|
|
255
|
+
// looking for where a block starts, not for a token.
|
|
256
|
+
//
|
|
257
|
+
// Ours and theirs take the two signal colours a diff already uses (removed /
|
|
258
|
+
// added), because that is the same distinction in the same direction; diff3's
|
|
259
|
+
// base section is neutral, since it belongs to neither side.
|
|
260
|
+
'.cm-line.cm-conflict-ours': {
|
|
261
|
+
backgroundColor: 'color-mix(in srgb, var(--theme-error) 12%, transparent)',
|
|
262
|
+
boxShadow: 'inset 2px 0 0 var(--theme-error)',
|
|
263
|
+
},
|
|
264
|
+
'.cm-line.cm-conflict-theirs': {
|
|
265
|
+
backgroundColor: 'color-mix(in srgb, var(--theme-success) 12%, transparent)',
|
|
266
|
+
boxShadow: 'inset 2px 0 0 var(--theme-success)',
|
|
267
|
+
},
|
|
268
|
+
'.cm-line.cm-conflict-base': {
|
|
269
|
+
backgroundColor: 'color-mix(in srgb, var(--theme-ink) 7%, transparent)',
|
|
270
|
+
boxShadow: 'inset 2px 0 0 color-mix(in srgb, var(--theme-ink) 35%, transparent)',
|
|
271
|
+
},
|
|
272
|
+
// Lint. The package ships hardcoded hex for every one of these, so they are
|
|
273
|
+
// restated from the palette — the same trap `matchingBracket` documents.
|
|
274
|
+
'.cm-lintRange-error': {
|
|
275
|
+
backgroundImage: 'none',
|
|
276
|
+
textDecoration: 'underline wavy var(--theme-error)',
|
|
277
|
+
textUnderlineOffset: '2px',
|
|
278
|
+
},
|
|
279
|
+
'.cm-lintRange-warning': {
|
|
280
|
+
backgroundImage: 'none',
|
|
281
|
+
textDecoration: 'underline wavy var(--theme-warning)',
|
|
282
|
+
textUnderlineOffset: '2px',
|
|
283
|
+
},
|
|
284
|
+
'.cm-lint-marker-error': { content: 'none', backgroundColor: 'var(--theme-error)' },
|
|
285
|
+
'.cm-lint-marker-warning': { content: 'none', backgroundColor: 'var(--theme-warning)' },
|
|
286
|
+
'.cm-diagnostic': {
|
|
287
|
+
borderLeftWidth: '3px',
|
|
288
|
+
borderLeftStyle: 'solid',
|
|
289
|
+
borderLeftColor: 'var(--theme-ink)',
|
|
290
|
+
padding: '3px 6px 3px 8px',
|
|
291
|
+
marginLeft: '-1px',
|
|
292
|
+
fontFamily: 'inherit',
|
|
293
|
+
},
|
|
294
|
+
'.cm-diagnostic-error': { borderLeftColor: 'var(--theme-error)' },
|
|
295
|
+
'.cm-diagnostic-warning': { borderLeftColor: 'var(--theme-warning)' },
|
|
296
|
+
'.cm-tooltip': {
|
|
297
|
+
backgroundColor: 'var(--editor-bg, var(--theme-paper))',
|
|
298
|
+
color: 'var(--editor-fg, var(--theme-ink))',
|
|
299
|
+
borderWidth: '1px',
|
|
300
|
+
borderStyle: 'solid',
|
|
301
|
+
borderColor: 'color-mix(in srgb, var(--theme-ink) 15%, transparent)',
|
|
302
|
+
fontFamily: 'inherit',
|
|
303
|
+
},
|
|
233
304
|
});
|
|
234
305
|
}
|
|
@@ -50,7 +50,7 @@ const PANELS: PanelRegistryPayload = {
|
|
|
50
50
|
panels: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', appUrl: '/api/panels/bundle/demo.js' }],
|
|
51
51
|
marketplaces: [],
|
|
52
52
|
errors: [],
|
|
53
|
-
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, gitOrigin: null }],
|
|
53
|
+
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, origin: 'local', gitOrigin: null }],
|
|
54
54
|
catalog: [],
|
|
55
55
|
disabledPanels: [],
|
|
56
56
|
gitStatus: {},
|
|
@@ -51,7 +51,7 @@ const PANELS: PanelRegistryPayload = {
|
|
|
51
51
|
panels: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', appUrl: '/api/panels/bundle/demo.js' }],
|
|
52
52
|
marketplaces: [],
|
|
53
53
|
errors: [],
|
|
54
|
-
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, gitOrigin: null }],
|
|
54
|
+
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, origin: 'local', gitOrigin: null }],
|
|
55
55
|
catalog: [],
|
|
56
56
|
disabledPanels: [],
|
|
57
57
|
gitStatus: {},
|
|
@@ -55,7 +55,7 @@ const PANELS: PanelRegistryPayload = {
|
|
|
55
55
|
panels: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', appUrl: '/api/panels/bundle/demo.js' }],
|
|
56
56
|
marketplaces: [],
|
|
57
57
|
errors: [],
|
|
58
|
-
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, gitOrigin: null }],
|
|
58
|
+
plugins: [{ pluginId: 'demo', name: 'Demo', version: '1.0.0', isPackage: true, built: true, enabled: true, bundled: false, origin: 'local', gitOrigin: null }],
|
|
59
59
|
catalog: [],
|
|
60
60
|
disabledPanels: [],
|
|
61
61
|
gitStatus: {},
|