dsh-vscode-mode 0.33.1 → 0.35.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.
@@ -8,7 +8,7 @@
8
8
  * 动作:svnUpdate / svnTortoise / svnRevert / svnAdd / svnDiffBase 统一执行与反馈文案。
9
9
  * 作者 ddj 2026年09月16号
10
10
  */
11
- import type { SvnAction, SvnAiPlan, SvnChangeEntry, SvnIgnoreItem, SvnItemStatus, SvnStatusPayload, SvnUpdateEntry } from '../shared/svn.js'
11
+ import type { SvnAction, SvnAiPlan, SvnChangeEntry, SvnIgnoreItem, SvnItemStatus, SvnPathKind, SvnStatusPayload, SvnUpdateEntry } from '../shared/svn.js'
12
12
  import { SVN_TORTOISE_LABELS, SVN_UPDATE_LABEL } from '../shared/svn.js'
13
13
  import { svnActionOn, svnActionsFor } from '../shared/svnActions.js'
14
14
  import type { SvnActionContext } from '../shared/svnActions.js'
@@ -614,6 +614,30 @@ export async function svnFileSizes(
614
614
  }
615
615
  }
616
616
 
617
+ /**
618
+ * 批量判型(窗口行图标用):磁盘上这些条目是文件、目录还是不存在。
619
+ *
620
+ * 未加载或调用失败返回空表:调用方按「非目录」回落文件图标,列表与动作不受影响。
621
+ * @author ddj 2026年11月23号
622
+ * @param sessionId 会话 id
623
+ * @param paths 工作副本相对路径列表(host 单次上限 PATH_KINDS_CAP,调用方分块)
624
+ * @returns 路径 → 类型表(不存在的路径不出现在表里)
625
+ */
626
+ export async function svnPathKinds(
627
+ sessionId: string | undefined,
628
+ paths: string[],
629
+ ): Promise<Record<string, SvnPathKind>> {
630
+ try {
631
+ const res = await rpc('svn.pathKinds', { sessionId, paths })
632
+ if (!res.ok) return {}
633
+ const table: Record<string, SvnPathKind> = {}
634
+ for (const item of res.kinds) table[item.path] = item.kind
635
+ return table
636
+ } catch (error) {
637
+ return {}
638
+ }
639
+ }
640
+
617
641
  // --endregion
618
642
 
619
643
  /**
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import React from 'react'
9
9
  import { openDiffView } from '../events.js'
10
+ import { recoverComposer, watchComposer } from '../composerState.js'
10
11
  import { diffSummary } from '../state/diffSummary.js'
11
12
  import { subscribeReview } from '../state/reviewFeed.js'
12
13
  import { subscribeRecords } from '../state/recordsFeed.js'
@@ -27,6 +28,12 @@ export function ConversationDiffDock(props) {
27
28
  const sessionId = props?.sessionId
28
29
  const [summary, setSummary] = React.useState(null)
29
30
  const [, setStoreRevision] = React.useState(0)
31
+ // 输入条槽崩溃后官方不会自愈:所有会话的输入框都会一直是空的,这里给出恢复入口
32
+ const [composerBroken, setComposerBroken] = React.useState(false)
33
+
34
+ React.useEffect(() => {
35
+ return watchComposer(typeof document === 'undefined' ? undefined : document, setComposerBroken)
36
+ }, [])
30
37
 
31
38
  React.useEffect(() => {
32
39
  if (!sessionId) {
@@ -57,14 +64,25 @@ export function ConversationDiffDock(props) {
57
64
  // 命令栏浮层的兜底宿主:本 dock 是每会话常驻 slot(编辑区未挂载时仍能唤起命令栏);
58
65
  // 与 EditorView 同时挂载时由 commandPaletteStore 的单实例认领保证只渲染一份。
59
66
  const palette = React.createElement(CommandPalette, { key: 'edrv-palette', sessionId })
67
+ const crashHint = composerBroken
68
+ ? renderDock(React.createElement('div', { className: 'edrv-composer-crash' },
69
+ React.createElement('span', { className: 'edrv-composer-crash-text' },
70
+ '对话输入框渲染失败(官方槽抛错后不会自愈),点右侧按钮恢复'),
71
+ React.createElement('button', {
72
+ type: 'button',
73
+ className: 'edrv-composer-crash-fix',
74
+ onClick: recoverComposer,
75
+ }, '恢复输入框')), 'edrv-composer-crash')
76
+ : null
60
77
  if (editorSnapshot) {
61
- if (!dockInLayout(editorSnapshot, 'tab')) return palette
78
+ if (!dockInLayout(editorSnapshot, 'tab')) return React.createElement(React.Fragment, null, crashHint, palette)
62
79
  return React.createElement(React.Fragment, null,
80
+ crashHint,
63
81
  renderDock(React.createElement(DiffBox, Object.assign({}, editorSnapshot, { dock: true })), sessionId),
64
82
  palette)
65
83
  }
66
84
 
67
- if (!sessionId || !summary?.pendingFiles?.length) return palette
85
+ if (!sessionId || !summary?.pendingFiles?.length) return React.createElement(React.Fragment, null, crashHint, palette)
68
86
 
69
87
  const paths = summary.pendingFiles.map((file) => file.path)
70
88
  const click = () => {
@@ -75,6 +93,7 @@ export function ConversationDiffDock(props) {
75
93
  }
76
94
 
77
95
  return React.createElement(React.Fragment, null,
96
+ crashHint,
78
97
  palette,
79
98
  renderDock(React.createElement(DiffBox, {
80
99
  mode: 'chat', dock: true, fileTotal: paths.length, onOpenNextFile: click,
@@ -19,6 +19,9 @@ import { SVN_ACTION_BY_ID } from '../../shared/svnActions.js'
19
19
  import type { SvnChangeEntry } from '../../shared/svn.js'
20
20
  import { SVN_STATUS_LABEL, SVN_STATUS_LETTER, SVN_STATUS_TONE } from '../../shared/svn.js'
21
21
  import { updateParent } from './svnUpdateModel.js'
22
+ import { entryIconEl } from './icons.js'
23
+ import { isDirOf } from './svnIcons.js'
24
+ import { useSvnEntryKinds } from './useSvnEntryKinds.js'
22
25
  import {
23
26
  commitActs,
24
27
  commitHintOf,
@@ -333,8 +336,8 @@ function msgMenuEntriesOf(s, menu) {
333
336
  }
334
337
 
335
338
  /**
336
- * 单条待提交文件(勾选 / 状态字母 / 路径),支持右键与键盘唤起菜单。
337
- * @author ddj 2026年11月15号 / 2026年11月21号
339
+ * 单条待提交文件(勾选 / 状态字母 / 图标 / 路径),支持右键与键盘唤起菜单。
340
+ * @author ddj 2026年11月15号 / 2026年11月21号 / 2026年11月23号
338
341
  * @param entry 变更条目 @param checked 是否勾选 @param onToggle 切换 @param s 视图状态(菜单与动作)
339
342
  * @returns 行元素
340
343
  */
@@ -358,6 +361,8 @@ function rowEl(entry, checked, onToggle, s) {
358
361
  role: 'cell',
359
362
  title: SVN_STATUS_LABEL[entry.status] ?? entry.status,
360
363
  }, SVN_STATUS_LETTER[entry.status] ?? '?'),
364
+ React.createElement('span', { className: 'edrv-svncommit-icon', role: 'cell', 'aria-hidden': true },
365
+ entryIconEl(entry.path, isDirOf(entry.path, s.dirs, s.kinds))),
361
366
  React.createElement('span', { className: 'edrv-svncommit-path', role: 'cell', title: entry.path }, entry.path))
362
367
  }
363
368
 
@@ -390,6 +395,7 @@ function tableEl(s) {
390
395
  React.createElement('div', { className: 'edrv-svncommit-cols' },
391
396
  React.createElement('span', null, '勾选'),
392
397
  React.createElement('span', null, '状态'),
398
+ React.createElement('span', { 'aria-hidden': true }),
393
399
  React.createElement('span', null, '路径')),
394
400
  React.createElement('div', { className: 'edrv-svncommit-list', role: 'table', 'aria-label': '待提交文件清单' }, ...body))
395
401
  }
@@ -732,8 +738,10 @@ export function SvnCommitDialog(props) {
732
738
  const s = useCommitState(sessionId, seed, notify, onCommitted, props.onChanged)
733
739
  const context = useCommitMenu()
734
740
  const rowPick = useRowPick(s.rowOrder)
741
+ const entryKind = useSvnEntryKinds(s.rowOrder, sessionId)
735
742
  const view = {
736
743
  ...s, onClose, notify, selection: rowPick.selected, pickRow: rowPick.choose,
744
+ dirs: entryKind.dirs, kinds: entryKind.kinds,
737
745
  menu: context.menu,
738
746
  menuOpen: (event, kind, entry, node) => context.open(event, kind, entry, node, pickPathsOf(rowPick, entry)),
739
747
  onCompare: props.onCompare, onShowLog: props.onShowLog,
@@ -3,7 +3,7 @@
3
3
  * @author ddj 2026年09月24号
4
4
  */
5
5
  import React from 'react'
6
- import type { SvnConflictState, SvnResolveAccept, SvnUpdateRow, SvnUpdateState } from '../../shared/svn.js'
6
+ import type { SvnConflictState, SvnPathKind, SvnResolveAccept, SvnUpdateRow, SvnUpdateState } from '../../shared/svn.js'
7
7
  import { copyText } from '../copyText.js'
8
8
  import { rpc } from '../rpc.js'
9
9
  import { absoluteOf } from '../tabActions.js'
@@ -12,6 +12,13 @@ import type { ContextMenuEntry } from './ContextMenu.js'
12
12
  import { FloatingWindow } from './FloatingWindow.js'
13
13
  import { nextConflict, nextUpdateSort, rowConflict, sortUpdateRows, updateActs, updateCloseMode, updateDone, updateLocked, updateParent, updateRange, updateReady, updateType } from './svnUpdateModel.js'
14
14
  import type { UpdateColumn, UpdateSort } from './svnUpdateModel.js'
15
+ import { entryIconEl } from './icons.js'
16
+ import { isDirOf } from './svnIcons.js'
17
+ import { useSvnEntryKinds } from './useSvnEntryKinds.js'
18
+ import type { SvnEntryKinds } from './useSvnEntryKinds.js'
19
+
20
+ /** 流式输出期间判型请求的合并窗口:更新还在写行时只保留最后一次请求。 */
21
+ const KIND_QUERY_DEBOUNCE_MS = 400
15
22
 
16
23
  interface UpdateProps {
17
24
  sessionId?: string
@@ -253,6 +260,26 @@ function menuEntries(props: UpdateProps, state: SvnUpdateState, menu: UpdateMenu
253
260
  ]
254
261
  }
255
262
 
263
+ /**
264
+ * 行图标用的目录判定输入:更新行是流式到达的,路径集合与可查白名单在这里派生一次。
265
+ * @author ddj 2026年11月23号
266
+ * @param rows 当前全部输出行
267
+ * @param sessionId 会话 id
268
+ * @returns 目录集合与类型表
269
+ */
270
+ function useRowKinds(rows: SvnUpdateRow[], sessionId?: string) {
271
+ const kindPaths = React.useMemo(
272
+ () => rows.filter((row) => row.action).map((row) => row.relPath || row.path),
273
+ [rows],
274
+ )
275
+ // 工作区外的行没有可 stat 的相对路径:只把工作区内 relPath 交给 host 查。
276
+ const kindOnly = React.useMemo(
277
+ () => new Set(rows.filter((row) => row.action && row.relPath).map((row) => row.relPath as string)),
278
+ [rows],
279
+ )
280
+ return useSvnEntryKinds(kindPaths, sessionId, { only: kindOnly, debounceMs: KIND_QUERY_DEBOUNCE_MS })
281
+ }
282
+
256
283
  /**
257
284
  * 将一条增量行映射为高密度的三列;单元格显示工作副本内相对路径,完整绝对路径留在 title 中。
258
285
  * @author ddj 2026年09月24号
@@ -261,11 +288,15 @@ function menuEntries(props: UpdateProps, state: SvnUpdateState, menu: UpdateMenu
261
288
  * @param picked 是否选中
262
289
  * @param onPick 选择回调
263
290
  * @param onMenu 右键回调
291
+ * @param resolved 冲突是否已解决
292
+ * @param dirs 已确定的目录集合
293
+ * @param kinds host 返回的类型表
264
294
  * @returns 行元素
265
295
  */
266
296
  function rowElement(row: SvnUpdateRow, cwd: string | null | undefined, picked: boolean,
267
297
  onPick: (event: React.MouseEvent<HTMLDivElement>) => void,
268
- onMenu: (event: React.MouseEvent<HTMLDivElement>) => void, resolved: boolean): React.ReactElement {
298
+ onMenu: (event: React.MouseEvent<HTMLDivElement>) => void, resolved: boolean,
299
+ dirs: ReadonlySet<string>, kinds: Readonly<Record<string, SvnPathKind | undefined>>): React.ReactElement {
269
300
  // 显示用相对路径(窄窗省略尾部时先保住文件名),悬浮与复制仍用完整绝对路径。
270
301
  const full = row.relPath ? absoluteOf(row.relPath, cwd) : (row.path || row.label)
271
302
  const path = row.relPath || row.path || row.label
@@ -276,6 +307,9 @@ function rowElement(row: SvnUpdateRow, cwd: string | null | undefined, picked: b
276
307
  onClick: onPick, onContextMenu: onMenu, title: row.raw,
277
308
  },
278
309
  React.createElement('span', { role: 'cell', className: 'edrv-update-action tone-' + tone }, resolved ? row.label + '(已解决)' : row.action ? row.label : '信息'),
310
+ // 信息行(Updating '.' / At revision N 等)不是文件行,图标列留空。
311
+ React.createElement('span', { role: 'cell', className: 'edrv-update-icon', 'aria-hidden': true },
312
+ row.action ? entryIconEl(path, isDirOf(path, dirs, kinds)) : null),
279
313
  React.createElement('span', { role: 'cell', className: 'edrv-update-path', title: full }, path),
280
314
  React.createElement('span', { role: 'cell', className: 'edrv-update-type' }, row.action ? updateType(row.path) : ''))
281
315
  }
@@ -417,17 +451,28 @@ function updateHead(props: UpdateProps, state: SvnUpdateState | null, phase: str
417
451
  */
418
452
  function updateTable(props: UpdateProps, rows: SvnUpdateRow[], view: ReturnType<typeof useUpdateView>,
419
453
  selection: ReturnType<typeof useUpdateMenu>, finished: boolean, sort: UpdateSort | null,
420
- onSort: (column: UpdateColumn) => void, states: ReadonlyMap<string, SvnConflictState>): React.ReactElement {
454
+ onSort: (column: UpdateColumn) => void, states: ReadonlyMap<string, SvnConflictState>,
455
+ entryKind: SvnEntryKinds): React.ReactElement {
421
456
  const visible = rows.slice(view.range.start, view.range.end)
457
+ /**
458
+ * 可排序的列表头(图标列不参与排序,单独占一格空表头)。
459
+ * @author ddj 2026年09月24号 / 2026年11月23号
460
+ * @param column 排序列
461
+ * @returns 表头单元格
462
+ */
463
+ const sortHead = (column: UpdateColumn) => {
464
+ const direction = sort?.column === column ? sort.direction : 0
465
+ const label = column === 'action' ? '操作' : column === 'path' ? '路径' : '类型(推断)'
466
+ return React.createElement('span', { key: column, role: 'columnheader', 'aria-sort': direction === 1 ? 'ascending' : direction === -1 ? 'descending' : 'none' },
467
+ React.createElement('button', { type: 'button', className: 'edrv-update-sort', onClick: () => onSort(column),
468
+ title: '点击切换升序、降序、原始顺序' + (column === 'type' ? ';仅推断类型,非 SVN 属性' : '') }, label + (direction === 1 ? ' ▲' : direction === -1 ? ' ▼' : ' ↕')))
469
+ }
422
470
  return React.createElement('div', { className: 'edrv-update-table', role: 'table', 'aria-label': 'SVN 更新文件明细', 'aria-rowcount': rows.length },
423
471
  React.createElement('div', { role: 'row', className: 'edrv-update-cols' },
424
- (['action', 'path', 'type'] as const).map((column) => {
425
- const direction = sort?.column === column ? sort.direction : 0
426
- const label = column === 'action' ? '操作' : column === 'path' ? '路径' : '类型(推断)'
427
- return React.createElement('span', { key: column, role: 'columnheader', 'aria-sort': direction === 1 ? 'ascending' : direction === -1 ? 'descending' : 'none' },
428
- React.createElement('button', { type: 'button', className: 'edrv-update-sort', onClick: () => onSort(column),
429
- title: '点击切换升序、降序、原始顺序' + (column === 'type' ? ';仅推断类型,非 SVN 属性' : '') }, label + (direction === 1 ? ' ▲' : direction === -1 ? ' ▼' : ' ↕')))
430
- })),
472
+ sortHead('action'),
473
+ React.createElement('span', { key: 'icon', role: 'columnheader', className: 'edrv-update-icon', 'aria-hidden': true }),
474
+ sortHead('path'),
475
+ sortHead('type')),
431
476
  React.createElement('div', { className: 'edrv-update-list', ref: view.listRef, role: 'rowgroup', onScroll: view.onScroll },
432
477
  React.createElement('div', { className: 'edrv-update-space', style: { height: rows.length * view.rowHeight } },
433
478
  visible.map((row, index) => React.createElement('div', {
@@ -436,7 +481,7 @@ function updateTable(props: UpdateProps, rows: SvnUpdateRow[], view: ReturnType<
436
481
  'aria-rowindex': view.range.start + index + 1,
437
482
  }, rowElement(row, props.cwd, selection.picked.has(row.seq),
438
483
  (event) => selection.pick(event, row), (event) => selection.openMenu(event, row),
439
- row.action === 'C' && !rowConflict(row, states))))),
484
+ row.action === 'C' && !rowConflict(row, states), entryKind.dirs, entryKind.kinds)))),
440
485
  !rows.length ? React.createElement('div', { className: 'edrv-update-empty' },
441
486
  finished ? '没有逐文件变更' : '等待 SVN 输出…') : null))
442
487
  }
@@ -514,6 +559,7 @@ export function SvnUpdateDialog(props: UpdateProps): React.ReactElement {
514
559
  const conflictPaths = React.useMemo(() => [...new Set(rows.filter((row) => row.action === 'C' && row.relPath).map((row) => row.relPath!))], [rows])
515
560
  const evidence = useConflictState(props, conflictPaths, finished)
516
561
  const write = useConflictWrite(props, finished, evidence)
562
+ const entryKind = useRowKinds(rows, props.sessionId)
517
563
  const remaining = new Set(rows.filter((row) => rowConflict(row, evidence.states)).map((row) => row.relPath || row.path)).size
518
564
  const outside = rows.some((row) => row.action === 'C' && !row.relPath)
519
565
  const closeMode = updateCloseMode(finished, error, Boolean(state), Boolean(selection.menu || props.childOverlay || write.busy))
@@ -569,7 +615,7 @@ export function SvnUpdateDialog(props: UpdateProps): React.ReactElement {
569
615
  closeOnEsc: closeMode.passive, onClose: dismiss,
570
616
  },
571
617
  updateHead(props, state, phase, closable, dismiss),
572
- updateTable(props, displayRows, view, selection, finished, sort, onSort, evidence.states),
618
+ updateTable(props, displayRows, view, selection, finished, sort, onSort, evidence.states, entryKind),
573
619
  updateStatus(state, error || evidence.error, cleaned),
574
620
  outside ? React.createElement('div', { className: 'edrv-update-warning' }, '存在工作区外冲突;可定位但不能在此执行解决操作') : null,
575
621
  write.busy ? React.createElement('div', { role: 'status' }, '正在处理冲突并核对 SVN 状态…') : null,
@@ -72,20 +72,68 @@ export const IconBranchOutline16 = iconOf('IconBranchOutline16', 'IconBranchOutl
72
72
  // 两代同名存活的原语:直通再导出(0.1.6/0.1.7 实证均在)
73
73
  export { FileTypeIcon, classifyFileType } from '@deepseek-ai/dsh-client-ui-primitives'
74
74
 
75
+ /** 文件图标元素缓存上限(文件类型数远小于此;超限整体重置,防异常分类值把表撑爆)。 */
76
+ const FILE_ICON_CACHE_MAX = 64
77
+ /** 类型 → 图标元素(同一类型复用同一元素实例,全量渲染的清单不会每帧重建 4000 个节点)。 */
78
+ const fileIconCache = new Map<string, React.ReactElement | null>()
79
+ /** 目录图标元素(闭合/展开各一份,理由同上)。 */
80
+ const dirIconCache = new Map<string, React.ReactElement>()
81
+
82
+ /**
83
+ * 目录图标元素(官方 IconFolderClose16/Open16,与文件树同一套原语)。
84
+ * @author ddj 2026年09月10号 / 2026年11月23号
85
+ * @param isOpen 目录是否展开(窗口行恒为闭合)
86
+ * @returns 图标元素;原语缺失返回 null
87
+ */
88
+ export function dirIconEl(isOpen = false): React.ReactElement | null {
89
+ const Icon = isOpen ? IconFolderOpen16 : IconFolderClose16
90
+ if (typeof Icon !== 'function') return null
91
+ const cached = dirIconCache.get(isOpen ? 'open' : 'close')
92
+ if (cached) return cached
93
+ // 与 fileIconEl 同法:图标是纯函数组件,直接调用并收窄返回类型(createElement 重载不认 unknown)。
94
+ const el = Icon({ size: 16, className: 'edrv-tree-icon' }) as React.ReactElement
95
+ dirIconCache.set(isOpen ? 'open' : 'close', el)
96
+ return el
97
+ }
98
+
75
99
  /**
76
100
  * 文件图标元素(官方 FileTypeIcon + classifyFileType 分类,未知类型为 other)。
77
- * 文件树与 SVN 变更行共用(原为 FileExplorer 私有副本,上移共享防两处漂移)。
78
- * @author ddj 2026年09月23号
101
+ * 文件树、SVN 变更行与提交/更新窗口共用;元素按分类缓存,重复渲染不重建。
102
+ * @author ddj 2026年09月23号 / 2026年11月23号
79
103
  * @param name 文件名(含扩展名;目录由调用方走目录图标)
80
104
  * @returns 图标元素;原语缺失或分类异常返回 null
81
105
  */
82
106
  export function fileIconEl(name: string): React.ReactElement | null {
83
107
  if (typeof FileTypeIcon !== 'function' || typeof classifyFileType !== 'function') return null
108
+ let kind: ReturnType<typeof classifyFileType>
109
+ try {
110
+ kind = classifyFileType(String(name ?? ''))
111
+ } catch (error) {
112
+ return null
113
+ }
114
+ const cacheKey = String(kind)
115
+ if (fileIconCache.has(cacheKey)) return fileIconCache.get(cacheKey) ?? null
116
+ let el: React.ReactElement | null = null
84
117
  try {
85
118
  // FileTypeIcon 签名为 (props) => ReactNode(非 ReactElement),createElement 重载不认——
86
119
  // 纯函数组件直接调用并收窄返回类型(与 FileExplorer 原 createElement 等效)。
87
- return FileTypeIcon({ kind: classifyFileType(String(name ?? '')), size: 16, className: 'edrv-tree-icon' }) as React.ReactElement
120
+ el = FileTypeIcon({ kind, size: 16, className: 'edrv-tree-icon' }) as React.ReactElement
88
121
  } catch (error) {
89
- return null
122
+ el = null
90
123
  }
124
+ if (fileIconCache.size >= FILE_ICON_CACHE_MAX) fileIconCache.clear()
125
+ fileIconCache.set(cacheKey, el)
126
+ return el
127
+ }
128
+
129
+ /**
130
+ * 条目图标分派:目录 → 文件夹图标,文件 → 官方类型图标。
131
+ * @author ddj 2026年11月23号
132
+ * @param path 条目路径(取末段做扩展名分类;目录不参与分类)
133
+ * @param isDir 是否目录(调用方用 SVN 判型结果决定)
134
+ * @returns 图标元素;原语缺失返回 null
135
+ */
136
+ export function entryIconEl(path: string, isDir: boolean): React.ReactElement | null {
137
+ if (isDir) return dirIconEl(false)
138
+ return fileIconEl(String(path ?? '').split(/[\\/]/).pop() || '')
91
139
  }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * dsh-vscode-mode client — SVN 提交/更新窗口行图标的目录判定(纯函数,可单测)。
3
+ *
4
+ * 为什么需要它:`svn status --xml` 的 `<wc-status>` 与 `svn update` 的文本行都不带 kind
5
+ * (实测 status XML 只有 item/props/revision 三个属性),客户端只能自己判。先白拿一层证据:
6
+ * 递归输出里某条目若是另一条目的上级目录,它必然是目录;剩下的(空目录、只改了属性的目录、
7
+ * 未版本控制的目录、已删除的目录)才去问 host 查盘,够不着的按文件图标回落。
8
+ * @author ddj 2026年11月23号
9
+ */
10
+ import type { SvnPathKind } from '../../shared/svn.js'
11
+ import { PATH_KINDS_CAP, svnChunksOf } from '../../shared/svn.js'
12
+
13
+ /** 单次窗口判型请求的总量上限(3 批):超出的路径按文件图标回落,不无限追加请求。 */
14
+ export const KIND_QUERY_MAX = PATH_KINDS_CAP * 3
15
+
16
+ /**
17
+ * 从清单本身推断目录:某路径是另一条目的上级目录时,它一定是目录。
18
+ *
19
+ * 复杂度与总层级深度成正比(不是两两比较),4000 条清单也只是一次线性扫。
20
+ * @author ddj 2026年11月23号
21
+ * @param paths 清单内全部路径(`/` 分隔,工作副本相对)
22
+ * @returns 可确定为目录的路径集合
23
+ */
24
+ export function dirsFromChildren(paths: readonly string[]): Set<string> {
25
+ const all = new Set(paths)
26
+ const dirs = new Set<string>()
27
+ for (const path of paths) {
28
+ let at = path.lastIndexOf('/')
29
+ while (at > 0) {
30
+ const parent = path.slice(0, at)
31
+ if (all.has(parent)) dirs.add(parent)
32
+ at = parent.lastIndexOf('/')
33
+ }
34
+ }
35
+ return dirs
36
+ }
37
+
38
+ /**
39
+ * 判定不出、需要问 host 的路径(去重、去空、保持原顺序)。
40
+ * @author ddj 2026年11月23号
41
+ * @param paths 清单内全部路径
42
+ * @param dirs 已由子项关系确定的目录集合
43
+ * @returns 待查路径列表
44
+ */
45
+ export function kindCandidatesOf(paths: readonly string[], dirs: ReadonlySet<string>): string[] {
46
+ const seen = new Set<string>()
47
+ const out: string[] = []
48
+ for (const path of paths) {
49
+ if (!path || dirs.has(path) || seen.has(path)) continue
50
+ seen.add(path)
51
+ out.push(path)
52
+ }
53
+ return out
54
+ }
55
+
56
+ /**
57
+ * 待查路径按 host 单次上限分块(含总量上限,超出部分不问)。
58
+ * @author ddj 2026年11月23号
59
+ * @param candidates 待查路径(见 kindCandidatesOf)
60
+ * @param max 总量上限
61
+ * @returns 分块列表;空数组 = 不需要请求
62
+ */
63
+ export function kindQueryChunksOf(candidates: readonly string[], max = KIND_QUERY_MAX): string[][] {
64
+ if (!candidates.length) return []
65
+ const capped = candidates.length > max ? candidates.slice(0, Math.max(0, max)) : candidates
66
+ return svnChunksOf(capped, PATH_KINDS_CAP)
67
+ }
68
+
69
+ /**
70
+ * 多块响应合并成一张表(后到的覆盖先到的:同一路径取值一致,覆盖无害)。
71
+ * @author ddj 2026年11月23号
72
+ * @param tables 各块返回的路径 → 类型表
73
+ * @returns 合并后的表
74
+ */
75
+ export function mergeKindsOf(...tables: ReadonlyArray<Readonly<Record<string, SvnPathKind>>>): Record<string, SvnPathKind> {
76
+ const merged: Record<string, SvnPathKind> = {}
77
+ for (const table of tables) {
78
+ for (const [path, kind] of Object.entries(table)) merged[path] = kind
79
+ }
80
+ return merged
81
+ }
82
+
83
+ /**
84
+ * 最终判定:子项关系说它是目录,或 host 说它是目录,都算目录。
85
+ *
86
+ * `missing`(磁盘上没有)不算目录:已删除的条目画文件图标,不误导成「这个目录还在」。
87
+ * @author ddj 2026年11月23号
88
+ * @param path 条目路径
89
+ * @param dirs 子项关系确定的目录集合
90
+ * @param kinds host 返回的类型表
91
+ * @returns 是否按目录图标显示
92
+ */
93
+ export function isDirOf(
94
+ path: string,
95
+ dirs: ReadonlySet<string>,
96
+ kinds: Readonly<Record<string, SvnPathKind | undefined>>,
97
+ ): boolean {
98
+ return dirs.has(path) || kinds[path] === 'dir'
99
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * dsh-vscode-mode client — SVN 行图标的目录判定钩子(提交窗口 / 更新窗口 / 侧栏面板共用)。
3
+ *
4
+ * 判定顺序:先用子项关系白拿(某条目是另一条目的上级目录 → 必是目录),
5
+ * 剩下的路径按 host 单次上限分块查盘;请求失败或尚未返回时表为空,行按文件图标回落。
6
+ * 三处窗口共用同一个钩子,避免判定口径与请求节奏各写一份后漂移。
7
+ * @author ddj 2026年11月23号
8
+ */
9
+ import React from 'react'
10
+ import type { SvnPathKind } from '../../shared/svn.js'
11
+ import { svnPathKinds } from '../svnStatus.js'
12
+ import { dirsFromChildren, kindCandidatesOf, kindQueryChunksOf, mergeKindsOf } from './svnIcons.js'
13
+
14
+ /** 一轮判定结果:已确定的目录集合 + host 类型表。 */
15
+ export interface SvnEntryKinds {
16
+ /** 子项关系确定的目录集合。 */
17
+ dirs: ReadonlySet<string>
18
+ /** host 返回的类型表(未出现的路径按文件处理)。 */
19
+ kinds: Readonly<Record<string, SvnPathKind>>
20
+ }
21
+
22
+ /** 调用方约束。 */
23
+ export interface SvnEntryKindsOptions {
24
+ /** 只允许查这些路径(更新窗口只查工作区内的 relPath,工作区外的行不 stat)。 */
25
+ only?: ReadonlySet<string> | null
26
+ /** 请求合并窗(毫秒):流式出行期间只保留最后一次;默认 0 = 立即请求。 */
27
+ debounceMs?: number
28
+ }
29
+
30
+ /**
31
+ * 计算行图标用的目录判定结果。
32
+ *
33
+ * `paths` 需要调用方自己 memo(面板与窗口都已有派生集合),否则每帧重算子项关系。
34
+ * @author ddj 2026年11月23号
35
+ * @param paths 本轮要显示的条目路径(`/` 分隔)
36
+ * @param sessionId 会话 id
37
+ * @param options 可查路径白名单与合并窗
38
+ * @returns 目录集合与类型表
39
+ */
40
+ export function useSvnEntryKinds(
41
+ paths: readonly string[],
42
+ sessionId?: string,
43
+ options: SvnEntryKindsOptions = {},
44
+ ): SvnEntryKinds {
45
+ const [kinds, setKinds] = React.useState<Record<string, SvnPathKind>>({})
46
+ const dirs = React.useMemo(() => dirsFromChildren(paths), [paths])
47
+
48
+ const only = options.only ?? null
49
+ const candidates = React.useMemo(() => {
50
+ const list = kindCandidatesOf(paths, dirs)
51
+ return only ? list.filter((path) => only.has(path)) : list
52
+ }, [paths, dirs, only])
53
+ const signature = candidates.join('\n')
54
+ const delay = options.debounceMs ?? 0
55
+
56
+ React.useEffect(() => {
57
+ const chunks = kindQueryChunksOf(candidates)
58
+ if (!chunks.length) { setKinds({}); return () => {} }
59
+
60
+ let alive = true
61
+ /**
62
+ * 逐块并发请求后合并(node 端每块内部再并发 16 条)。
63
+ * @author ddj 2026年11月23号
64
+ */
65
+ const run = () => {
66
+ void Promise.all(chunks.map((chunk) => svnPathKinds(sessionId, chunk))).then((tables) => {
67
+ if (alive) setKinds(mergeKindsOf(...tables))
68
+ })
69
+ }
70
+ if (!delay) { run(); return () => { alive = false } }
71
+
72
+ const timer = setTimeout(run, delay)
73
+ return () => { alive = false; clearTimeout(timer) }
74
+ }, [signature, sessionId, delay])
75
+
76
+ return { dirs, kinds }
77
+ }