dsh-remote-vs 0.27.0 → 0.28.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.en.md +110 -19
- package/README.md +82 -19
- package/lib/client.js +6789 -6607
- package/lib/index.js +546 -16
- package/lib/types/changes/recorder.d.ts +119 -2
- package/lib/types/client/CodeEditor.d.ts +15 -0
- package/lib/types/client/api.d.ts +17 -1
- package/lib/types/client/changes/apply-failure.d.ts +41 -0
- package/lib/types/client/changes/block-confirm.d.ts +97 -0
- package/lib/types/client/changes/diff-outcome.d.ts +56 -0
- package/lib/types/client/changes/freshness.d.ts +51 -0
- package/lib/types/client/changes/model.d.ts +19 -1
- package/lib/types/client/changes/session-diff.d.ts +100 -0
- package/lib/types/client/changes/staleness.d.ts +98 -0
- package/lib/types/client/changes/turn-reverted.d.ts +82 -0
- package/lib/types/client/changes/turn-view.d.ts +131 -0
- package/lib/types/client/changes/undo-affordance.d.ts +44 -10
- package/lib/types/client/changes/undo-target.d.ts +12 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +91 -1
- package/lib/types/client/vsc/change-marks.d.ts +21 -0
- package/lib/types/protocol.d.ts +99 -1
- package/package.json +1 -1
- package/src/changes/recorder.ts +851 -8
- package/src/client/CodeEditor.tsx +43 -3
- package/src/client/EditorPane.tsx +64 -7
- package/src/client/api.ts +30 -3
- package/src/client/changes/ChangesDock.tsx +539 -54
- package/src/client/changes/apply-failure.ts +73 -0
- package/src/client/changes/block-confirm.ts +180 -0
- package/src/client/changes/changes.css +45 -0
- package/src/client/changes/diff-outcome.ts +97 -0
- package/src/client/changes/freshness.ts +68 -0
- package/src/client/changes/model.ts +56 -1
- package/src/client/changes/session-diff.ts +187 -0
- package/src/client/changes/staleness.ts +148 -0
- package/src/client/changes/turn-reverted.ts +254 -0
- package/src/client/changes/turn-view.ts +195 -0
- package/src/client/changes/undo-affordance.ts +295 -63
- package/src/client/changes/undo-target.ts +12 -0
- package/src/client/i18n.ts +102 -4
- package/src/client/scm/DiffView.tsx +32 -13
- package/src/client/store.tsx +392 -16
- package/src/client/vsc/change-marks.ts +21 -0
- package/src/client/vsc/preview-document.tsx +4 -1
- package/src/client/vsc/vsc.css +6642 -6509
- package/src/protocol.ts +101 -1
- package/src/routes.ts +20 -9
|
@@ -153,7 +153,13 @@ import {
|
|
|
153
153
|
} from './vsc/change-marks.ts'
|
|
154
154
|
import { blameExtension, blameViewportReporter } from './vsc/blame.ts'
|
|
155
155
|
import type { BlameLine } from './blame-model.ts'
|
|
156
|
-
import {
|
|
156
|
+
import {
|
|
157
|
+
DEFAULT_CONFIRM_LABEL,
|
|
158
|
+
DEFAULT_CONFIRMED_LABEL,
|
|
159
|
+
DEFAULT_TRIGGER_LABEL,
|
|
160
|
+
DEFAULT_UNDO_LABEL,
|
|
161
|
+
undoAffordance,
|
|
162
|
+
} from './changes/undo-affordance.ts'
|
|
157
163
|
|
|
158
164
|
/**
|
|
159
165
|
* The editor surface is OPAQUE and scrolls in the editor's own palette
|
|
@@ -228,6 +234,21 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
228
234
|
onUndoChange?: (mark: ChangeMark) => void
|
|
229
235
|
/** 悬浮按钮的文案(由调用方按 `kind` 给出它的 i18n 说法)。 */
|
|
230
236
|
undoLabel?: (mark: ChangeMark) => string
|
|
237
|
+
/** 行尾那枚 `⋯` 的说明(title / aria-label,调用方传 i18n)。 */
|
|
238
|
+
undoTriggerLabel?: () => string
|
|
239
|
+
/**
|
|
240
|
+
* 悬浮栏的第二个动作:「确认保留」(块级本地笔记,见 `changes/block-confirm.ts`)。
|
|
241
|
+
*
|
|
242
|
+
* 不传 = 悬浮栏只有撤销一个动作(与没有这个功能时完全一致)。传了也只是把
|
|
243
|
+
* 读/切换交回去:存储、会话归属都在调用方那一侧,编辑器组件不持有这份状态,更
|
|
244
|
+
* 不会因为它写任何远端。
|
|
245
|
+
*/
|
|
246
|
+
blockConfirm?: {
|
|
247
|
+
isConfirmed: (mark: ChangeMark) => boolean
|
|
248
|
+
onToggle: (mark: ChangeMark) => void
|
|
249
|
+
label: (mark: ChangeMark) => string
|
|
250
|
+
pressedLabel?: (mark: ChangeMark) => string
|
|
251
|
+
}
|
|
231
252
|
/** 改动点跳转的目标行(1-based),配合 `revealHunkNonce` 重跳同一行。 */
|
|
232
253
|
revealHunkLine?: number
|
|
233
254
|
/** 改动点跳转的 nonce(同 `revealNonce` 的道理)。 */
|
|
@@ -412,6 +433,12 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
412
433
|
*/
|
|
413
434
|
const labelsRef = useRef(t)
|
|
414
435
|
const undoArmed = props.onUndoChange !== undefined
|
|
436
|
+
/**
|
|
437
|
+
* 「确认保留」是否可用也是**能力**的一部分:它随"这批标记有没有块标识"一起到达,
|
|
438
|
+
* 所以要进 `armed` 键 —— 否则先挂载、后拿到标记的编辑器永远不会重装扩展,第二个
|
|
439
|
+
* 按钮就再也不会出现。
|
|
440
|
+
*/
|
|
441
|
+
const confirmArmed = props.blockConfirm !== undefined
|
|
415
442
|
useEffect(() => {
|
|
416
443
|
const current = viewRef.current
|
|
417
444
|
if (current === undefined) return
|
|
@@ -421,7 +448,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
421
448
|
}
|
|
422
449
|
const set = props.changeSet
|
|
423
450
|
const marks = set !== undefined
|
|
424
|
-
const armed = `${marks ? 'm' : ''}${undoArmed ? 'u' : ''}`
|
|
451
|
+
const armed = `${marks ? 'm' : ''}${undoArmed ? 'u' : ''}${confirmArmed ? 'c' : ''}`
|
|
425
452
|
if (armed !== armedRef.current) {
|
|
426
453
|
armedRef.current = armed
|
|
427
454
|
// 重装扩展会重建字段,之前下发过的数据随之消失,必须再喂一次。
|
|
@@ -432,6 +459,19 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
432
459
|
? [undoAffordance({
|
|
433
460
|
onUndo: (mark) => { propsRef.current.onUndoChange?.(mark) },
|
|
434
461
|
label: (mark) => propsRef.current.undoLabel?.(mark) ?? DEFAULT_UNDO_LABEL,
|
|
462
|
+
triggerLabel: () => propsRef.current.undoTriggerLabel?.() ?? DEFAULT_TRIGGER_LABEL,
|
|
463
|
+
...(confirmArmed
|
|
464
|
+
? {
|
|
465
|
+
confirm: {
|
|
466
|
+
isConfirmed: (mark) => propsRef.current.blockConfirm?.isConfirmed(mark) === true,
|
|
467
|
+
onToggle: (mark) => { propsRef.current.blockConfirm?.onToggle(mark) },
|
|
468
|
+
label: (mark) => propsRef.current.blockConfirm?.label(mark) ?? DEFAULT_CONFIRM_LABEL,
|
|
469
|
+
pressedLabel: (mark) => propsRef.current.blockConfirm?.pressedLabel?.(mark)
|
|
470
|
+
?? propsRef.current.blockConfirm?.label(mark)
|
|
471
|
+
?? DEFAULT_CONFIRMED_LABEL,
|
|
472
|
+
},
|
|
473
|
+
}
|
|
474
|
+
: {}),
|
|
435
475
|
})]
|
|
436
476
|
: []),
|
|
437
477
|
]
|
|
@@ -449,7 +489,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
449
489
|
} catch {
|
|
450
490
|
// Disposed.
|
|
451
491
|
}
|
|
452
|
-
}, [props.changeSet, undoArmed, view, t])
|
|
492
|
+
}, [props.changeSet, undoArmed, confirmArmed, view, t])
|
|
453
493
|
|
|
454
494
|
/**
|
|
455
495
|
* Blame gutter: install/replace it when the pane hands over a new window.
|
|
@@ -29,6 +29,9 @@ import { sameLocalDir } from './composer.ts'
|
|
|
29
29
|
import { editorViewStateOf, pruneEditorViewStates, registerLiveEditor, rememberEditorViewState } from './live-editor.ts'
|
|
30
30
|
import { useRemoteChatTarget } from './use-remote-chat-target.ts'
|
|
31
31
|
import { useExplorer, gotoChange, markChangeStale, repoRelative, undoChange, type EditorTab } from './store.tsx'
|
|
32
|
+
import { blockIdForMark, isStoredBlockConfirmed, toggleStoredBlock, type ConfirmStorage } from './changes/block-confirm.ts'
|
|
33
|
+
import { changeOriginForTab } from './changes/undo-target.ts'
|
|
34
|
+
import type { ChangeMark } from './vsc/change-marks.ts'
|
|
32
35
|
import { DiffView } from './scm/DiffView.tsx'
|
|
33
36
|
import { loadBlame, loadFileHistory } from './scm/actions.ts'
|
|
34
37
|
import { isCommittedBlame, planBlameWindow, type BlameLine, type FileHistoryCommit } from './blame-model.ts'
|
|
@@ -88,12 +91,12 @@ function outlineAvailable(tab: EditorTab | undefined): tab is EditorTab {
|
|
|
88
91
|
const BLAME_PREF_KEY = 'dsh-remote-vs.editor.blame'
|
|
89
92
|
const EMPTY_BLAME: ReadonlyMap<number, BlameLine> = new Map()
|
|
90
93
|
|
|
91
|
-
/** Inline blame is
|
|
94
|
+
/** Inline blame is OFF by default; the user opts in and the choice survives a reload. */
|
|
92
95
|
function readBlamePreference(): boolean {
|
|
93
96
|
try {
|
|
94
|
-
return localStorage.getItem(BLAME_PREF_KEY)
|
|
97
|
+
return localStorage.getItem(BLAME_PREF_KEY) === '1'
|
|
95
98
|
} catch {
|
|
96
|
-
return
|
|
99
|
+
return false
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -1157,11 +1160,66 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1157
1160
|
*/
|
|
1158
1161
|
const canSwitchToEdit = activeTab !== undefined
|
|
1159
1162
|
&& activeTab.kind === 'diff'
|
|
1163
|
+
// 会话只读 diff 不开「切换为内容编辑」:它属于会话账本,编辑入口是面板左键
|
|
1164
|
+
// (会带着标记打开);这里再开一次只会打开一个没有标记的普通标签页。
|
|
1165
|
+
&& activeTab.sessionDiff === undefined
|
|
1160
1166
|
&& activeTab.ref === undefined
|
|
1161
1167
|
&& activeTab.diff !== undefined
|
|
1162
1168
|
&& !activeTab.diff.unsupported
|
|
1163
1169
|
&& !(activeTab.diff.newText === '' && activeTab.diff.oldText !== '')
|
|
1164
1170
|
const displayPath = activeTab?.fullPath ?? ''
|
|
1171
|
+
/**
|
|
1172
|
+
* 信息栏里那句"这一页是什么 diff"。
|
|
1173
|
+
*
|
|
1174
|
+
* 三种来源必须分得清:会话账本的只读比较、暂存区(只读)、某个提交(历史)。
|
|
1175
|
+
* 写成一串 if 而不是嵌套三元:三种情况各说各的,读起来不会串行。
|
|
1176
|
+
*/
|
|
1177
|
+
let diffScopeLabel = ''
|
|
1178
|
+
if (activeTab?.kind === 'diff') {
|
|
1179
|
+
if (activeTab.sessionDiff !== undefined) diffScopeLabel = t('changes.diffTabLabel')
|
|
1180
|
+
else if (activeTab.ref !== undefined) diffScopeLabel = `${t('scm.commitDiff')} ${activeTab.ref.slice(0, 7)}`
|
|
1181
|
+
else if (activeTab.staged) diffScopeLabel = t('scm.stagedReadonly')
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* 编辑器悬浮栏的「确认保留」(块级本地笔记,见 `changes/block-confirm.ts`)。
|
|
1185
|
+
*
|
|
1186
|
+
* 三个前提缺一不可:这一页有改动标记、标记带着块标识(建标记时带了远端绝对路径)、
|
|
1187
|
+
* 以及这批标记有 provenance(会话归属 —— 笔记按会话存)。任何一个缺失就不提供这个
|
|
1188
|
+
* 动作,悬浮栏回到"只有撤销"。
|
|
1189
|
+
*
|
|
1190
|
+
* 读写都走 `localStorage`,**不发任何请求**:这是"我看到哪儿了"的记号,不是远端
|
|
1191
|
+
* 事实;状态变化不经过 React(编辑器在 React 之外点它),所以每次现读。
|
|
1192
|
+
*/
|
|
1193
|
+
const blockConfirm = (() => {
|
|
1194
|
+
const set = activeTab?.changeSet
|
|
1195
|
+
if (activeTab === undefined || set === undefined || set === null) return undefined
|
|
1196
|
+
const blocks = set.blocks
|
|
1197
|
+
const sessionId = changeOriginForTab(activeTab.id)?.sessionId
|
|
1198
|
+
if (blocks === undefined || sessionId === undefined || sessionId === '') return undefined
|
|
1199
|
+
const storage = (): ConfirmStorage | undefined => {
|
|
1200
|
+
try {
|
|
1201
|
+
return window.localStorage
|
|
1202
|
+
} catch {
|
|
1203
|
+
// 隐私模式 / 禁用存储:不提供这一级(而不是给一个点了不生效的按钮)。
|
|
1204
|
+
return undefined
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return {
|
|
1208
|
+
isConfirmed: (mark: ChangeMark): boolean => {
|
|
1209
|
+
const id = blockIdForMark(blocks, mark)
|
|
1210
|
+
const store = storage()
|
|
1211
|
+
return id === undefined || store === undefined ? false : isStoredBlockConfirmed(store, sessionId, id)
|
|
1212
|
+
},
|
|
1213
|
+
onToggle: (mark: ChangeMark): void => {
|
|
1214
|
+
const id = blockIdForMark(blocks, mark)
|
|
1215
|
+
const store = storage()
|
|
1216
|
+
if (id === undefined || store === undefined) return
|
|
1217
|
+
toggleStoredBlock(store, sessionId, id)
|
|
1218
|
+
},
|
|
1219
|
+
label: (): string => t('changes.confirmBlock'),
|
|
1220
|
+
pressedLabel: (): string => t('changes.confirmedBlock'),
|
|
1221
|
+
}
|
|
1222
|
+
})()
|
|
1165
1223
|
const language = isDiff
|
|
1166
1224
|
? 'Diff'
|
|
1167
1225
|
: activeTab?.image === true
|
|
@@ -1281,10 +1339,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1281
1339
|
/>
|
|
1282
1340
|
)}
|
|
1283
1341
|
{activeTab.kind === 'diff' && (
|
|
1284
|
-
<span style={{ color: 'var(--rvs-fg3)' }}>
|
|
1285
|
-
{activeTab.staged && activeTab.ref === undefined ? t('scm.stagedReadonly') : ''}
|
|
1286
|
-
{activeTab.ref !== undefined ? `${t('scm.commitDiff')} ${activeTab.ref.slice(0, 7)}` : ''}
|
|
1287
|
-
</span>
|
|
1342
|
+
<span style={{ color: 'var(--rvs-fg3)' }}>{diffScopeLabel}</span>
|
|
1288
1343
|
)}
|
|
1289
1344
|
<span style={{ color: 'var(--rvs-fg3)' }}>{language}</span>
|
|
1290
1345
|
{/* Connection health sits where the build stamp does: it is the
|
|
@@ -1693,6 +1748,8 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1693
1748
|
onChangeStale={() => { markChangeStale(activeTab.id) }}
|
|
1694
1749
|
onUndoChange={(mark) => { void undoChange(activeTab.id, mark) }}
|
|
1695
1750
|
undoLabel={(mark) => undoActionLabel(t, mark.kind)}
|
|
1751
|
+
undoTriggerLabel={() => t('changes.actions')}
|
|
1752
|
+
{...(blockConfirm === undefined ? {} : { blockConfirm })}
|
|
1696
1753
|
onSave={() => { void saveActive() }}
|
|
1697
1754
|
onDirty={(dirty) => store.updateTab(activeTab.id, { dirty })}
|
|
1698
1755
|
onBuffer={(tabId, text) => store.updateTab(tabId, { text })}
|
package/src/client/api.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type HelperAvailability,
|
|
12
12
|
type ImportReport,
|
|
13
13
|
type RemoteChangesDiff,
|
|
14
|
+
type RemoteChangesListRequest,
|
|
14
15
|
type RemoteChangesSummary,
|
|
15
16
|
type RemoteConnectionStatus,
|
|
16
17
|
type RemoteDeployState,
|
|
@@ -642,13 +643,23 @@ export const api = {
|
|
|
642
643
|
* is opened for review.
|
|
643
644
|
*/
|
|
644
645
|
changes: {
|
|
645
|
-
|
|
646
|
-
|
|
646
|
+
/**
|
|
647
|
+
* @param force - `⟳` semantics: tracked scan now AND re-arm the slow new-file
|
|
648
|
+
* walk (expensive; a deliberate click).
|
|
649
|
+
* @param trackedOnly - "user came back to the page": tracked files now, but the
|
|
650
|
+
* slow walk keeps its cadence/write-off (see `RemoteChangesListRequest`).
|
|
651
|
+
*/
|
|
652
|
+
list: (sessionId: string, force = false, repoSubdir = '', trackedOnly = false) => {
|
|
653
|
+
const body: RemoteChangesListRequest = {
|
|
647
654
|
op: 'list',
|
|
648
655
|
sessionId,
|
|
649
656
|
...(force ? { force: true } : {}),
|
|
657
|
+
...(trackedOnly ? { trackedOnly: true } : {}),
|
|
650
658
|
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
651
|
-
}
|
|
659
|
+
}
|
|
660
|
+
return post<{ summary: RemoteChangesSummary | null }>(REMOTE_API.changes, body)
|
|
661
|
+
.then(r => r.summary ?? null)
|
|
662
|
+
},
|
|
652
663
|
diff: (sessionId: string, path: string, repoSubdir = '') =>
|
|
653
664
|
post<{ diff: RemoteChangesDiff | null }>(REMOTE_API.changes, {
|
|
654
665
|
op: 'diff',
|
|
@@ -656,6 +667,22 @@ export const api = {
|
|
|
656
667
|
path,
|
|
657
668
|
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
658
669
|
}).then(r => r.diff ?? null),
|
|
670
|
+
/**
|
|
671
|
+
* The same comparison, but against the previous completed turn's close
|
|
672
|
+
* instead of the session baseline (the panel's 「本轮」 scope).
|
|
673
|
+
*
|
|
674
|
+
* Answers `unavailable` / `stale` (with a reason) instead of hunks when the
|
|
675
|
+
* host has no cached per-turn contents or the file moved on after the turn —
|
|
676
|
+
* the client must fall back to `diff` (session view) rather than paint lines
|
|
677
|
+
* that no longer exist.
|
|
678
|
+
*/
|
|
679
|
+
turnDiff: (sessionId: string, path: string, repoSubdir = '') =>
|
|
680
|
+
post<{ diff: RemoteChangesDiff | null }>(REMOTE_API.changes, {
|
|
681
|
+
op: 'turnDiff',
|
|
682
|
+
sessionId,
|
|
683
|
+
path,
|
|
684
|
+
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
685
|
+
}).then(r => r.diff ?? null),
|
|
659
686
|
},
|
|
660
687
|
// -- routing mode (volatile, persists to the profile patch)
|
|
661
688
|
setRoutingMode: (mode: 'off' | 'shadow' | 'enforce') =>
|