@deepseek-ai/dsh-experimental-client-ui-forge 0.2.2-rc.5 → 0.2.3-alpha.2
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.i18n.yaml +12 -12
- package/README.md +47 -30
- package/README.zh.md +47 -30
- package/lib/client.js +18 -8
- package/lib/client.js.map +1 -1
- package/lib/index.js +2444 -406
- package/lib/typert.host.js +3433 -950
- package/lib/typert.remote-client.d.ts +89 -14
- package/lib/typert.remote-client.d.ts.map +1 -1
- package/lib/typert.remote-client.js +3155 -978
- package/lib/types/branch-name.d.ts +30 -0
- package/lib/types/branch-name.d.ts.map +1 -0
- package/lib/types/branch-name.js.map +1 -0
- package/lib/types/client/AttentionIndicator.d.ts +22 -0
- package/lib/types/client/AttentionIndicator.d.ts.map +1 -0
- package/lib/types/client/AttentionIndicator.js.map +1 -0
- package/lib/types/client/BaseMenu.d.ts.map +1 -1
- package/lib/types/client/BaseMenu.js.map +1 -1
- package/lib/types/client/ChangeRequestCard.d.ts +87 -9
- package/lib/types/client/ChangeRequestCard.d.ts.map +1 -1
- package/lib/types/client/ChangeRequestCard.js.map +1 -1
- package/lib/types/client/ChangeRequestOverview.d.ts +126 -10
- package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -1
- package/lib/types/client/ChangeRequestOverview.js.map +1 -1
- package/lib/types/client/ChangeRequestsSection.d.ts +76 -0
- package/lib/types/client/ChangeRequestsSection.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestsSection.js.map +1 -0
- package/lib/types/client/ChangedFiles.d.ts +6 -2
- package/lib/types/client/ChangedFiles.d.ts.map +1 -1
- package/lib/types/client/ChangedFiles.js.map +1 -1
- package/lib/types/client/ChangesLoading.d.ts +14 -0
- package/lib/types/client/ChangesLoading.d.ts.map +1 -0
- package/lib/types/client/ChangesLoading.js.map +1 -0
- package/lib/types/client/ChangesTab.d.ts +62 -14
- package/lib/types/client/ChangesTab.d.ts.map +1 -1
- package/lib/types/client/ChangesTab.js.map +1 -1
- package/lib/types/client/ChangesTabTitle.js.map +1 -1
- package/lib/types/client/DiffFile.d.ts +23 -4
- package/lib/types/client/DiffFile.d.ts.map +1 -1
- package/lib/types/client/DiffFile.js.map +1 -1
- package/lib/types/client/EnvironmentRows.d.ts +79 -0
- package/lib/types/client/EnvironmentRows.d.ts.map +1 -0
- package/lib/types/client/EnvironmentRows.js.map +1 -0
- package/lib/types/client/FileTreePane.d.ts +5 -2
- package/lib/types/client/FileTreePane.d.ts.map +1 -1
- package/lib/types/client/FileTreePane.js.map +1 -1
- package/lib/types/client/LensFilter.d.ts +50 -0
- package/lib/types/client/LensFilter.d.ts.map +1 -0
- package/lib/types/client/LensFilter.js.map +1 -0
- package/lib/types/client/ReasonButton.d.ts +15 -0
- package/lib/types/client/ReasonButton.d.ts.map +1 -0
- package/lib/types/client/ReasonButton.js.map +1 -0
- package/lib/types/client/ReviewComposer.d.ts +11 -4
- package/lib/types/client/ReviewComposer.d.ts.map +1 -1
- package/lib/types/client/ReviewComposer.js.map +1 -1
- package/lib/types/client/ReviewControls.d.ts +18 -7
- package/lib/types/client/ReviewControls.d.ts.map +1 -1
- package/lib/types/client/ReviewControls.js.map +1 -1
- package/lib/types/client/ReviewThread.d.ts +3 -1
- package/lib/types/client/ReviewThread.d.ts.map +1 -1
- package/lib/types/client/ReviewThread.js.map +1 -1
- package/lib/types/client/ReviewThreads.d.ts +32 -2
- package/lib/types/client/ReviewThreads.d.ts.map +1 -1
- package/lib/types/client/ReviewThreads.js.map +1 -1
- package/lib/types/client/SessionHoverForge.d.ts.map +1 -1
- package/lib/types/client/SessionHoverForge.js.map +1 -1
- package/lib/types/client/SubmitReview.d.ts +4 -4
- package/lib/types/client/SubmitReview.d.ts.map +1 -1
- package/lib/types/client/SubmitReview.js.map +1 -1
- package/lib/types/client/ThreadList.js.map +1 -1
- package/lib/types/client/ViewOptionsMenu.d.ts +7 -1
- package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -1
- package/lib/types/client/ViewOptionsMenu.js.map +1 -1
- package/lib/types/client/WorktreeNameDialog.d.ts +38 -0
- package/lib/types/client/WorktreeNameDialog.d.ts.map +1 -0
- package/lib/types/client/WorktreeNameDialog.js.map +1 -0
- package/lib/types/client/WorktreeProgress.d.ts +14 -3
- package/lib/types/client/WorktreeProgress.d.ts.map +1 -1
- package/lib/types/client/WorktreeProgress.js.map +1 -1
- package/lib/types/client/WorktreeToggle.d.ts +22 -15
- package/lib/types/client/WorktreeToggle.d.ts.map +1 -1
- package/lib/types/client/WorktreeToggle.js.map +1 -1
- package/lib/types/client/action-notices.d.ts +25 -0
- package/lib/types/client/action-notices.d.ts.map +1 -0
- package/lib/types/client/action-notices.js.map +1 -0
- package/lib/types/client/annotations.d.ts +41 -0
- package/lib/types/client/annotations.d.ts.map +1 -0
- package/lib/types/client/annotations.js.map +1 -0
- package/lib/types/client/branch-search.d.ts +38 -0
- package/lib/types/client/branch-search.d.ts.map +1 -0
- package/lib/types/client/branch-search.js.map +1 -0
- package/lib/types/client/change-requests-store.d.ts +25 -0
- package/lib/types/client/change-requests-store.d.ts.map +1 -0
- package/lib/types/client/change-requests-store.js.map +1 -0
- package/lib/types/client/changes-address.d.ts +3 -1
- package/lib/types/client/changes-address.d.ts.map +1 -1
- package/lib/types/client/changes-address.js.map +1 -1
- package/lib/types/client/changes-service.d.ts +119 -0
- package/lib/types/client/changes-service.d.ts.map +1 -0
- package/lib/types/client/changes-service.js.map +1 -0
- package/lib/types/client/changes-store.d.ts +6 -2
- package/lib/types/client/changes-store.d.ts.map +1 -1
- package/lib/types/client/changes-store.js.map +1 -1
- package/lib/types/client/checkout.d.ts.map +1 -1
- package/lib/types/client/checkout.js.map +1 -1
- package/lib/types/client/diff-rows.d.ts +49 -7
- package/lib/types/client/diff-rows.d.ts.map +1 -1
- package/lib/types/client/diff-rows.js.map +1 -1
- package/lib/types/client/file-tree.d.ts +7 -0
- package/lib/types/client/file-tree.d.ts.map +1 -1
- package/lib/types/client/file-tree.js.map +1 -1
- package/lib/types/client/forge-copy.d.ts +29 -0
- package/lib/types/client/forge-copy.d.ts.map +1 -0
- package/lib/types/client/forge-copy.js.map +1 -0
- package/lib/types/client/format.d.ts +8 -0
- package/lib/types/client/format.d.ts.map +1 -1
- package/lib/types/client/format.js.map +1 -1
- package/lib/types/client/glyphs.d.ts +3 -3
- package/lib/types/client/glyphs.d.ts.map +1 -1
- package/lib/types/client/glyphs.js.map +1 -1
- package/lib/types/client/highlight-context.d.ts +73 -0
- package/lib/types/client/highlight-context.d.ts.map +1 -0
- package/lib/types/client/highlight-context.js.map +1 -0
- package/lib/types/client/index.d.ts +9 -5
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js.map +1 -1
- package/lib/types/client/lens-filter.d.ts +69 -0
- package/lib/types/client/lens-filter.d.ts.map +1 -0
- package/lib/types/client/lens-filter.js.map +1 -0
- package/lib/types/client/locales.d.ts +188 -36
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/locales.js.map +1 -1
- package/lib/types/client/mount.d.ts +0 -4
- package/lib/types/client/mount.d.ts.map +1 -1
- package/lib/types/client/mount.js.map +1 -1
- package/lib/types/client/review-page/ReviewChat.d.ts +112 -0
- package/lib/types/client/review-page/ReviewChat.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewChat.js.map +1 -0
- package/lib/types/client/review-page/ReviewDetail.d.ts +56 -0
- package/lib/types/client/review-page/ReviewDetail.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewDetail.js.map +1 -0
- package/lib/types/client/review-page/ReviewLabels.d.ts +32 -0
- package/lib/types/client/review-page/ReviewLabels.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewLabels.js.map +1 -0
- package/lib/types/client/review-page/ReviewList.d.ts +68 -0
- package/lib/types/client/review-page/ReviewList.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewList.js.map +1 -0
- package/lib/types/client/review-page/ReviewNav.d.ts +28 -0
- package/lib/types/client/review-page/ReviewNav.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewNav.js.map +1 -0
- package/lib/types/client/review-page/ReviewPage.d.ts +61 -0
- package/lib/types/client/review-page/ReviewPage.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewPage.js.map +1 -0
- package/lib/types/client/review-page/ReviewStatus.d.ts +37 -0
- package/lib/types/client/review-page/ReviewStatus.d.ts.map +1 -0
- package/lib/types/client/review-page/ReviewStatus.js.map +1 -0
- package/lib/types/client/review-page/host-stream.d.ts +24 -0
- package/lib/types/client/review-page/host-stream.d.ts.map +1 -0
- package/lib/types/client/review-page/host-stream.js.map +1 -0
- package/lib/types/client/review-page/review-lists.d.ts +116 -0
- package/lib/types/client/review-page/review-lists.d.ts.map +1 -0
- package/lib/types/client/review-page/review-lists.js.map +1 -0
- package/lib/types/client/review-page/review-mount.d.ts +50 -0
- package/lib/types/client/review-page/review-mount.d.ts.map +1 -0
- package/lib/types/client/review-page/review-mount.js.map +1 -0
- package/lib/types/client/review-page/review-store.d.ts +79 -0
- package/lib/types/client/review-page/review-store.d.ts.map +1 -0
- package/lib/types/client/review-page/review-store.js.map +1 -0
- package/lib/types/client/review-queue.d.ts +19 -0
- package/lib/types/client/review-queue.d.ts.map +1 -1
- package/lib/types/client/review-queue.js.map +1 -1
- package/lib/types/client/review-threads.d.ts +0 -8
- package/lib/types/client/review-threads.d.ts.map +1 -1
- package/lib/types/client/review-threads.js.map +1 -1
- package/lib/types/client/review.d.ts +18 -0
- package/lib/types/client/review.d.ts.map +1 -1
- package/lib/types/client/review.js.map +1 -1
- package/lib/types/client/slots.d.ts +114 -0
- package/lib/types/client/slots.d.ts.map +1 -0
- package/lib/types/client/slots.js.map +1 -0
- package/lib/types/client/source.d.ts +29 -23
- package/lib/types/client/source.d.ts.map +1 -1
- package/lib/types/client/source.js.map +1 -1
- package/lib/types/client/status.d.ts +13 -2
- package/lib/types/client/status.d.ts.map +1 -1
- package/lib/types/client/status.js.map +1 -1
- package/lib/types/git.d.ts +4 -15
- package/lib/types/git.d.ts.map +1 -1
- package/lib/types/git.js.map +1 -1
- package/lib/types/index.d.ts +346 -28
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/lens-version.d.ts +14 -0
- package/lib/types/lens-version.d.ts.map +1 -0
- package/lib/types/lens-version.js.map +1 -0
- package/lib/types/lenses.d.ts +122 -0
- package/lib/types/lenses.d.ts.map +1 -0
- package/lib/types/lenses.js.map +1 -0
- package/lib/types/local-diff.d.ts +16 -0
- package/lib/types/local-diff.d.ts.map +1 -1
- package/lib/types/local-diff.js.map +1 -1
- package/lib/types/panel.d.ts +59 -8
- package/lib/types/panel.d.ts.map +1 -1
- package/lib/types/panel.js.map +1 -1
- package/lib/types/parse.d.ts +24 -8
- package/lib/types/parse.d.ts.map +1 -1
- package/lib/types/parse.js.map +1 -1
- package/lib/types/review-cache.d.ts +29 -19
- package/lib/types/review-cache.d.ts.map +1 -1
- package/lib/types/review-cache.js.map +1 -1
- package/lib/types/states.d.ts +11 -7
- package/lib/types/states.d.ts.map +1 -1
- package/lib/types/states.js.map +1 -1
- package/lib/types/types.d.ts +266 -20
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/viewer-lists.d.ts +113 -0
- package/lib/types/viewer-lists.d.ts.map +1 -0
- package/lib/types/viewer-lists.js.map +1 -0
- package/lib/types/worktree.d.ts +20 -11
- package/lib/types/worktree.d.ts.map +1 -1
- package/lib/types/worktree.js.map +1 -1
- package/locale/de.json +1 -1
- package/locale/en.json +1 -1
- package/locale/es.json +1 -1
- package/locale/fr.json +1 -1
- package/locale/ja.json +1 -1
- package/locale/pt.json +1 -1
- package/locale/ru.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +61 -52
- package/src/branch-name.ts +74 -0
- package/src/client/AttentionIndicator.tsx +37 -0
- package/src/client/BaseMenu.module.css +0 -20
- package/src/client/BaseMenu.tsx +9 -52
- package/src/client/ChangeRequestCard.tsx +276 -131
- package/src/client/ChangeRequestOverview.module.css +1 -1
- package/src/client/ChangeRequestOverview.tsx +183 -67
- package/src/client/ChangeRequestsSection.tsx +234 -0
- package/src/client/ChangedFiles.module.css +5 -1
- package/src/client/ChangedFiles.tsx +72 -36
- package/src/client/ChangesLoading.module.css +110 -0
- package/src/client/ChangesLoading.tsx +69 -0
- package/src/client/ChangesTab.module.css +83 -114
- package/src/client/ChangesTab.tsx +331 -100
- package/src/client/ChangesTabTitle.tsx +3 -3
- package/src/client/DiffFile.tsx +241 -45
- package/src/client/EnvironmentRows.tsx +263 -0
- package/src/client/FileLabel.tsx +1 -1
- package/src/client/FileTreePane.tsx +11 -6
- package/src/client/{ForgeTab.module.css → Forge.module.css} +130 -275
- package/src/client/LensFilter.module.css +87 -0
- package/src/client/LensFilter.tsx +105 -0
- package/src/client/ReasonButton.tsx +23 -0
- package/src/client/ReviewComposer.module.css +2 -8
- package/src/client/ReviewComposer.tsx +27 -8
- package/src/client/ReviewControls.module.css +39 -0
- package/src/client/ReviewControls.tsx +71 -15
- package/src/client/ReviewThread.tsx +55 -30
- package/src/client/ReviewThreads.module.css +24 -0
- package/src/client/ReviewThreads.tsx +56 -21
- package/src/client/SessionHoverForge.tsx +2 -1
- package/src/client/SubmitReview.tsx +11 -8
- package/src/client/ThreadList.tsx +1 -1
- package/src/client/ViewOptionsMenu.tsx +19 -4
- package/src/client/WorktreeNameDialog.module.css +53 -0
- package/src/client/WorktreeNameDialog.tsx +93 -0
- package/src/client/WorktreeProgress.tsx +100 -35
- package/src/client/WorktreeToggle.module.css +121 -5
- package/src/client/WorktreeToggle.tsx +178 -61
- package/src/client/action-notices.ts +38 -0
- package/src/client/annotations.ts +105 -0
- package/src/client/branch-search.tsx +77 -0
- package/src/client/change-requests-store.ts +50 -0
- package/src/client/changes-address.ts +3 -1
- package/src/client/changes-service.ts +173 -0
- package/src/client/changes-store.ts +103 -91
- package/src/client/checkout.ts +2 -1
- package/src/client/diff-rows.ts +100 -16
- package/src/client/file-tree.ts +29 -0
- package/src/client/forge-copy.ts +49 -0
- package/src/client/format.ts +14 -0
- package/src/client/glyphs.tsx +12 -13
- package/src/client/highlight-context.ts +213 -0
- package/src/client/index.ts +20 -5
- package/src/client/lens-filter.ts +136 -0
- package/src/client/locales.ts +1504 -288
- package/src/client/mount.ts +228 -109
- package/src/client/review-page/ReviewChat.tsx +311 -0
- package/src/client/review-page/ReviewDetail.tsx +331 -0
- package/src/client/review-page/ReviewLabels.tsx +94 -0
- package/src/client/review-page/ReviewList.tsx +461 -0
- package/src/client/review-page/ReviewNav.tsx +47 -0
- package/src/client/review-page/ReviewPage.module.css +946 -0
- package/src/client/review-page/ReviewPage.tsx +287 -0
- package/src/client/review-page/ReviewStatus.tsx +259 -0
- package/src/client/review-page/host-stream.ts +63 -0
- package/src/client/review-page/review-lists.ts +207 -0
- package/src/client/review-page/review-mount.ts +228 -0
- package/src/client/review-page/review-store.ts +94 -0
- package/src/client/review-queue.ts +30 -0
- package/src/client/review-threads.ts +0 -12
- package/src/client/review.ts +27 -0
- package/src/client/slots.ts +92 -0
- package/src/client/source.ts +67 -43
- package/src/client/status.ts +16 -4
- package/src/git.ts +16 -38
- package/src/index.ts +900 -152
- package/src/lens-version.ts +27 -0
- package/src/lenses.ts +284 -0
- package/src/local-diff.ts +48 -1
- package/src/panel.ts +123 -28
- package/src/parse.ts +86 -10
- package/src/review-cache.ts +57 -37
- package/src/states.ts +38 -18
- package/src/types.ts +267 -21
- package/src/viewer-lists.ts +375 -0
- package/src/worktree.ts +64 -34
- package/lib/types/client/ForgeTab.d.ts +0 -65
- package/lib/types/client/ForgeTab.d.ts.map +0 -1
- package/lib/types/client/ForgeTab.js.map +0 -1
- package/lib/types/client/ForgeTabTitle.d.ts +0 -11
- package/lib/types/client/ForgeTabTitle.d.ts.map +0 -1
- package/lib/types/client/ForgeTabTitle.js.map +0 -1
- package/lib/types/client/HeaderButton.d.ts +0 -27
- package/lib/types/client/HeaderButton.d.ts.map +0 -1
- package/lib/types/client/HeaderButton.js.map +0 -1
- package/lib/types/client/LocalChangesCard.d.ts +0 -29
- package/lib/types/client/LocalChangesCard.d.ts.map +0 -1
- package/lib/types/client/LocalChangesCard.js.map +0 -1
- package/src/client/ForgeTab.tsx +0 -263
- package/src/client/ForgeTabTitle.tsx +0 -21
- package/src/client/HeaderButton.module.css +0 -29
- package/src/client/HeaderButton.tsx +0 -68
- package/src/client/LocalChangesCard.tsx +0 -83
package/src/client/diff-rows.ts
CHANGED
|
@@ -25,14 +25,42 @@ export interface SplitRow {
|
|
|
25
25
|
readonly right: SplitCell | null
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** Unchanged lines one step of a gap shows, and the most a gap shows on one click: the step of GitHub's and GitLab's diffs. */
|
|
29
|
+
export const EXPAND_STEP = 20
|
|
30
|
+
|
|
31
|
+
/** The lines a gap shows: `top` continue the hunk above it, `bottom` lead into the hunk below it. */
|
|
32
|
+
export interface GapReveal {
|
|
33
|
+
readonly top: number
|
|
34
|
+
readonly bottom: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** How a click expands a gap: one step down from the hunk above it, one step up from the hunk below it, or wholly. */
|
|
38
|
+
export type GapExpansion = 'down' | 'up' | 'all'
|
|
39
|
+
|
|
40
|
+
/** Where a gap sits: before the first hunk, between two hunks, or after the last hunk. */
|
|
41
|
+
export type GapEdge = 'leading' | 'middle' | 'trailing'
|
|
42
|
+
|
|
28
43
|
/** A run of drawn rows, or unchanged lines drawn as one row that expands them. */
|
|
29
44
|
export type DiffSegment =
|
|
30
45
|
| { readonly kind: 'rows'; readonly rows: readonly DiffRow[] }
|
|
31
46
|
/**
|
|
32
|
-
* `index` is the hunk the lines precede, or the hunk count for the lines after the last hunk;
|
|
33
|
-
*
|
|
47
|
+
* `index` is the hunk the lines precede, or the hunk count for the lines after the last hunk; `count` is null while
|
|
48
|
+
* the length of the file is unknown. The hidden lines are new-side lines `from` to `to`, null while unknown, whose old
|
|
49
|
+
* numbers are `offset` higher.
|
|
34
50
|
*/
|
|
35
|
-
| {
|
|
51
|
+
| {
|
|
52
|
+
readonly kind: 'gap'
|
|
53
|
+
readonly index: number
|
|
54
|
+
readonly count: number | null
|
|
55
|
+
readonly edge: GapEdge
|
|
56
|
+
readonly from: number
|
|
57
|
+
readonly to: number | null
|
|
58
|
+
readonly offset: number
|
|
59
|
+
}
|
|
60
|
+
/** Consecutive hunks a filter lens folds, drawn as one row that shows them, with the unchanged lines between them. */
|
|
61
|
+
| { readonly kind: 'folded'; readonly hunks: readonly number[] }
|
|
62
|
+
|
|
63
|
+
const NO_FOLDS: ReadonlySet<number> = new Set()
|
|
36
64
|
|
|
37
65
|
/** A line as drawn: without the carriage return of a CRLF line ending. */
|
|
38
66
|
function drawn(text: string): string {
|
|
@@ -140,37 +168,65 @@ function endsNewSide(hunk: ForgeDiffHunk): boolean {
|
|
|
140
168
|
/**
|
|
141
169
|
* Lay out one file as runs of rows separated by collapsed unchanged lines.
|
|
142
170
|
* Unchanged lines before a hunk, between hunks, and after the last hunk
|
|
143
|
-
* collapse into one gap each;
|
|
144
|
-
*
|
|
145
|
-
*
|
|
171
|
+
* collapse into one gap each; once `lines` is known, a gap draws the lines its
|
|
172
|
+
* reveal shows at its top and bottom, and a gap whose reveal covers it joins
|
|
173
|
+
* the rows around it. The lines after the last hunk are unknown until `lines`
|
|
174
|
+
* arrives, unless the file is new, deleted, or its last hunk reaches its end. Consecutive folded hunks draw as one
|
|
175
|
+
* folded segment that takes the unchanged lines between them too.
|
|
146
176
|
* @param file - one file of a diff.
|
|
147
177
|
* @param lines - the file's new side, which {@link matchesHunks} accepted, or undefined while it has not been read.
|
|
148
|
-
* @param open -
|
|
178
|
+
* @param open - the lines each expanded gap shows, by gap index.
|
|
179
|
+
* @param folded - indexes of the hunks a filter lens folds.
|
|
149
180
|
* @returns the segments in file order.
|
|
150
181
|
*/
|
|
151
|
-
export function segmentsOf(
|
|
182
|
+
export function segmentsOf(
|
|
183
|
+
file: ForgeDiffFile, lines: readonly string[] | undefined, open: ReadonlyMap<number, GapReveal>, folded: ReadonlySet<number> = NO_FOLDS,
|
|
184
|
+
): DiffSegment[] {
|
|
152
185
|
const segments: DiffSegment[] = []
|
|
153
186
|
let rows: DiffRow[] = []
|
|
154
187
|
const flush = (): void => {
|
|
155
188
|
if (rows.length > 0) segments.push({ kind: 'rows', rows })
|
|
156
189
|
rows = []
|
|
157
190
|
}
|
|
191
|
+
/** Draw unchanged new-side lines `first` to `last` of the known file, whose old numbers are `offset` higher. */
|
|
192
|
+
const context = (known: readonly string[], first: number, last: number, offset: number): void => {
|
|
193
|
+
for (const [at, text] of known.slice(first - 1, last).entries()) {
|
|
194
|
+
rows.push({ kind: 'context', old: first + at + offset, new: first + at, text: drawn(text) })
|
|
195
|
+
}
|
|
196
|
+
}
|
|
158
197
|
/** Unchanged new-side lines `from` to `to`, null while unknown, whose old numbers are `offset` higher. */
|
|
159
198
|
const gap = (index: number, from: number, to: number | null, offset: number): void => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
199
|
+
const edge: GapEdge = index === 0 ? 'leading' : index === file.hunks.length ? 'trailing' : 'middle'
|
|
200
|
+
const reveal = open.get(index)
|
|
201
|
+
if (lines === undefined || to === null || reveal === undefined) {
|
|
202
|
+
flush()
|
|
203
|
+
segments.push({ kind: 'gap', index, count: to === null ? null : to - from + 1, edge, from, to, offset })
|
|
164
204
|
return
|
|
165
205
|
}
|
|
166
|
-
|
|
167
|
-
|
|
206
|
+
const total = to - from + 1
|
|
207
|
+
const top = Math.min(reveal.top, total)
|
|
208
|
+
const bottom = Math.min(reveal.bottom, total - top)
|
|
209
|
+
context(lines, from, from + top - 1, offset)
|
|
210
|
+
if (top + bottom < total) {
|
|
211
|
+
flush()
|
|
212
|
+
segments.push({ kind: 'gap', index, count: total - top - bottom, edge, from: from + top, to: to - bottom, offset })
|
|
213
|
+
}
|
|
214
|
+
context(lines, to - bottom + 1, to, offset)
|
|
168
215
|
}
|
|
169
216
|
let newEnd = 0
|
|
170
217
|
let oldEnd = 0
|
|
218
|
+
let run: number[] | null = null
|
|
171
219
|
for (const [index, hunk] of file.hunks.entries()) {
|
|
172
|
-
if (
|
|
173
|
-
|
|
220
|
+
if (run !== null && folded.has(index)) run.push(index)
|
|
221
|
+
else {
|
|
222
|
+
run = null
|
|
223
|
+
if (hunk.newStart - 1 > newEnd) gap(index, newEnd + 1, hunk.newStart - 1, hunk.oldStart - hunk.newStart)
|
|
224
|
+
if (folded.has(index)) {
|
|
225
|
+
flush()
|
|
226
|
+
run = [index]
|
|
227
|
+
segments.push({ kind: 'folded', hunks: run })
|
|
228
|
+
} else rows.push(...hunkRows(hunk))
|
|
229
|
+
}
|
|
174
230
|
newEnd = hunk.newStart + hunk.newLines - 1
|
|
175
231
|
oldEnd = hunk.oldStart + hunk.oldLines - 1
|
|
176
232
|
}
|
|
@@ -183,6 +239,34 @@ export function segmentsOf(file: ForgeDiffFile, lines: readonly string[] | undef
|
|
|
183
239
|
return segments
|
|
184
240
|
}
|
|
185
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Show more of one gap: a step down from the hunk above it, a step up from the hunk below it, or all of it.
|
|
244
|
+
* @param open - the lines each expanded gap of a file shows, by gap index.
|
|
245
|
+
* @param index - the gap.
|
|
246
|
+
* @param expansion - which way the gap expands.
|
|
247
|
+
* @returns the reveals with that gap's widened.
|
|
248
|
+
*/
|
|
249
|
+
export function revealGap(
|
|
250
|
+
open: ReadonlyMap<number, GapReveal> | undefined, index: number, expansion: GapExpansion,
|
|
251
|
+
): ReadonlyMap<number, GapReveal> {
|
|
252
|
+
const previous = open?.get(index) ?? { top: 0, bottom: 0 }
|
|
253
|
+
const next = expansion === 'all' ? { top: Number.POSITIVE_INFINITY, bottom: 0 }
|
|
254
|
+
: expansion === 'down' ? { ...previous, top: previous.top + EXPAND_STEP } : { ...previous, bottom: previous.bottom + EXPAND_STEP }
|
|
255
|
+
return new Map([...open ?? [], [index, next]])
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Whether a gap still hides a line.
|
|
260
|
+
* @param gap - the gap segment.
|
|
261
|
+
* @param side - the side that numbers the line.
|
|
262
|
+
* @param line - the line.
|
|
263
|
+
* @returns whether the line is among the gap's hidden lines.
|
|
264
|
+
*/
|
|
265
|
+
export function hidesLine(gap: Extract<DiffSegment, { kind: 'gap' }>, side: 'L' | 'R', line: number): boolean {
|
|
266
|
+
const at = side === 'L' ? line - gap.offset : line
|
|
267
|
+
return at >= gap.from && (gap.to === null || at <= gap.to)
|
|
268
|
+
}
|
|
269
|
+
|
|
186
270
|
/**
|
|
187
271
|
* Count the rows a file's hunks draw.
|
|
188
272
|
* @param file - one file of a diff.
|
package/src/client/file-tree.ts
CHANGED
|
@@ -69,6 +69,35 @@ export function filesInTreeOrder(nodes: readonly ChangedFileNode[]): readonly Fo
|
|
|
69
69
|
})
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Find the viewed files and the directories whose every file is viewed, which the tree draws subdued.
|
|
74
|
+
* @param nodes - the complete directory-first tree.
|
|
75
|
+
* @param viewed - paths of the files marked viewed at their current change.
|
|
76
|
+
* @returns the paths of those files and directories.
|
|
77
|
+
*/
|
|
78
|
+
export function viewedNodes(nodes: readonly ChangedFileNode[], viewed: ReadonlySet<string>): ReadonlySet<string> {
|
|
79
|
+
const done = new Set<string>()
|
|
80
|
+
const visit = (node: ChangedFileNode): boolean => {
|
|
81
|
+
switch (node.kind) {
|
|
82
|
+
case 'file':
|
|
83
|
+
if (!viewed.has(node.path)) return false
|
|
84
|
+
break
|
|
85
|
+
case 'directory': {
|
|
86
|
+
// Every child is visited, so viewed files below an unviewed sibling still count.
|
|
87
|
+
const children = node.children.map(visit)
|
|
88
|
+
if (!children.every(Boolean)) return false
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
/* v8 ignore next -- closed ChangedFileNode union exhaustiveness guard */
|
|
92
|
+
default: return assertNever(node, 'ChangedFileNode')
|
|
93
|
+
}
|
|
94
|
+
done.add(node.path)
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
for (const node of nodes) visit(node)
|
|
98
|
+
return done
|
|
99
|
+
}
|
|
100
|
+
|
|
72
101
|
/**
|
|
73
102
|
* Keep matching files and their ancestors without changing directory identities.
|
|
74
103
|
* @param nodes - the complete compacted tree.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Copy of one changes view that names the change request's code host and what the host calls a change request. */
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import type { ForgeDescription } from '@deepseek-ai/dsh-experimental-forge/types'
|
|
5
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
6
|
+
import type { NS } from './locales.ts'
|
|
7
|
+
|
|
8
|
+
/** The `forge` and `noun` parameters of copy that names the code host; a type alias so it passes as notice parameters. */
|
|
9
|
+
export type HostParams = {
|
|
10
|
+
/** Product name of the code host, such as `GitHub`. */
|
|
11
|
+
readonly forge: string
|
|
12
|
+
/** The code host's word for a change request, such as `PR`. */
|
|
13
|
+
readonly noun: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The view's copy, given the `forge` and `noun` parameters, and those parameters for its notices. */
|
|
17
|
+
export interface ForgeCopy {
|
|
18
|
+
/** Translate a key; the caller's parameters override `forge` and `noun`. */
|
|
19
|
+
readonly t: TranslateNS<typeof NS>
|
|
20
|
+
/** The parameters, for notices whose copy names the code host. */
|
|
21
|
+
readonly host: HostParams
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Give every string of a changes view the code host's name as `forge` and its word for a change request as `noun`.
|
|
26
|
+
* Without a provider for the change request, `forge` is the host name of its URL and `noun` the pull request word,
|
|
27
|
+
* which only appears beside the read failures such a view shows.
|
|
28
|
+
* @param translate - forge panel copy.
|
|
29
|
+
* @param url - web URL of the change request, or null for local changes.
|
|
30
|
+
* @param forge - how the change request's provider names itself, or null without one.
|
|
31
|
+
* @returns copy with both parameters, and the parameters.
|
|
32
|
+
*/
|
|
33
|
+
export function useForgeCopy(translate: TranslateNS<typeof NS>, url: string | null, forge: ForgeDescription | null): ForgeCopy {
|
|
34
|
+
const label = forge?.label ?? (url === null ? '' : hostOf(url))
|
|
35
|
+
const noun = translate(forge?.changeRequestNoun === 'merge-request' ? 'noun.mergeRequest' : 'noun.pullRequest')
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
const host = { forge: label, noun }
|
|
38
|
+
return { t: (key, params) => translate(key, { ...host, ...params }), host }
|
|
39
|
+
}, [translate, label, noun])
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Read the host name of a web URL.
|
|
44
|
+
* @param url - web URL.
|
|
45
|
+
* @returns the host as written, or the whole URL when it names none.
|
|
46
|
+
*/
|
|
47
|
+
function hostOf(url: string): string {
|
|
48
|
+
return /^[a-z][a-z\d+.-]*:\/\/([^/?#]+)/i.exec(url)?.[1] ?? url
|
|
49
|
+
}
|
package/src/client/format.ts
CHANGED
|
@@ -35,3 +35,17 @@ export function formatAgo(iso: string, now: number, t: Translate): string | unde
|
|
|
35
35
|
const { unit, n } = relativeTime(at, now)
|
|
36
36
|
return t(`time.${unit}`, { n })
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Format how long ago an ISO time was in the compact form a one-line list row shows, such as 5分钟 or 2d.
|
|
41
|
+
* @param iso - ISO 8601 time.
|
|
42
|
+
* @param now - current epoch milliseconds.
|
|
43
|
+
* @param t - forge panel copy.
|
|
44
|
+
* @returns the label, or undefined for an unparsable time.
|
|
45
|
+
*/
|
|
46
|
+
export function formatShortAgo(iso: string, now: number, t: Translate): string | undefined {
|
|
47
|
+
const at = Date.parse(iso)
|
|
48
|
+
if (!Number.isFinite(at)) return undefined
|
|
49
|
+
const { unit, n } = relativeTime(at, now)
|
|
50
|
+
return t(`time.short.${unit}`, { n })
|
|
51
|
+
}
|
package/src/client/glyphs.tsx
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import type { ReactNode } from 'react'
|
|
4
4
|
import clsx from 'clsx'
|
|
5
|
-
import { IconCheckCircleFillRegular
|
|
5
|
+
import { IconCheckCircleFillRegular } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
6
6
|
import type { CheckState, ChecksRollup } from '@deepseek-ai/dsh-experimental-forge/types'
|
|
7
7
|
import type { ChangeRequestTone } from './status.ts'
|
|
8
|
-
import css from './
|
|
8
|
+
import css from './Forge.module.css'
|
|
9
9
|
|
|
10
10
|
const BRANCH_ENDS = (
|
|
11
11
|
<>
|
|
@@ -125,25 +125,24 @@ const CHECK_TONE: Record<CheckState, string | undefined> = {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* Draw the decorative outcome of one check beside its text: a
|
|
129
|
-
* for
|
|
130
|
-
*
|
|
128
|
+
* Draw the decorative outcome of one check beside its text, each inside the same ring: a check for success, a cross
|
|
129
|
+
* for failure, a half fill while it runs, and a dash for neutral, skipped, and cancelled checks. The ring has the
|
|
130
|
+
* radius and width of the success icon's, so mixed outcomes read as one set.
|
|
131
131
|
* @param props.state - check outcome.
|
|
132
132
|
* @param props.size - width and height in pixels, 16 by default.
|
|
133
133
|
* @returns the glyph.
|
|
134
134
|
*/
|
|
135
135
|
export function CheckGlyph({ state, size = 16 }: { readonly state: CheckState; readonly size?: number | undefined }): ReactNode {
|
|
136
|
-
const running = state === 'pending'
|
|
137
136
|
return (
|
|
138
137
|
<span className={clsx(css.checkGlyph, CHECK_TONE[state])} data-forge-check={state} aria-hidden="true">
|
|
139
|
-
{state === 'success'
|
|
140
|
-
{state === 'failure' && <IconCloseCircleFillRegular size={size} />}
|
|
141
|
-
{state !== 'success' && state !== 'failure' && (
|
|
138
|
+
{state === 'success' ? <IconCheckCircleFillRegular size={size} /> : (
|
|
142
139
|
<svg width={size} height={size} viewBox="0 0 16 16" fill="none">
|
|
143
|
-
<circle cx="8" cy="8" r="
|
|
144
|
-
{
|
|
145
|
-
? <path d="
|
|
146
|
-
:
|
|
140
|
+
<circle cx="8" cy="8" r="7.25" stroke="currentColor" strokeWidth={1.3} />
|
|
141
|
+
{state === 'failure'
|
|
142
|
+
? <path d="M5.9 5.9L10.1 10.1M10.1 5.9L5.9 10.1" stroke="currentColor" strokeWidth={1.5} strokeLinecap="square" />
|
|
143
|
+
: state === 'pending'
|
|
144
|
+
? <path d="M8 2.8A5.2 5.2 0 0 1 8 13.2Z" fill="currentColor" />
|
|
145
|
+
: <path d="M5.5 8H10.5" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" />}
|
|
147
146
|
</svg>
|
|
148
147
|
)}
|
|
149
148
|
</span>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlighting of drawn rows with the lines before them. A run of rows drawn after collapsed unchanged lines is
|
|
3
|
+
* highlighted again with up to {@link HIGHLIGHT_CONTEXT_LINES} lines of the file before it, so a code block, comment,
|
|
4
|
+
* or string that opens in the collapsed lines colors the run as it does in the whole file. Constructs that open further
|
|
5
|
+
* back keep the colors of the run alone.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useCallback, useEffect, useRef, useState, type RefObject } from 'react'
|
|
9
|
+
import type { CodeHighlighter, HighlightSpan } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
10
|
+
import type { ForgeDiffHunk } from '../types.ts'
|
|
11
|
+
import type { DiffRow } from './diff-rows.ts'
|
|
12
|
+
|
|
13
|
+
/** Lines before a run that its highlighting reads; one call stays within an idle period for the slower grammars. */
|
|
14
|
+
export const HIGHLIGHT_CONTEXT_LINES = 120
|
|
15
|
+
|
|
16
|
+
/** Tokens of one side's lines by line number. */
|
|
17
|
+
export type LineSpans = ReadonlyMap<number, readonly HighlightSpan[]>
|
|
18
|
+
|
|
19
|
+
/** One side of one run of rows: its first and last line numbers and their texts. */
|
|
20
|
+
export interface SideRun {
|
|
21
|
+
readonly side: 'old' | 'new'
|
|
22
|
+
readonly first: number
|
|
23
|
+
readonly last: number
|
|
24
|
+
readonly texts: readonly string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A line as drawn: without the carriage return of a CRLF line ending. */
|
|
28
|
+
function drawn(text: string): string {
|
|
29
|
+
return text.endsWith('\r') ? text.slice(0, -1) : text
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Rebuild the old side of a file from its new side and the hunks of its diff.
|
|
34
|
+
* @param lines - the new side, which the hunks describe.
|
|
35
|
+
* @param hunks - the hunks, in file order.
|
|
36
|
+
* @returns the old side's lines.
|
|
37
|
+
*/
|
|
38
|
+
export function oldSideLines(lines: readonly string[], hunks: readonly ForgeDiffHunk[]): string[] {
|
|
39
|
+
const old: string[] = []
|
|
40
|
+
// Lines are appended one at a time: spreading a long run of unchanged lines into push would exceed the argument limit.
|
|
41
|
+
const copy = (from: number, to?: number): void => {
|
|
42
|
+
for (const line of lines.slice(from - 1, to)) old.push(line)
|
|
43
|
+
}
|
|
44
|
+
let at = 1
|
|
45
|
+
for (const hunk of hunks) {
|
|
46
|
+
copy(at, hunk.newStart - 1)
|
|
47
|
+
at = Math.max(at, hunk.newStart)
|
|
48
|
+
for (const line of hunk.lines) {
|
|
49
|
+
const sign = line.charAt(0)
|
|
50
|
+
if (sign === ' ' || sign === '-') old.push(line.slice(1))
|
|
51
|
+
if (sign === ' ' || sign === '+') at++
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
copy(at)
|
|
55
|
+
return old
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One side of a run of rows, which numbers its lines consecutively.
|
|
60
|
+
* @param rows - the run.
|
|
61
|
+
* @param side - the side.
|
|
62
|
+
* @returns the side's lines, or undefined when the run has none on that side.
|
|
63
|
+
*/
|
|
64
|
+
export function sideRun(rows: readonly DiffRow[], side: 'old' | 'new'): SideRun | undefined {
|
|
65
|
+
const numbers: number[] = []
|
|
66
|
+
const texts: string[] = []
|
|
67
|
+
for (const row of rows) {
|
|
68
|
+
const no = row[side]
|
|
69
|
+
if (no === null) continue
|
|
70
|
+
numbers.push(no)
|
|
71
|
+
texts.push(row.text)
|
|
72
|
+
}
|
|
73
|
+
const first = numbers[0]
|
|
74
|
+
const last = numbers.at(-1)
|
|
75
|
+
return first === undefined || last === undefined ? undefined : { side, first, last, texts }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Highlight one side of a run after the lines of the file before it.
|
|
80
|
+
* @param run - the side of the run.
|
|
81
|
+
* @param file - the whole side the run belongs to.
|
|
82
|
+
* @param highlighter - the file's highlighter.
|
|
83
|
+
* @returns the run's tokens by line number, null when nothing precedes the run, or undefined while the grammar is
|
|
84
|
+
* unavailable.
|
|
85
|
+
*/
|
|
86
|
+
export function contextSpans(run: SideRun, file: readonly string[], highlighter: CodeHighlighter): LineSpans | null | undefined {
|
|
87
|
+
const start = Math.max(1, run.first - HIGHLIGHT_CONTEXT_LINES)
|
|
88
|
+
if (start === run.first) return null
|
|
89
|
+
const context = file.slice(start - 1, run.first - 1).map(drawn)
|
|
90
|
+
const highlighted = highlighter([...context, ...run.texts].join('\n'))
|
|
91
|
+
if (highlighted === undefined) return undefined
|
|
92
|
+
// Shiki omits a final empty token row, so a final empty line gets no tokens.
|
|
93
|
+
return new Map(run.texts.map((_text, index) => [run.first + index, highlighted[context.length + index] ?? []]))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whole sides of a file: the new side as read, and the old side rebuilt from it. */
|
|
97
|
+
export interface FileSides {
|
|
98
|
+
readonly old: readonly string[]
|
|
99
|
+
readonly new: readonly string[]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Key of one side of a run in one change of a file, which its tokens are kept under. Tokens carry the text of their
|
|
104
|
+
* lines, so the key names the change: the same lines of another change of the file never take these tokens.
|
|
105
|
+
* @param change - the digest of the file's change.
|
|
106
|
+
* @param run - the side of the run.
|
|
107
|
+
* @returns the key.
|
|
108
|
+
*/
|
|
109
|
+
export function runKey(change: string, run: SideRun): string {
|
|
110
|
+
return `${change}:${run.side}:${String(run.first)}:${String(run.last)}`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const NO_SPANS: ReadonlyMap<string, LineSpans> = new Map()
|
|
114
|
+
|
|
115
|
+
/** Schedule work for an idle period, or soon where the browser offers none. */
|
|
116
|
+
function whenIdle(work: () => void): () => void {
|
|
117
|
+
if (typeof requestIdleCallback === 'function') {
|
|
118
|
+
const handle = requestIdleCallback(work, { timeout: 2000 })
|
|
119
|
+
return () => { cancelIdleCallback(handle) }
|
|
120
|
+
}
|
|
121
|
+
const handle = setTimeout(work, 16)
|
|
122
|
+
return () => { clearTimeout(handle) }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Whether the reader holds a text selection inside an element. */
|
|
126
|
+
function selectsIn(element: HTMLElement | null): boolean {
|
|
127
|
+
const selection = window.getSelection()
|
|
128
|
+
return element !== null && selection !== null && !selection.isCollapsed && element.contains(selection.anchorNode)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Highlight each side of each run again with the lines before it, one side of one run per idle period, once the whole
|
|
133
|
+
* file is known. The tokens apply in one update when every run is done and only while the reader selects nothing
|
|
134
|
+
* inside `root`, since redrawn tokens would drop the selection; a selection or drag defers them until it ends. Tokens
|
|
135
|
+
* are kept under the change they were computed for, so another change of the file finds none of them, even before its
|
|
136
|
+
* text is read; a new reading of the text starts the work over.
|
|
137
|
+
* @param runs - the sides of the drawn runs.
|
|
138
|
+
* @param sides - the whole file, or undefined while it is unknown.
|
|
139
|
+
* @param change - the digest of the file's change, which every key names.
|
|
140
|
+
* @param highlighter - the file's highlighter; a grammar that loads later resumes the work.
|
|
141
|
+
* @param root - the element whose selection defers the update.
|
|
142
|
+
* @param selecting - whether the reader is dragging a selection.
|
|
143
|
+
* @returns the corrected tokens by {@link runKey}.
|
|
144
|
+
*/
|
|
145
|
+
export function useContextHighlight(
|
|
146
|
+
runs: readonly SideRun[], sides: FileSides | undefined, change: string, highlighter: CodeHighlighter,
|
|
147
|
+
root: RefObject<HTMLElement | null>, selecting: boolean,
|
|
148
|
+
): ReadonlyMap<string, LineSpans> {
|
|
149
|
+
const [applied, setApplied] = useState(NO_SPANS)
|
|
150
|
+
const shown = useRef(applied)
|
|
151
|
+
shown.current = applied
|
|
152
|
+
const cache = useRef<{ sides: FileSides | undefined; spans: Map<string, LineSpans | null> }>({ sides: undefined, spans: new Map() })
|
|
153
|
+
const pending = useRef<ReadonlyMap<string, LineSpans> | null>(null)
|
|
154
|
+
const held = useRef(selecting)
|
|
155
|
+
held.current = selecting
|
|
156
|
+
// Applies the pending tokens unless the reader is selecting, else tries again at each selection change until they apply.
|
|
157
|
+
const attempt = (): void => {
|
|
158
|
+
if (pending.current === null) return
|
|
159
|
+
if (held.current || selectsIn(root.current)) {
|
|
160
|
+
document.addEventListener('selectionchange', retry)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
document.removeEventListener('selectionchange', retry)
|
|
164
|
+
setApplied(pending.current)
|
|
165
|
+
pending.current = null
|
|
166
|
+
}
|
|
167
|
+
const latest = useRef(attempt)
|
|
168
|
+
latest.current = attempt
|
|
169
|
+
const retry = useCallback((): void => { latest.current() }, [])
|
|
170
|
+
useEffect(() => () => { document.removeEventListener('selectionchange', retry) }, [retry])
|
|
171
|
+
useEffect(() => { if (!selecting) retry() }, [selecting, retry])
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (sides === undefined) return
|
|
174
|
+
if (cache.current.sides !== sides) {
|
|
175
|
+
cache.current = { sides, spans: new Map() }
|
|
176
|
+
pending.current = null
|
|
177
|
+
setApplied(NO_SPANS)
|
|
178
|
+
}
|
|
179
|
+
const spans = cache.current.spans
|
|
180
|
+
const waiting = runs.filter(run => !spans.has(runKey(change, run)))
|
|
181
|
+
let cancel = (): void => {}
|
|
182
|
+
const finish = (): void => {
|
|
183
|
+
const done = new Map<string, LineSpans>()
|
|
184
|
+
for (const run of runs) {
|
|
185
|
+
const key = runKey(change, run)
|
|
186
|
+
const value = spans.get(key)
|
|
187
|
+
if (value !== undefined && value !== null) done.set(key, value)
|
|
188
|
+
}
|
|
189
|
+
// Tokens the view already shows need no update, which would redraw every row of the file.
|
|
190
|
+
const current = shown.current
|
|
191
|
+
if (done.size === current.size && [...done].every(([key, value]) => current.get(key) === value)) return
|
|
192
|
+
pending.current = done
|
|
193
|
+
retry()
|
|
194
|
+
}
|
|
195
|
+
const next = (at: number): void => {
|
|
196
|
+
const run = waiting[at]
|
|
197
|
+
if (run === undefined) {
|
|
198
|
+
finish()
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
cancel = whenIdle(() => {
|
|
202
|
+
const value = contextSpans(run, sides[run.side], highlighter)
|
|
203
|
+
// A grammar still loading leaves the rest to the highlighter that arrives with it.
|
|
204
|
+
if (value === undefined) return
|
|
205
|
+
spans.set(runKey(change, run), value)
|
|
206
|
+
next(at + 1)
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
next(0)
|
|
210
|
+
return () => { cancel() }
|
|
211
|
+
}, [runs, sides, change, highlighter, retry])
|
|
212
|
+
return applied
|
|
213
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser entry of the forge panel: the
|
|
3
|
-
*
|
|
2
|
+
* Browser entry of the forge panel: the Session panel's change requests
|
|
3
|
+
* section, Environment rows, and attention indicator, the changes view, the
|
|
4
|
+
* worktree option and creation card, and their Remote.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import type { Context } from '@deepseek-ai/cordis'
|
|
@@ -11,12 +12,26 @@ export { inject } from './mount.ts'
|
|
|
11
12
|
export type { ForgePanelKey } from './locales.ts'
|
|
12
13
|
export type { ChangeRequestActions, ChangeRequestCardProps } from './ChangeRequestCard.tsx'
|
|
13
14
|
export type { ChangesParams, ChangesSource, ChangesTarget } from './changes-address.ts'
|
|
15
|
+
export type {
|
|
16
|
+
ForgeAnnotationSource, ForgeChangesService, ForgeChangesSidebar, ForgeLensDescription, ForgeLineAnnotation,
|
|
17
|
+
} from './changes-service.ts'
|
|
18
|
+
export type {
|
|
19
|
+
ForgeChangeRequestCardActionsProps, ForgeChangesFileMenuProps, ForgeChangesToolbarProps, ForgeCommentActionsProps,
|
|
20
|
+
ForgeLineAnnotationProps,
|
|
21
|
+
} from './slots.ts'
|
|
22
|
+
// The Host face's lens and extension types that the slot owner props and the changes view surface name.
|
|
23
|
+
export type {
|
|
24
|
+
ForgeExtensionState, ForgeLensFile, ForgeLensFrame, ForgeLensId, ForgeLensKeep, ForgeLensRequest, ForgeLineRange,
|
|
25
|
+
ForgeRegisteredLens,
|
|
26
|
+
} from '../types.ts'
|
|
14
27
|
export type { ChangesTabInjected, ChangesTabProps } from './ChangesTab.tsx'
|
|
15
28
|
export type { ChangesTabTitleProps } from './ChangesTabTitle.tsx'
|
|
16
29
|
export type { DiffFileAction, DiffFileProps, DiffFileText } from './DiffFile.tsx'
|
|
17
|
-
export type {
|
|
18
|
-
export type {
|
|
19
|
-
|
|
30
|
+
export type { AttentionIndicatorInjected, AttentionIndicatorProps } from './AttentionIndicator.tsx'
|
|
31
|
+
export type {
|
|
32
|
+
ChangeRequestsActionsInjected, ChangeRequestsActionsProps, ChangeRequestsSectionInjected, ChangeRequestsSectionProps,
|
|
33
|
+
} from './ChangeRequestsSection.tsx'
|
|
34
|
+
export type { CheckoutRowInjected, CheckoutRowProps, LocalChangesRowInjected, LocalChangesRowProps } from './EnvironmentRows.tsx'
|
|
20
35
|
export type { WorktreeProgressInjected, WorktreeProgressProps } from './WorktreeProgress.tsx'
|
|
21
36
|
export type { WorktreeToggleInjected, WorktreeToggleProps } from './WorktreeToggle.tsx'
|
|
22
37
|
export type { ActionNotice, NoticeOptions, PanelSnapshot } from './source.ts'
|