dsh-gufa-code 1.3.215 → 1.3.234
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 +76 -21
- package/client.js +549 -37
- package/docs/screenshot-git.jpg +0 -0
- package/docs/screenshot-main.jpg +0 -0
- package/docs/screenshot-moyu.jpg +0 -0
- package/host/code.js +86 -5
- package/host/fs.js +98 -3
- package/host/open-with.js +322 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/screenshots.json +3 -1
- package/scripts/selftest-host.mjs +47 -0
- package/src/client/00-core.js +17 -0
- package/src/client/20-editor.js +68 -15
- package/src/client/50-panels.js +116 -5
- package/src/client/58b-drag-ref.js +3 -0
- package/src/client/90-app.js +167 -16
- package/src/client/99-main.js +177 -0
package/client.js
CHANGED
|
@@ -16,10 +16,20 @@ const GUFA_NS = 'gufa-code'
|
|
|
16
16
|
const G = {}
|
|
17
17
|
G.NS = GUFA_NS
|
|
18
18
|
/** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
|
|
19
|
-
G.BUILD = '1.3.
|
|
19
|
+
G.BUILD = '1.3.234'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
23
|
+
/** 经典模式悬浮入口:优先打开当前聊天所在工作区(而不是上次保存的项目)。 */
|
|
24
|
+
G.pendingSessionEntry = false
|
|
25
|
+
/** 由 App 暴露给文件打开器使用的编辑器入口(打开指定绝对路径文件)。 */
|
|
26
|
+
G.ideOpenPaths = null
|
|
27
|
+
/** 系统「打开方式」请求的目标条目:App boot 时优先打开该工作区,避免先恢复旧项目再被覆盖。 */
|
|
28
|
+
G.pendingOpenEntries = null
|
|
29
|
+
/** 正在处理系统「打开方式」请求:期间入口工作区同步不得把项目改回当前会话 cwd。 */
|
|
30
|
+
G.openWithActive = false
|
|
31
|
+
/** App 初始 boot(恢复项目/会话)是否完成;open-with 必须等它结束再切目标工作区。 */
|
|
32
|
+
G.ideBootDone = false
|
|
23
33
|
G.ctx = null
|
|
24
34
|
G.h = h
|
|
25
35
|
G.React = React
|
|
@@ -1794,6 +1804,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1794
1804
|
color:var(--gufa-text);cursor:pointer;text-align:left;font-size:12.5px;white-space:nowrap;min-width:0;width:100%}
|
|
1795
1805
|
.gufa-tree-row:hover{background:var(--gufa-hover)}
|
|
1796
1806
|
.gufa-tree-row[data-selected]{background:var(--gufa-active)}
|
|
1807
|
+
.gufa-tree-row[data-drop]{background:color-mix(in srgb, var(--gufa-accent) 18%, transparent);outline:1px dashed var(--gufa-accent);outline-offset:-1px;border-radius:6px}
|
|
1808
|
+
.gufa-panel-body[data-drop-root]{box-shadow:inset 0 0 0 2px color-mix(in srgb, var(--gufa-accent) 55%, transparent)}
|
|
1797
1809
|
.gufa-tree-row[data-kind="dir"]{color:var(--gufa-text)}
|
|
1798
1810
|
.gufa-tree-name{overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;min-width:0}
|
|
1799
1811
|
.gufa-explorer-notice{margin:4px 10px 0;padding:3px 8px;border-radius:6px;font-size:11px;line-height:1.5;color:var(--gufa-text);
|
|
@@ -2018,6 +2030,11 @@ html[data-gufa-ide] .liang-skin-backdrop{display:none!important}
|
|
|
2018
2030
|
background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;cursor:pointer;text-align:left}
|
|
2019
2031
|
.gufa-more-entry:hover{background:var(--dsw-alias-interactive-bg-hover, var(--gufa-hover))}
|
|
2020
2032
|
.gufa-more-entry-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2033
|
+
/* 经典模式聊天右上角工具区的「古法编程」入口:只加一个显眼边框,其余保持原生 link 样式 */
|
|
2034
|
+
.gufa-header-entry{min-height:28px;flex:none;display:inline-flex;align-items:center;padding:3px 9px;border:1.5px solid var(--gufa-accent, #b13a2b);border-radius:7px;background:transparent;color:var(--dsw-alias-label-secondary, var(--gufa-text-dim));font:500 12px/1 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;cursor:pointer;white-space:nowrap;transition:background .15s ease,color .15s ease}
|
|
2035
|
+
.gufa-header-entry:hover{color:var(--dsw-alias-label-primary, var(--gufa-text));background:var(--dsw-alias-interactive-bg-hover, var(--gufa-hover))}
|
|
2036
|
+
.gufa-header-entry:focus-visible{outline:2px solid var(--dsw-focus-ring-color, var(--gufa-accent));outline-offset:2px}
|
|
2037
|
+
.gufa-header-entry-label{white-space:nowrap}
|
|
2021
2038
|
.gufa-menu{position:absolute;z-index:2147483000;min-width:150px;padding:5px;border-radius:9px;border:1px solid var(--gufa-border-strong);
|
|
2022
2039
|
background:var(--gufa-solid-overlay-bg);box-shadow:0 12px 30px color-mix(in srgb, #000 28%, transparent)}
|
|
2023
2040
|
.gufa-menu-item{display:flex;align-items:center;gap:8px;width:100%;height:28px;padding:0 9px;border:0;border-radius:6px;
|
|
@@ -3130,7 +3147,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3130
3147
|
*/
|
|
3131
3148
|
/* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
|
|
3132
3149
|
Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
|
|
3133
|
-
const GUFA_DEFINITION_LANGUAGES = ['python']
|
|
3150
|
+
const GUFA_DEFINITION_LANGUAGES = ['python', 'php']
|
|
3134
3151
|
function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
3135
3152
|
try {
|
|
3136
3153
|
if (monaco === null || monaco === undefined) return
|
|
@@ -3190,7 +3207,7 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
|
3190
3207
|
language: 'python',
|
|
3191
3208
|
content: model.getValue(),
|
|
3192
3209
|
})
|
|
3193
|
-
} else {
|
|
3210
|
+
} else if (language === 'javascript' || language === 'typescript') {
|
|
3194
3211
|
/* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
|
|
3195
3212
|
JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
|
|
3196
3213
|
result = await G.api('code.tsDefinition', {
|
|
@@ -3200,6 +3217,16 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
|
3200
3217
|
column: position.column,
|
|
3201
3218
|
content: model.getValue(),
|
|
3202
3219
|
})
|
|
3220
|
+
} else {
|
|
3221
|
+
/* PHP 等无内置语言服务的语言:项目级定义搜索(Host code.definition) */
|
|
3222
|
+
result = await G.api('code.definition', {
|
|
3223
|
+
root: info.root,
|
|
3224
|
+
path: info.path,
|
|
3225
|
+
line: position.lineNumber,
|
|
3226
|
+
column: position.column,
|
|
3227
|
+
word,
|
|
3228
|
+
content: model.getValue(),
|
|
3229
|
+
})
|
|
3203
3230
|
}
|
|
3204
3231
|
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3205
3232
|
return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
|
|
@@ -3487,6 +3514,23 @@ const GUFA_LINT_ENABLED = true
|
|
|
3487
3514
|
const activePathRef = useRef(activePath)
|
|
3488
3515
|
const statusRef = useRef('loading')
|
|
3489
3516
|
const pendingRevealRef = useRef(null)
|
|
3517
|
+
/* 打开未加载的文件时,editor 可能还没挂载/模型还没切换;先记住目标位置,
|
|
3518
|
+
等编辑器就绪或切到目标文件后再落光标,避免只跳文件、位置不准。 */
|
|
3519
|
+
const applyPendingReveal = useCallback((editor) => {
|
|
3520
|
+
const pending = pendingRevealRef.current
|
|
3521
|
+
if (pending === null || pending === undefined) return false
|
|
3522
|
+
if (editor === null || editor === undefined) return false
|
|
3523
|
+
if (modelPathRef.current !== pending.path) return false
|
|
3524
|
+
pendingRevealRef.current = null
|
|
3525
|
+
try {
|
|
3526
|
+
editor.setPosition({ lineNumber: pending.line, column: pending.column })
|
|
3527
|
+
editor.revealLineInCenter(pending.line)
|
|
3528
|
+
editor.focus()
|
|
3529
|
+
} catch {
|
|
3530
|
+
/* ignore */
|
|
3531
|
+
}
|
|
3532
|
+
return true
|
|
3533
|
+
}, [])
|
|
3490
3534
|
|
|
3491
3535
|
/** idle → loading → ready / error */
|
|
3492
3536
|
const [status, setStatus] = useState('loading')
|
|
@@ -4049,6 +4093,33 @@ const GUFA_LINT_ENABLED = true
|
|
|
4049
4093
|
clearHoverDecoration()
|
|
4050
4094
|
return
|
|
4051
4095
|
}
|
|
4096
|
+
/* 其它语言(PHP / Go / Java …):走项目级定义搜索。
|
|
4097
|
+
queryDefinitions + decideDefinition 已实现,此前没接到点击入口。 */
|
|
4098
|
+
try {
|
|
4099
|
+
const resolved = await queryDefinitions(position, word, model, path, root)
|
|
4100
|
+
const decision = decideDefinition(resolved)
|
|
4101
|
+
if (decision.kind === 'open') {
|
|
4102
|
+
G.bus.emit('editor:open-at', {
|
|
4103
|
+
path: decision.match.path,
|
|
4104
|
+
line: decision.match.line,
|
|
4105
|
+
column: decision.match.column,
|
|
4106
|
+
})
|
|
4107
|
+
clearHoverDecoration()
|
|
4108
|
+
return
|
|
4109
|
+
}
|
|
4110
|
+
if (decision.kind === 'pick') {
|
|
4111
|
+
G.bus.emit('definition:pick', {
|
|
4112
|
+
word,
|
|
4113
|
+
matches: decision.matches,
|
|
4114
|
+
x: Number.isFinite(Number(event.clientX)) ? Number(event.clientX) : 240,
|
|
4115
|
+
y: Number.isFinite(Number(event.clientY)) ? Number(event.clientY) : 240,
|
|
4116
|
+
})
|
|
4117
|
+
clearHoverDecoration()
|
|
4118
|
+
return
|
|
4119
|
+
}
|
|
4120
|
+
} catch {
|
|
4121
|
+
/* 解析失败继续走原生兜底,不跳错 */
|
|
4122
|
+
}
|
|
4052
4123
|
/* 其它语言:保留 Monaco 原生 action 兜底 */
|
|
4053
4124
|
try {
|
|
4054
4125
|
instance.focus()
|
|
@@ -4490,17 +4561,7 @@ const GUFA_LINT_ENABLED = true
|
|
|
4490
4561
|
}
|
|
4491
4562
|
}
|
|
4492
4563
|
reportCursor()
|
|
4493
|
-
|
|
4494
|
-
if (pending !== null && pending !== undefined && pending.path === targetTab.path) {
|
|
4495
|
-
pendingRevealRef.current = null
|
|
4496
|
-
try {
|
|
4497
|
-
editor.setPosition({ lineNumber: pending.line, column: pending.column })
|
|
4498
|
-
editor.revealLineInCenter(pending.line)
|
|
4499
|
-
editor.focus()
|
|
4500
|
-
} catch {
|
|
4501
|
-
/* ignore */
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4564
|
+
applyPendingReveal(editor)
|
|
4504
4565
|
/* 打开 Python 文件时预热 pyright,避免第一次 Cmd+点击等语言服务启动 */
|
|
4505
4566
|
if (targetTab.language === 'python' && !GUFA_LSP_WARMED.has(root)) {
|
|
4506
4567
|
GUFA_LSP_WARMED.add(root)
|
|
@@ -4523,19 +4584,28 @@ const GUFA_LINT_ENABLED = true
|
|
|
4523
4584
|
} else if (targetTab !== null) {
|
|
4524
4585
|
modelPathRef.current = targetTab.path
|
|
4525
4586
|
}
|
|
4526
|
-
}, [status, tabs, activePath, root, reportCursor, disposeAllModels, disposeModelAt])
|
|
4587
|
+
}, [status, tabs, activePath, root, reportCursor, applyPendingReveal, disposeAllModels, disposeModelAt])
|
|
4588
|
+
|
|
4589
|
+
/* 编辑器挂载完成/模型已就绪时,把还没落地的定义跳转位置补上 */
|
|
4590
|
+
useEffect(() => {
|
|
4591
|
+
applyPendingReveal(editorRef.current)
|
|
4592
|
+
}, [status, tabs, activePath, applyPendingReveal])
|
|
4527
4593
|
|
|
4528
4594
|
/* 搜索面板点击结果 → 打开文件并跳到对应行列(由 App 通过 bus 发来) */
|
|
4529
4595
|
useEffect(() => {
|
|
4530
4596
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
4531
4597
|
return G.bus.on('editor:reveal', (detail) => {
|
|
4532
4598
|
const editor = editorRef.current
|
|
4533
|
-
if (editor === null || editor === undefined) return
|
|
4534
4599
|
const rawLine = Number(detail?.line)
|
|
4535
4600
|
const rawColumn = Number(detail?.column)
|
|
4536
4601
|
const line = Number.isFinite(rawLine) ? Math.max(1, Math.trunc(rawLine)) : 1
|
|
4537
4602
|
const column = Number.isFinite(rawColumn) ? Math.max(1, Math.trunc(rawColumn)) : 1
|
|
4538
4603
|
const path = typeof detail?.path === 'string' && detail.path !== '' ? detail.path : null
|
|
4604
|
+
if (editor === null || editor === undefined) {
|
|
4605
|
+
/* 编辑器还没挂载(首次打开文件):先记下位置,挂载/切模型后的 effect 会补上 */
|
|
4606
|
+
if (path !== null) pendingRevealRef.current = { path, line, column }
|
|
4607
|
+
return
|
|
4608
|
+
}
|
|
4539
4609
|
if (path !== null && modelPathRef.current !== path) {
|
|
4540
4610
|
pendingRevealRef.current = { path, line, column }
|
|
4541
4611
|
return
|
|
@@ -8046,6 +8116,8 @@ G.GitGraphView = function GitGraphView(props) {
|
|
|
8046
8116
|
* 纯展示 + 直接调用 Host API,状态自持;容器在 90-app.js。
|
|
8047
8117
|
*/
|
|
8048
8118
|
|
|
8119
|
+
const GUFA_EXPLORER_MOVE_TYPE = 'application/x-gufa-explorer-move'
|
|
8120
|
+
|
|
8049
8121
|
/* ── 资源管理器 ────────────────────────────────────────────────────────── */
|
|
8050
8122
|
G.Explorer = function Explorer(props) {
|
|
8051
8123
|
const t = G.useT()
|
|
@@ -8055,6 +8127,8 @@ G.Explorer = function Explorer(props) {
|
|
|
8055
8127
|
const [selected, setSelected] = useState(() => (props.activePath ? { path: props.activePath, kind: 'file' } : null))
|
|
8056
8128
|
const [multi, setMulti] = useState([])
|
|
8057
8129
|
const [clipboard, setClipboard] = useState(null)
|
|
8130
|
+
const [dragTarget, setDragTarget] = useState(null)
|
|
8131
|
+
const internalDragRef = useRef(null)
|
|
8058
8132
|
const [menu, setMenu] = useState(null)
|
|
8059
8133
|
const [menuError, setMenuError] = useState('')
|
|
8060
8134
|
const [notice, setNotice] = useState('')
|
|
@@ -8178,8 +8252,12 @@ G.Explorer = function Explorer(props) {
|
|
|
8178
8252
|
|
|
8179
8253
|
const copySelection = (paths) => {
|
|
8180
8254
|
if (!Array.isArray(paths) || paths.length === 0) return
|
|
8181
|
-
|
|
8255
|
+
const entries = paths.filter((path) => typeof path === 'string' && path !== '')
|
|
8256
|
+
if (entries.length === 0) return
|
|
8257
|
+
setClipboard({ entries })
|
|
8182
8258
|
setMenuError('')
|
|
8259
|
+
/* 同时写入系统剪贴板(file URL / alias 列表):另一个古法编程实例或 Finder 可以直接粘贴 */
|
|
8260
|
+
void G.api('fs.copyToSystemClipboard', { root, from: entries }).catch(() => {})
|
|
8183
8261
|
}
|
|
8184
8262
|
|
|
8185
8263
|
/* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
|
|
@@ -8223,6 +8301,59 @@ G.Explorer = function Explorer(props) {
|
|
|
8223
8301
|
return () => window.removeEventListener('blur', clear)
|
|
8224
8302
|
}, [])
|
|
8225
8303
|
|
|
8304
|
+
const selectRoot = () => {
|
|
8305
|
+
containerRef.current?.focus?.()
|
|
8306
|
+
setMulti([])
|
|
8307
|
+
setSelected({ path: '', kind: 'dir' })
|
|
8308
|
+
}
|
|
8309
|
+
|
|
8310
|
+
/** 内部拖拽目标目录:拖到文件行 = 其父目录;拖到文件夹/空白 = 文件夹/根目录。 */
|
|
8311
|
+
const internalDropTargetDir = (target) => {
|
|
8312
|
+
const row = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
8313
|
+
if (row === null) return ''
|
|
8314
|
+
const path = row.getAttribute('data-edrv-path') ?? ''
|
|
8315
|
+
const kind = row.getAttribute('data-kind')
|
|
8316
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
8317
|
+
}
|
|
8318
|
+
|
|
8319
|
+
/** 把资源管理器里拖拽的条目移动到目标目录(根目录传 '')。 */
|
|
8320
|
+
const moveEntries = async (paths, targetDir) => {
|
|
8321
|
+
const list = (Array.isArray(paths) ? paths : []).filter((path) => typeof path === 'string' && path !== '')
|
|
8322
|
+
const movable = list.filter((path) => {
|
|
8323
|
+
if (path === targetDir) return false
|
|
8324
|
+
if (targetDir !== '' && targetDir.startsWith(`${path}/`)) return false
|
|
8325
|
+
return true
|
|
8326
|
+
})
|
|
8327
|
+
if (movable.length === 0) return
|
|
8328
|
+
showNotice(`正在移动 ${movable.length} 项…`)
|
|
8329
|
+
const failed = []
|
|
8330
|
+
let moved = 0
|
|
8331
|
+
let last = null
|
|
8332
|
+
for (const path of movable) {
|
|
8333
|
+
const base = path.split('/').filter(Boolean).pop() ?? path
|
|
8334
|
+
const nextPath = targetDir === '' ? base : `${targetDir}/${base}`
|
|
8335
|
+
if (nextPath === path) continue
|
|
8336
|
+
try {
|
|
8337
|
+
await G.api('fs.rename', { root, path, nextPath })
|
|
8338
|
+
moved += 1
|
|
8339
|
+
last = { path: nextPath, kind: kindByPathRef.current.get(path) ?? 'file' }
|
|
8340
|
+
} catch (error) {
|
|
8341
|
+
failed.push(`${path}:${G.errorText(error)}`)
|
|
8342
|
+
}
|
|
8343
|
+
}
|
|
8344
|
+
const dirsToRefresh = new Set(['', targetDir])
|
|
8345
|
+
for (const path of movable) dirsToRefresh.add(projectDirOf(path))
|
|
8346
|
+
for (const dir of dirsToRefresh) void loadDir(dir)
|
|
8347
|
+
props.onChanged?.()
|
|
8348
|
+
if (last !== null) {
|
|
8349
|
+
setMulti([])
|
|
8350
|
+
setSelected(last)
|
|
8351
|
+
if (last.kind === 'dir') setExpanded((current) => ({ ...current, [last.path]: true }))
|
|
8352
|
+
}
|
|
8353
|
+
if (moved > 0) showNotice(`已移动 ${moved} 项${failed.length > 0 ? `,${failed.length} 项失败` : ''}`)
|
|
8354
|
+
else if (failed.length > 0) showNotice(`移动失败:${failed[0]}`)
|
|
8355
|
+
}
|
|
8356
|
+
|
|
8226
8357
|
const noticeRef = useRef(0)
|
|
8227
8358
|
const showNotice = (text) => {
|
|
8228
8359
|
setNotice(text)
|
|
@@ -8375,6 +8506,8 @@ G.Explorer = function Explorer(props) {
|
|
|
8375
8506
|
'data-git-status': status !== undefined ? status : undefined,
|
|
8376
8507
|
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
8377
8508
|
'data-edrv-path': entry.path,
|
|
8509
|
+
'data-drop': isDir && dragTarget === entry.path ? '' : undefined,
|
|
8510
|
+
draggable: true,
|
|
8378
8511
|
style: { paddingLeft: 8 + depth * 14 },
|
|
8379
8512
|
title: entry.path,
|
|
8380
8513
|
onClick: (event) => {
|
|
@@ -8398,6 +8531,22 @@ G.Explorer = function Explorer(props) {
|
|
|
8398
8531
|
onDoubleClick: () => {
|
|
8399
8532
|
if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
|
|
8400
8533
|
},
|
|
8534
|
+
onDragStart: (event) => {
|
|
8535
|
+
const dragPaths = multi.length > 0 && multi.includes(entry.path) ? multi.slice() : [entry.path]
|
|
8536
|
+
internalDragRef.current = dragPaths
|
|
8537
|
+
try {
|
|
8538
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) {
|
|
8539
|
+
event.dataTransfer.effectAllowed = 'copyMove'
|
|
8540
|
+
event.dataTransfer.setData(GUFA_EXPLORER_MOVE_TYPE, JSON.stringify({ paths: dragPaths }))
|
|
8541
|
+
}
|
|
8542
|
+
} catch {
|
|
8543
|
+
/* ignore */
|
|
8544
|
+
}
|
|
8545
|
+
},
|
|
8546
|
+
onDragEnd: () => {
|
|
8547
|
+
internalDragRef.current = null
|
|
8548
|
+
setDragTarget(null)
|
|
8549
|
+
},
|
|
8401
8550
|
onContextMenu: (event) => openContextMenu(event, entry),
|
|
8402
8551
|
},
|
|
8403
8552
|
h(
|
|
@@ -8449,28 +8598,59 @@ G.Explorer = function Explorer(props) {
|
|
|
8449
8598
|
},
|
|
8450
8599
|
onDragOver: (event) => {
|
|
8451
8600
|
const types = event.dataTransfer?.types
|
|
8452
|
-
if (types === undefined || types === null
|
|
8601
|
+
if (types === undefined || types === null) return
|
|
8602
|
+
const list = Array.from(types)
|
|
8603
|
+
if (list.includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
8604
|
+
event.preventDefault()
|
|
8605
|
+
event.stopPropagation()
|
|
8606
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) event.dataTransfer.dropEffect = 'move'
|
|
8607
|
+
setDragTarget(internalDropTargetDir(event.target))
|
|
8608
|
+
return
|
|
8609
|
+
}
|
|
8610
|
+
if (!list.includes('Files')) return
|
|
8453
8611
|
event.preventDefault()
|
|
8454
8612
|
event.stopPropagation()
|
|
8455
8613
|
event.dataTransfer.dropEffect = 'copy'
|
|
8456
8614
|
},
|
|
8615
|
+
onDragLeave: (event) => {
|
|
8616
|
+
if (event.currentTarget instanceof Node && event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return
|
|
8617
|
+
setDragTarget(null)
|
|
8618
|
+
},
|
|
8457
8619
|
onDrop: (event) => {
|
|
8620
|
+
const types = event.dataTransfer?.types
|
|
8621
|
+
if (types !== undefined && types !== null && Array.from(types).includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
8622
|
+
event.preventDefault()
|
|
8623
|
+
event.stopPropagation()
|
|
8624
|
+
const paths = internalDragRef.current
|
|
8625
|
+
internalDragRef.current = null
|
|
8626
|
+
const targetDir = internalDropTargetDir(event.target)
|
|
8627
|
+
setDragTarget(null)
|
|
8628
|
+
void moveEntries(paths, targetDir)
|
|
8629
|
+
return
|
|
8630
|
+
}
|
|
8458
8631
|
const files = event.dataTransfer?.files
|
|
8459
8632
|
if (files === undefined || files === null || files.length === 0) return
|
|
8460
8633
|
event.preventDefault()
|
|
8461
8634
|
event.stopPropagation()
|
|
8462
8635
|
void uploadFiles(files, dropTargetDir(event.target))
|
|
8463
8636
|
},
|
|
8637
|
+
onClick: (event) => {
|
|
8638
|
+
/* 点击资源管理器空白处:选中根目录,而不是保留上一次选中的文件/文件夹 */
|
|
8639
|
+
if (!(event.target instanceof Element)) return
|
|
8640
|
+
if (event.target.closest('[data-edrv-path]') !== null) return
|
|
8641
|
+
if (event.target.closest('.gufa-panel-head, button, input, textarea, [role="menu"]') !== null) return
|
|
8642
|
+
selectRoot()
|
|
8643
|
+
},
|
|
8464
8644
|
onKeyDown: (event) => {
|
|
8465
8645
|
if (event.key === 'Enter') {
|
|
8466
|
-
if (selected === null) return
|
|
8646
|
+
if (selected === null || selected.path === '') return
|
|
8467
8647
|
event.preventDefault()
|
|
8468
8648
|
props.onRename?.(selected.path)
|
|
8469
8649
|
return
|
|
8470
8650
|
}
|
|
8471
8651
|
const mod = event.metaKey || event.ctrlKey
|
|
8472
8652
|
if (!mod || event.altKey) {
|
|
8473
|
-
if (event.key === 'Delete' && selected !== null) {
|
|
8653
|
+
if (event.key === 'Delete' && selected !== null && selected.path !== '') {
|
|
8474
8654
|
event.preventDefault()
|
|
8475
8655
|
props.onDelete?.(selected.path)
|
|
8476
8656
|
}
|
|
@@ -8485,7 +8665,7 @@ G.Explorer = function Explorer(props) {
|
|
|
8485
8665
|
void pasteInto(selectedDir())
|
|
8486
8666
|
} else if (key === 'backspace' || event.key === 'Delete') {
|
|
8487
8667
|
event.preventDefault()
|
|
8488
|
-
if (selected !== null) props.onDelete?.(selected.path)
|
|
8668
|
+
if (selected !== null && selected.path !== '') props.onDelete?.(selected.path)
|
|
8489
8669
|
}
|
|
8490
8670
|
},
|
|
8491
8671
|
},
|
|
@@ -8505,6 +8685,7 @@ G.Explorer = function Explorer(props) {
|
|
|
8505
8685
|
'div',
|
|
8506
8686
|
{
|
|
8507
8687
|
className: 'gufa-panel-body gufa-scroll',
|
|
8688
|
+
'data-drop-root': dragTarget === '' ? '' : undefined,
|
|
8508
8689
|
onContextMenu: (event) => {
|
|
8509
8690
|
try {
|
|
8510
8691
|
if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
|
|
@@ -10868,6 +11049,9 @@ function install(ctx) {
|
|
|
10868
11049
|
};
|
|
10869
11050
|
const onDrop = (event) => {
|
|
10870
11051
|
if (!isOurs(event.dataTransfer)) return;
|
|
11052
|
+
/* 资源管理器内部拖拽移动文件:交给 Explorer 自己的 drop 处理,不当作 @ 引用插入 */
|
|
11053
|
+
if (event.dataTransfer !== null && Array.prototype.indexOf.call(event.dataTransfer.types, "application/x-gufa-explorer-move") !== -1
|
|
11054
|
+
&& event.target instanceof Element && event.target.closest(".gufa-sidepanel") !== null) return;
|
|
10871
11055
|
if (dropZoneOf(event.target) === null) {
|
|
10872
11056
|
toast("松手位置不在输入框内,未插入", "err");
|
|
10873
11057
|
return;
|
|
@@ -13406,6 +13590,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13406
13590
|
const [banner, setBanner] = useState('')
|
|
13407
13591
|
const [tabs, setTabs] = useState([])
|
|
13408
13592
|
const [activePath, setActivePath] = useState(null)
|
|
13593
|
+
const activePathRef = useRef(activePath)
|
|
13594
|
+
activePathRef.current = activePath
|
|
13595
|
+
const pendingOpenAtRef = useRef(null)
|
|
13409
13596
|
/* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
|
|
13410
13597
|
const [selection, setSelection] = useState(null)
|
|
13411
13598
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
@@ -13433,6 +13620,20 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13433
13620
|
const [workspaceSessions, setWorkspaceSessions] = useState({ status: 'idle', sessions: [], groups: [], sessionIds: [], archivedSessionIds: [] })
|
|
13434
13621
|
const [workspaceIndex, setWorkspaceIndex] = useState([])
|
|
13435
13622
|
const [recentCurrentIds, setRecentCurrentIds] = useState([])
|
|
13623
|
+
const [bootStage, setBootStage] = useState('idle')
|
|
13624
|
+
useLayoutEffect(() => {
|
|
13625
|
+
/* App 挂载是新实例:先清掉上一实例的 boot 完成标记,避免 open-with 看到陈旧 true */
|
|
13626
|
+
G.ideBootDone = false
|
|
13627
|
+
}, [])
|
|
13628
|
+
useEffect(() => {
|
|
13629
|
+
if (bootStage === 'done') {
|
|
13630
|
+
G.ideBootDone = true
|
|
13631
|
+
void G.api('dev.log', { message: 'boot-stage done' }).catch(() => {})
|
|
13632
|
+
} else if (bootStage === 'loading') {
|
|
13633
|
+
G.ideBootDone = false
|
|
13634
|
+
}
|
|
13635
|
+
return () => { if (bootStage === 'done') G.ideBootDone = false }
|
|
13636
|
+
}, [bootStage])
|
|
13436
13637
|
/* 会话运行状态(与经典侧边栏同源:uiSession.sessionStatus,含 running/pendingInteraction/completionUnread) */
|
|
13437
13638
|
const [sessionStatuses, setSessionStatuses] = useState(() => new Map())
|
|
13438
13639
|
const [sessionStatusReady, setSessionStatusReady] = useState(false)
|
|
@@ -13482,6 +13683,14 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13482
13683
|
G.projectRoot = typeof value?.root === 'string' ? value.root : null
|
|
13483
13684
|
setProject(value)
|
|
13484
13685
|
writeJson(GUFA_LS.project, value?.root ?? null)
|
|
13686
|
+
try {
|
|
13687
|
+
if ((window.__gufaProjectApplyLogs ?? 20) > 0) {
|
|
13688
|
+
window.__gufaProjectApplyLogs = (window.__gufaProjectApplyLogs ?? 20) - 1
|
|
13689
|
+
void G.api('dev.log', { message: `project-apply root=${String(value?.root ?? '')}` }).catch(() => {})
|
|
13690
|
+
}
|
|
13691
|
+
} catch {
|
|
13692
|
+
/* ignore */
|
|
13693
|
+
}
|
|
13485
13694
|
setTabs([])
|
|
13486
13695
|
setActivePath(null)
|
|
13487
13696
|
setSelection(null)
|
|
@@ -13506,8 +13715,31 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13506
13715
|
if (bootedRef.current) return
|
|
13507
13716
|
bootedRef.current = true
|
|
13508
13717
|
let cancelled = false
|
|
13718
|
+
setBootStage('idle')
|
|
13509
13719
|
void (async () => {
|
|
13510
13720
|
/* 从工作区菜单点进来的:跳过「恢复上次项目」,直接按入口工作区打开 */
|
|
13721
|
+
/* 系统「打开方式」:优先直接打开文件所在目录,绝不先恢复上次项目,避免随后覆盖 */
|
|
13722
|
+
const pendingOpenEntries = Array.isArray(G.pendingOpenEntries) ? G.pendingOpenEntries : null
|
|
13723
|
+
if (pendingOpenEntries !== null && pendingOpenEntries.length > 0) {
|
|
13724
|
+
const firstOpen = pendingOpenEntries.find((entry) => entry !== null && typeof entry === 'object' && typeof entry.path === 'string' && entry.path !== '')
|
|
13725
|
+
if (firstOpen !== undefined) {
|
|
13726
|
+
const openPath = String(firstOpen.path)
|
|
13727
|
+
const normalizedOpen = openPath.replace(/\\/g, '/')
|
|
13728
|
+
const openDir = firstOpen.kind === 'dir'
|
|
13729
|
+
? openPath
|
|
13730
|
+
: (normalizedOpen.lastIndexOf('/') > 0 ? openPath.slice(0, normalizedOpen.lastIndexOf('/')) : openPath)
|
|
13731
|
+
try {
|
|
13732
|
+
const value = await G.api('project.open', { path: openDir })
|
|
13733
|
+
if (!cancelled) applyProject(value)
|
|
13734
|
+
void G.api('dev.log', { message: `open-with boot workspace=${value.root}` }).catch(() => {})
|
|
13735
|
+
return
|
|
13736
|
+
} catch (error) {
|
|
13737
|
+
if (!cancelled) setBootError(G.errorText(error))
|
|
13738
|
+
}
|
|
13739
|
+
}
|
|
13740
|
+
}
|
|
13741
|
+
const preferSessionWorkspace = G.pendingSessionEntry === true
|
|
13742
|
+
if (preferSessionWorkspace) G.pendingSessionEntry = false
|
|
13511
13743
|
const pendingEntry = G.pendingEntryWorkspace
|
|
13512
13744
|
if (pendingEntry !== null && pendingEntry !== undefined && typeof pendingEntry.key === 'string') {
|
|
13513
13745
|
try {
|
|
@@ -13523,6 +13755,15 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13523
13755
|
/* 回落到恢复上次项目 */
|
|
13524
13756
|
}
|
|
13525
13757
|
}
|
|
13758
|
+
if (preferSessionWorkspace && typeof sessionCwd === 'string' && sessionCwd !== '') {
|
|
13759
|
+
try {
|
|
13760
|
+
const value = await G.api('project.open', { path: sessionCwd })
|
|
13761
|
+
if (!cancelled) applyProject(value)
|
|
13762
|
+
} catch (error) {
|
|
13763
|
+
if (!cancelled) setBootError(G.errorText(error))
|
|
13764
|
+
}
|
|
13765
|
+
return
|
|
13766
|
+
}
|
|
13526
13767
|
const saved = floatState !== null && floatState !== undefined && typeof floatState.projectRoot === 'string' && floatState.projectRoot !== ''
|
|
13527
13768
|
? floatState.projectRoot
|
|
13528
13769
|
: readJson(GUFA_LS.project)
|
|
@@ -13546,7 +13787,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13546
13787
|
if (!cancelled) setBootError(G.errorText(error))
|
|
13547
13788
|
}
|
|
13548
13789
|
}
|
|
13549
|
-
})()
|
|
13790
|
+
})().catch(() => {}).finally(() => {
|
|
13791
|
+
/* 依赖变化触发的 cleanup 不代表组件卸载;这里必须无条件发出 boot 完成信号 */
|
|
13792
|
+
setBootStage('done')
|
|
13793
|
+
})
|
|
13550
13794
|
return () => {
|
|
13551
13795
|
cancelled = true
|
|
13552
13796
|
}
|
|
@@ -13699,7 +13943,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13699
13943
|
/* ignore */
|
|
13700
13944
|
}
|
|
13701
13945
|
setActivePath(existing.path)
|
|
13702
|
-
return
|
|
13946
|
+
return true
|
|
13703
13947
|
}
|
|
13704
13948
|
try {
|
|
13705
13949
|
const doc = await G.api('fs.read', { root: project.root, path })
|
|
@@ -13730,8 +13974,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13730
13974
|
))
|
|
13731
13975
|
}
|
|
13732
13976
|
setActivePath(gufaNormalizeProjectPath(doc.path ?? path))
|
|
13977
|
+
return true
|
|
13733
13978
|
} catch (error) {
|
|
13734
13979
|
setBanner(G.errorText(error))
|
|
13980
|
+
return false
|
|
13735
13981
|
}
|
|
13736
13982
|
}, [project, tabs])
|
|
13737
13983
|
|
|
@@ -13743,20 +13989,106 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13743
13989
|
|
|
13744
13990
|
/* 从搜索/定位结果打开文件并跳到指定行列(等 tab 切换完成后再触发编辑器 reveal) */
|
|
13745
13991
|
const openFileAt = useCallback(async (rawPath, line, column) => {
|
|
13746
|
-
if (typeof rawPath !== 'string' || rawPath === '') return
|
|
13992
|
+
if (typeof rawPath !== 'string' || rawPath === '') return false
|
|
13747
13993
|
const path = gufaNormalizeProjectPath(rawPath)
|
|
13748
|
-
await openFile(path)
|
|
13994
|
+
const opened = await openFile(path)
|
|
13995
|
+
if (opened === false) return false
|
|
13749
13996
|
const targetLine = Number.isFinite(Number(line)) ? Math.max(1, Math.trunc(Number(line))) : 1
|
|
13750
13997
|
const targetColumn = Number.isFinite(Number(column)) ? Math.max(1, Math.trunc(Number(column))) : 1
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13998
|
+
const target = { path, line: targetLine, column: targetColumn }
|
|
13999
|
+
const currentActive = activePathRef.current === null ? null : gufaNormalizeProjectPath(activePathRef.current)
|
|
14000
|
+
if (currentActive === path) {
|
|
14001
|
+
/* 文件本来就打开着:编辑器/model 已就绪,延迟一帧即可 */
|
|
14002
|
+
window.setTimeout(() => {
|
|
14003
|
+
try { G.bus.emit('editor:reveal', target) } catch { /* ignore */ }
|
|
14004
|
+
}, 80)
|
|
14005
|
+
return
|
|
14006
|
+
}
|
|
14007
|
+
/* 文件未打开:交给 activePath effect,在 tab 真正切过去之后再 reveal(避免固定 120ms 的竞态) */
|
|
14008
|
+
pendingOpenAtRef.current = target
|
|
13758
14009
|
}, [openFile])
|
|
13759
14010
|
|
|
14011
|
+
/* 系统文件「打开方式」:暴露入口给 99-main 的 pending 轮询(打开指定绝对路径文件)。 */
|
|
14012
|
+
const projectRef = useRef(project)
|
|
14013
|
+
projectRef.current = project
|
|
14014
|
+
const applyProjectRef = useRef(applyProject)
|
|
14015
|
+
applyProjectRef.current = applyProject
|
|
14016
|
+
const openFileAtRef = useRef(openFileAt)
|
|
14017
|
+
openFileAtRef.current = openFileAt
|
|
14018
|
+
const openFileRef = useRef(openFile)
|
|
14019
|
+
openFileRef.current = openFile
|
|
14020
|
+
useEffect(() => {
|
|
14021
|
+
const sleep = (ms) => new Promise((resolve) => { window.setTimeout(resolve, ms) })
|
|
14022
|
+
const normalize = (value) => String(value ?? '').replace(/\\/g, '/').replace(/\/+$/, '')
|
|
14023
|
+
const dirOf = (value) => {
|
|
14024
|
+
const normalized = String(value ?? '').replace(/\\/g, '/')
|
|
14025
|
+
const index = normalized.lastIndexOf('/')
|
|
14026
|
+
return index > 0 ? String(value).slice(0, value.length - (normalized.length - index)) : value
|
|
14027
|
+
}
|
|
14028
|
+
const handler = async (entries) => {
|
|
14029
|
+
const list = Array.isArray(entries)
|
|
14030
|
+
? entries.filter((entry) => entry !== null && typeof entry === 'object' && typeof entry.path === 'string' && entry.path !== '')
|
|
14031
|
+
: []
|
|
14032
|
+
if (list.length === 0) return false
|
|
14033
|
+
const first = list[0]
|
|
14034
|
+
const targetDir = first.kind === 'dir' ? first.path : dirOf(first.path)
|
|
14035
|
+
const targetRoot = normalize(targetDir)
|
|
14036
|
+
if (normalize(projectRef.current?.root) !== targetRoot) {
|
|
14037
|
+
try {
|
|
14038
|
+
const value = await G.api('project.open', { path: targetDir })
|
|
14039
|
+
applyProjectRef.current(value)
|
|
14040
|
+
/* 等 React 把项目状态提交;如果 boot 恢复旧项目还在覆盖,继续等目标根稳定 */
|
|
14041
|
+
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
14042
|
+
await sleep(150)
|
|
14043
|
+
if (normalize(projectRef.current?.root) === targetRoot) break
|
|
14044
|
+
}
|
|
14045
|
+
if (normalize(projectRef.current?.root) !== targetRoot) {
|
|
14046
|
+
console.error('[gufa-code] 目标工作区未稳定', targetRoot, projectRef.current?.root)
|
|
14047
|
+
return false
|
|
14048
|
+
}
|
|
14049
|
+
} catch (error) {
|
|
14050
|
+
console.error('[gufa-code] 打开文件所在工作区失败', error)
|
|
14051
|
+
return false
|
|
14052
|
+
}
|
|
14053
|
+
}
|
|
14054
|
+
const root = normalize(projectRef.current?.root ?? targetRoot)
|
|
14055
|
+
void G.api('dev.log', { message: `open-with apply dir=${targetDir} root=${root}` }).catch(() => {})
|
|
14056
|
+
const files = list.filter((entry) => entry.kind !== 'dir')
|
|
14057
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
14058
|
+
const absolute = normalize(files[index].path)
|
|
14059
|
+
const rel = absolute.startsWith(`${root}/`) ? absolute.slice(root.length + 1) : absolute.split('/').pop()
|
|
14060
|
+
if (typeof rel !== 'string' || rel === '' || rel.includes('..')) continue
|
|
14061
|
+
void G.api('dev.log', { message: `open-with open rel=${rel}` }).catch(() => {})
|
|
14062
|
+
const opened = index === 0
|
|
14063
|
+
? await openFileAtRef.current(rel, 1, 1)
|
|
14064
|
+
: await openFileRef.current(rel)
|
|
14065
|
+
if (opened === false) {
|
|
14066
|
+
void G.api('dev.log', { message: `open-with open-failed rel=${rel}` }).catch(() => {})
|
|
14067
|
+
return false
|
|
14068
|
+
}
|
|
14069
|
+
}
|
|
14070
|
+
G.pendingOpenEntries = null
|
|
14071
|
+
return true
|
|
14072
|
+
}
|
|
14073
|
+
G.ideOpenPaths = handler
|
|
14074
|
+
return () => {
|
|
14075
|
+
if (G.ideOpenPaths === handler) G.ideOpenPaths = null
|
|
14076
|
+
}
|
|
14077
|
+
}, [])
|
|
14078
|
+
|
|
14079
|
+
|
|
14080
|
+
/* 未打开文件跳转:activePath 切到目标文件后(子组件编辑器 effect 已先行)再发 reveal */
|
|
14081
|
+
useEffect(() => {
|
|
14082
|
+
const pending = pendingOpenAtRef.current
|
|
14083
|
+
if (pending === null || pending === undefined) return undefined
|
|
14084
|
+
if (activePath === null || gufaNormalizeProjectPath(activePath) !== gufaNormalizeProjectPath(pending.path)) return undefined
|
|
14085
|
+
pendingOpenAtRef.current = null
|
|
14086
|
+
const timer = window.setTimeout(() => {
|
|
14087
|
+
try { G.bus.emit('editor:reveal', pending) } catch { /* ignore */ }
|
|
14088
|
+
}, 40)
|
|
14089
|
+
return () => window.clearTimeout(timer)
|
|
14090
|
+
}, [activePath])
|
|
14091
|
+
|
|
13760
14092
|
/* Cmd/Ctrl+点击定义:编辑器 → App 跳转 / 多结果选择(兜底搜索在 host/code.js) */
|
|
13761
14093
|
useEffect(() => {
|
|
13762
14094
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
@@ -14893,6 +15225,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14893
15225
|
const entryWorkspaceSyncedRef = useRef(false)
|
|
14894
15226
|
useEffect(() => {
|
|
14895
15227
|
if (entryWorkspaceSyncedRef.current) return
|
|
15228
|
+
/* 系统「打开方式」正在处理:工作区由 open-with 决定,入口同步不得改回会话 cwd */
|
|
15229
|
+
if (G.openWithActive === true) {
|
|
15230
|
+
entryWorkspaceSyncedRef.current = true
|
|
15231
|
+
return
|
|
15232
|
+
}
|
|
14896
15233
|
/* 实例窗口:保持空工作区,不跟随主窗口/DSH 当前会话自动打开项目 */
|
|
14897
15234
|
if (G.instanceBoot === true) {
|
|
14898
15235
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -14903,14 +15240,12 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14903
15240
|
entryWorkspaceSyncedRef.current = true
|
|
14904
15241
|
return
|
|
14905
15242
|
}
|
|
14906
|
-
if (project === null && (G.pendingEntryWorkspace === null || G.pendingEntryWorkspace === undefined)) return
|
|
14907
15243
|
const pending = G.pendingEntryWorkspace
|
|
14908
15244
|
if (pending === null || pending === undefined || typeof pending.key !== 'string') {
|
|
14909
|
-
|
|
15245
|
+
/* 没有显式入口(例如重启 DSH 自动恢复 IDE):保留 boot 已恢复的「上次工作区」,
|
|
15246
|
+
不要改回当前会话 cwd —— 否则 open-with 打开的工作区永远不会被记住。 */
|
|
14910
15247
|
entryWorkspaceSyncedRef.current = true
|
|
14911
|
-
|
|
14912
|
-
void openProjectPath(sessionCwd).catch((error) => setBanner(G.errorText(error)))
|
|
14913
|
-
}
|
|
15248
|
+
void G.api('dev.log', { message: `entry-sync keep-saved project=${project !== null && typeof project.root === 'string' ? project.root : 'null'} sessionCwd=${typeof sessionCwd === 'string' ? sessionCwd : ''}` }).catch(() => {})
|
|
14914
15249
|
return
|
|
14915
15250
|
}
|
|
14916
15251
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -17053,6 +17388,162 @@ G.installWorkspaceMenuEntry = function installWorkspaceMenuEntry(ctx) {
|
|
|
17053
17388
|
}
|
|
17054
17389
|
}
|
|
17055
17390
|
|
|
17391
|
+
/** 经典模式聊天标题行的文本入口:和「智能体团队」同款 link 样式,但文案直接叫「古法编程」。 */
|
|
17392
|
+
G.GufaHeaderEntry = function GufaHeaderEntry() {
|
|
17393
|
+
const ideVisible = G.useMode()
|
|
17394
|
+
if (ideVisible === true) return null
|
|
17395
|
+
return h(
|
|
17396
|
+
'button',
|
|
17397
|
+
{
|
|
17398
|
+
type: 'button',
|
|
17399
|
+
className: 'gufa-header-entry',
|
|
17400
|
+
title: '进入古法编程(当前聊天的工作区)',
|
|
17401
|
+
'aria-label': '古法编程',
|
|
17402
|
+
onClick: (event) => {
|
|
17403
|
+
try {
|
|
17404
|
+
event.preventDefault()
|
|
17405
|
+
event.stopPropagation()
|
|
17406
|
+
} catch {
|
|
17407
|
+
/* ignore */
|
|
17408
|
+
}
|
|
17409
|
+
try {
|
|
17410
|
+
G.pendingSessionEntry = true
|
|
17411
|
+
G.enterGufa()
|
|
17412
|
+
} catch (error) {
|
|
17413
|
+
console.error('[gufa-code] 进入古法编程失败', error)
|
|
17414
|
+
}
|
|
17415
|
+
},
|
|
17416
|
+
},
|
|
17417
|
+
h('span', { className: 'gufa-header-entry-label' }, '古法编程'),
|
|
17418
|
+
)
|
|
17419
|
+
}
|
|
17420
|
+
|
|
17421
|
+
/** 文件关联打开:订阅 Host 的 open.watch 事件(不再轮询文件),处理成功后 ack。 */
|
|
17422
|
+
G.installOpenWithHandler = function installOpenWithHandler(ctx) {
|
|
17423
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') return () => {}
|
|
17424
|
+
let skip = false
|
|
17425
|
+
try {
|
|
17426
|
+
skip = typeof G.isFloatMode === 'function' && G.isFloatMode() === true
|
|
17427
|
+
if (!skip && /[?&]gufa-instance=1/.test(String(location.search || ''))) skip = true
|
|
17428
|
+
if (!skip && /welcome|update/i.test(String(location.href || ''))) skip = true
|
|
17429
|
+
} catch {
|
|
17430
|
+
skip = false
|
|
17431
|
+
}
|
|
17432
|
+
if (skip) return () => {}
|
|
17433
|
+
let stopped = false
|
|
17434
|
+
let busy = false
|
|
17435
|
+
let lastToken = ''
|
|
17436
|
+
let abortStream = null
|
|
17437
|
+
let reconnectTimer = 0
|
|
17438
|
+
let retryTimer = 0
|
|
17439
|
+
let logs = 20
|
|
17440
|
+
const log = (message) => {
|
|
17441
|
+
if (logs <= 0) return
|
|
17442
|
+
logs -= 1
|
|
17443
|
+
try { void G.api('dev.log', { message }).catch(() => {}) } catch { /* ignore */ }
|
|
17444
|
+
}
|
|
17445
|
+
const sleep = (ms) => new Promise((resolve) => { window.setTimeout(resolve, ms) })
|
|
17446
|
+
const ideReady = () => {
|
|
17447
|
+
try {
|
|
17448
|
+
return G.mode.get() === true
|
|
17449
|
+
&& G.ideBootDone === true
|
|
17450
|
+
&& typeof G.ideOpenPaths === 'function'
|
|
17451
|
+
&& document.querySelector('.gufa-overlay-root') !== null
|
|
17452
|
+
} catch {
|
|
17453
|
+
return false
|
|
17454
|
+
}
|
|
17455
|
+
}
|
|
17456
|
+
const waitIdeReady = async (maxAttempts = 100) => {
|
|
17457
|
+
for (let attempt = 0; attempt < maxAttempts && stopped !== true; attempt += 1) {
|
|
17458
|
+
if (ideReady()) return true
|
|
17459
|
+
await sleep(200)
|
|
17460
|
+
}
|
|
17461
|
+
return false
|
|
17462
|
+
}
|
|
17463
|
+
const openEntries = async (entries) => {
|
|
17464
|
+
if (!ideReady()) {
|
|
17465
|
+
log(`open-with enter ide mode=${G.mode.get() === true} hook=${typeof G.ideOpenPaths === 'function'} boot=${G.ideBootDone === true}`)
|
|
17466
|
+
try {
|
|
17467
|
+
G.pendingOpenEntries = entries
|
|
17468
|
+
G.pendingSessionEntry = false
|
|
17469
|
+
G.enterGufa()
|
|
17470
|
+
} catch {
|
|
17471
|
+
return false
|
|
17472
|
+
}
|
|
17473
|
+
/* 必须等 IDE 覆盖层真正挂载 + App 初始 boot 完成,否则旧项目会覆盖刚打开的工作区 */
|
|
17474
|
+
if (!(await waitIdeReady())) return false
|
|
17475
|
+
}
|
|
17476
|
+
const result = await G.ideOpenPaths(entries)
|
|
17477
|
+
return result !== false
|
|
17478
|
+
}
|
|
17479
|
+
const handlePending = async (event) => {
|
|
17480
|
+
if (stopped || busy) return
|
|
17481
|
+
const entries = event !== null && event !== undefined && Array.isArray(event.entries) ? event.entries : []
|
|
17482
|
+
const token = event !== null && event !== undefined && typeof event.token === 'string' ? event.token : ''
|
|
17483
|
+
if (entries.length === 0 || token === '' || token === lastToken) return
|
|
17484
|
+
G.openWithActive = true
|
|
17485
|
+
busy = true
|
|
17486
|
+
log(`open-with pending token=${token} entries=${entries.length} paths=${entries.map((entry) => entry.path).join('|')}`)
|
|
17487
|
+
const ok = await openEntries(entries)
|
|
17488
|
+
busy = false
|
|
17489
|
+
if (stopped) return
|
|
17490
|
+
if (ok) {
|
|
17491
|
+
lastToken = token
|
|
17492
|
+
await G.api('open.ack', { token }).catch(() => {})
|
|
17493
|
+
G.openWithActive = false
|
|
17494
|
+
log(`open-with ack token=${token}`)
|
|
17495
|
+
return
|
|
17496
|
+
}
|
|
17497
|
+
log(`open-with retry token=${token}`)
|
|
17498
|
+
if (retryTimer !== 0) window.clearTimeout(retryTimer)
|
|
17499
|
+
retryTimer = window.setTimeout(() => {
|
|
17500
|
+
retryTimer = 0
|
|
17501
|
+
void handlePending(event)
|
|
17502
|
+
}, 3000)
|
|
17503
|
+
}
|
|
17504
|
+
const scheduleReconnect = (delay = 1500) => {
|
|
17505
|
+
if (stopped) return
|
|
17506
|
+
if (reconnectTimer !== 0) return
|
|
17507
|
+
reconnectTimer = window.setTimeout(() => {
|
|
17508
|
+
reconnectTimer = 0
|
|
17509
|
+
connect()
|
|
17510
|
+
}, delay)
|
|
17511
|
+
}
|
|
17512
|
+
const connect = () => {
|
|
17513
|
+
if (stopped) return
|
|
17514
|
+
try {
|
|
17515
|
+
abortStream = G.stream('open.watch', {}, (event) => {
|
|
17516
|
+
if (event === null || event === undefined) return
|
|
17517
|
+
if (event.type === 'pending') void handlePending(event)
|
|
17518
|
+
else if (event.type === 'error') scheduleReconnect()
|
|
17519
|
+
}, () => scheduleReconnect())
|
|
17520
|
+
log('open-with stream connected')
|
|
17521
|
+
} catch {
|
|
17522
|
+
scheduleReconnect(3000)
|
|
17523
|
+
}
|
|
17524
|
+
}
|
|
17525
|
+
const start = () => {
|
|
17526
|
+
if (stopped) return
|
|
17527
|
+
void G.api('open.ensure', {}).catch(() => {})
|
|
17528
|
+
connect()
|
|
17529
|
+
}
|
|
17530
|
+
try {
|
|
17531
|
+
if (typeof ctx?.inject === 'function') ctx.inject(['layout'], () => start())
|
|
17532
|
+
else start()
|
|
17533
|
+
} catch {
|
|
17534
|
+
start()
|
|
17535
|
+
}
|
|
17536
|
+
return () => {
|
|
17537
|
+
stopped = true
|
|
17538
|
+
if (reconnectTimer !== 0) window.clearTimeout(reconnectTimer)
|
|
17539
|
+
if (retryTimer !== 0) window.clearTimeout(retryTimer)
|
|
17540
|
+
reconnectTimer = 0
|
|
17541
|
+
retryTimer = 0
|
|
17542
|
+
try { if (typeof abortStream === 'function') abortStream() } catch { /* ignore */ }
|
|
17543
|
+
abortStream = null
|
|
17544
|
+
}
|
|
17545
|
+
}
|
|
17546
|
+
|
|
17056
17547
|
/** 「更多」菜单里的入口行:点击进入古法编程(从当前工作区进入)。 */
|
|
17057
17548
|
G.MoreMenuEntry = function MoreMenuEntry(props) {
|
|
17058
17549
|
return h(
|
|
@@ -17643,6 +18134,14 @@ const GUFA_PLUGIN = {
|
|
|
17643
18134
|
}
|
|
17644
18135
|
}, 2500)
|
|
17645
18136
|
|
|
18137
|
+
// 系统文件「打开方式」:自动安装打开器并轮询 pending 文件请求。
|
|
18138
|
+
try {
|
|
18139
|
+
const disposeOpenWith = G.installOpenWithHandler(ctx)
|
|
18140
|
+
if (typeof disposeOpenWith === 'function') ctx.effect(() => disposeOpenWith, 'gufa-code: open-with handler')
|
|
18141
|
+
} catch (error) {
|
|
18142
|
+
console.error('[gufa-code] 文件关联打开器安装失败', error)
|
|
18143
|
+
}
|
|
18144
|
+
|
|
17646
18145
|
// 入口:工作区行的「...」菜单里注入「古法编程」一行。
|
|
17647
18146
|
try {
|
|
17648
18147
|
const disposeMenuEntry = G.installWorkspaceMenuEntry(ctx)
|
|
@@ -17651,6 +18150,19 @@ const GUFA_PLUGIN = {
|
|
|
17651
18150
|
console.error('[gufa-code] 安装工作区菜单入口失败', error)
|
|
17652
18151
|
}
|
|
17653
18152
|
|
|
18153
|
+
// 经典模式聊天右上角工具区:在头像菜单左侧的空位放「古法编程」文本入口。
|
|
18154
|
+
try {
|
|
18155
|
+
ctx.inject(['slots'], (scope) => {
|
|
18156
|
+
scope.slots.inject('conversation.session.header.utilities', () => scope.slots.register({
|
|
18157
|
+
name: 'conversation.session.header.utilities',
|
|
18158
|
+
id: 'gufa-code-entry',
|
|
18159
|
+
order: -100,
|
|
18160
|
+
}, G.GufaHeaderEntry))
|
|
18161
|
+
})
|
|
18162
|
+
} catch (error) {
|
|
18163
|
+
console.error('[gufa-code] 聊天头部入口注册失败', error)
|
|
18164
|
+
}
|
|
18165
|
+
|
|
17654
18166
|
// 面板注册:入口注入到工作区行的「...」菜单里(DSH 未提供该菜单的 slot)。
|
|
17655
18167
|
ctx.inject(['slots'], (scope) => {
|
|
17656
18168
|
// main key 仅作安全网:若侧边栏把主面板切到 gufa-code(点击拦截失效时),
|