dsh-gufa-code 1.3.108 → 1.3.112
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 +1 -0
- package/client.js +144 -1
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +8 -1
- package/host/fs.js +17 -0
- package/package.json +1 -1
- package/scripts/selftest-host.mjs +7 -0
- package/src/client/20-editor.js +47 -0
- package/src/client/90-app.js +96 -0
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ dsh plugin add dsh-gufa-code
|
|
|
41
41
|
- Monaco 编辑器(离线随包分发,无需联网下载);Monaco 自带 81 种语言全部映射(ABAP、Apex、Clojure、Elixir、F#、GraphQL、HCL/Terraform、Julia、Objective-C、Pascal、Perl、Protobuf、R、RST、Scheme、Solidity、SystemVerilog/Verilog、Tcl、TypeSpec、VB、WGSL、Bicep、Batch、CoffeeScript、Cypher、DAX、Logstash/ECL、MIPS、Power Query、Q#、Redis、SPARQL、Structured Text、Modula-3、ATS、Pony 系列等);
|
|
42
42
|
- **HTML 模板语法高亮**:EJS / Eta、ERB、Nunjucks / Jinja2(`.njk/.nunjucks/.jinja/.jinja2/.j2`)、Blade(`.blade.php`)、Haml、Slim,以及 Monaco 内置的 Handlebars / Mustache / Pug / Twig / Liquid / Razor / FreeMarker;扩展名自动识别;
|
|
43
43
|
- 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
|
|
44
|
+
- **AI/外部修改自动刷新**:已打开的标签每 1.6s 检查一次磁盘 mtime/size,AI 在会话里改完代码后编辑器自动换成新内容(保留光标位置),不需要关闭重开;点击文件树里的已打开文件也会重新对齐磁盘;有未保存修改时不会覆盖用户内容;
|
|
44
45
|
- **Copilot 风格 Tab 行内补全**:光标停/打字后,基于 Harness 自己的 DeepSeek 模型(默认 `deepseek-flash`,不需要额外 Copilot 订阅)流式生成灰色 ghost text,Tab 接受、Esc 忽略;支持 JS/TS/Python/Java/Go/Rust/C++/C#/JSON/YAML/Shell 等常见语言;
|
|
45
46
|
- 保存走磁盘版本冲突检测 + 原子写;未保存标记;
|
|
46
47
|
- **⌘/Ctrl + 点击跳转定义 / 方法实现**:Python 走 **Pyright 语言服务(LSP)**,JS/TS 走 Monaco 内置 TypeScript 语言服务(点击前会按需把当前文件的 import 依赖加载进 Monaco,跨文件变量/函数由 TS 语言服务解析);其他语言暂用项目级定义搜索兜底;优先走 Monaco 语言服务;目标文件没在 Monaco 里打开、或语言没有内置语言服务时,自动用项目级定义搜索兜底(函数 / 类 / 方法 / const / type 等声明)。兜底会解析 import/require 直接定位来源文件,并跳过压缩产物/大文件;同一个文件里的声明、import 命中的定义、目录距离近的定义直接跳,只有多个真正同名的声明才弹「跳转到定义」列表,点同名属性/变量时不会拿远端无关的 const 来凑数;按住 ⌘/Ctrl 悬停时,可跳转的符号会显示下划线 + 手型光标;
|
package/client.js
CHANGED
|
@@ -16,7 +16,7 @@ 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.112'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -3852,6 +3852,53 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3852
3852
|
/* ignore */
|
|
3853
3853
|
}
|
|
3854
3854
|
|
|
3855
|
+
/* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容 */
|
|
3856
|
+
try {
|
|
3857
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
3858
|
+
const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
|
|
3859
|
+
if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
|
|
3860
|
+
const target = modelsRef.current.get(detail.path)
|
|
3861
|
+
if (target === null || target === undefined) return
|
|
3862
|
+
let content = ''
|
|
3863
|
+
try {
|
|
3864
|
+
content = target.getValue()
|
|
3865
|
+
} catch {
|
|
3866
|
+
return
|
|
3867
|
+
}
|
|
3868
|
+
if (content === detail.content) return
|
|
3869
|
+
const active = modelPathRef.current === detail.path
|
|
3870
|
+
let position = null
|
|
3871
|
+
let scrollTop = 0
|
|
3872
|
+
if (active) {
|
|
3873
|
+
try {
|
|
3874
|
+
position = instance.getPosition()
|
|
3875
|
+
scrollTop = instance.getScrollTop()
|
|
3876
|
+
} catch {
|
|
3877
|
+
position = null
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
suppressChangeRef.current = true
|
|
3881
|
+
try {
|
|
3882
|
+
target.setValue(detail.content)
|
|
3883
|
+
} finally {
|
|
3884
|
+
suppressChangeRef.current = false
|
|
3885
|
+
}
|
|
3886
|
+
lastPropContentRef.current.set(detail.path, detail.content)
|
|
3887
|
+
if (active && position !== null && position !== undefined) {
|
|
3888
|
+
try {
|
|
3889
|
+
instance.setPosition(position)
|
|
3890
|
+
instance.setScrollTop(scrollTop)
|
|
3891
|
+
} catch {
|
|
3892
|
+
/* ignore */
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
})
|
|
3896
|
+
if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
|
|
3897
|
+
}
|
|
3898
|
+
} catch {
|
|
3899
|
+
/* ignore */
|
|
3900
|
+
}
|
|
3901
|
+
|
|
3855
3902
|
G.__gufaEditorDebug = {
|
|
3856
3903
|
focus: () => {
|
|
3857
3904
|
try {
|
|
@@ -12105,6 +12152,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12105
12152
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
12106
12153
|
const editorBuffersRef = useRef(new Map())
|
|
12107
12154
|
const tabsRef = useRef([])
|
|
12155
|
+
const reloadTabFromDiskRef = useRef(null)
|
|
12108
12156
|
const flushTimerRef = useRef(null)
|
|
12109
12157
|
const selectionTimerRef = useRef(null)
|
|
12110
12158
|
const pendingSelectionRef = useRef(null)
|
|
@@ -12331,6 +12379,12 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12331
12379
|
flushBuffersRef.current?.()
|
|
12332
12380
|
const existing = tabs.find((tab) => tab.path === path)
|
|
12333
12381
|
if (existing !== undefined) {
|
|
12382
|
+
/* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
|
|
12383
|
+
try {
|
|
12384
|
+
await reloadTabFromDiskRef.current?.(path)
|
|
12385
|
+
} catch {
|
|
12386
|
+
/* ignore */
|
|
12387
|
+
}
|
|
12334
12388
|
setActivePath(path)
|
|
12335
12389
|
return
|
|
12336
12390
|
}
|
|
@@ -12417,6 +12471,84 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12417
12471
|
})
|
|
12418
12472
|
}, [])
|
|
12419
12473
|
|
|
12474
|
+
/* 把某个已打开标签重新对齐磁盘内容(AI/外部修改检测、点击文件树时使用)。
|
|
12475
|
+
有未保存修改(dirty)时绝不覆盖用户内容。 */
|
|
12476
|
+
const reloadTabFromDisk = useCallback(async (path) => {
|
|
12477
|
+
if (project === null) return false
|
|
12478
|
+
const tab = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
|
|
12479
|
+
if (tab === undefined || tab.kind === 'diff' || tab.kind === 'graph') return false
|
|
12480
|
+
try {
|
|
12481
|
+
const doc = await G.api('fs.read', { root: project.root, path })
|
|
12482
|
+
const latest = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
|
|
12483
|
+
if (latest === undefined || latest.dirty === true) return false
|
|
12484
|
+
if (latest.revision === doc.revision && latest.content === doc.content) return false
|
|
12485
|
+
editorBuffersRef.current.delete(path)
|
|
12486
|
+
patchTab(path, {
|
|
12487
|
+
content: doc.content,
|
|
12488
|
+
revision: doc.revision,
|
|
12489
|
+
savedRevision: doc.revision,
|
|
12490
|
+
savedContent: doc.content,
|
|
12491
|
+
dirty: false,
|
|
12492
|
+
size: doc.size,
|
|
12493
|
+
mtimeMs: doc.mtimeMs,
|
|
12494
|
+
})
|
|
12495
|
+
try {
|
|
12496
|
+
G.bus.emit('editor:external-reload', { path, content: doc.content })
|
|
12497
|
+
} catch {
|
|
12498
|
+
/* ignore */
|
|
12499
|
+
}
|
|
12500
|
+
return true
|
|
12501
|
+
} catch {
|
|
12502
|
+
return false
|
|
12503
|
+
}
|
|
12504
|
+
}, [project, patchTab])
|
|
12505
|
+
reloadTabFromDiskRef.current = reloadTabFromDisk
|
|
12506
|
+
|
|
12507
|
+
/* AI/外部进程修改磁盘文件:轮询已打开且未修改的标签,自动同步编辑器和标签内容。
|
|
12508
|
+
1.6s 一次 fs.mtimes(只 stat),发现 mtime/size 变化才 fs.read 全文。 */
|
|
12509
|
+
useEffect(() => {
|
|
12510
|
+
if (project === null) return undefined
|
|
12511
|
+
let cancelled = false
|
|
12512
|
+
let busy = false
|
|
12513
|
+
const sync = async () => {
|
|
12514
|
+
if (busy || cancelled || document.visibilityState !== 'visible') return
|
|
12515
|
+
busy = true
|
|
12516
|
+
try {
|
|
12517
|
+
const open = (tabsRef.current ?? []).filter((tab) => tab !== null && tab !== undefined
|
|
12518
|
+
&& typeof tab.path === 'string' && tab.kind !== 'diff' && tab.kind !== 'graph')
|
|
12519
|
+
const clean = open.filter((tab) => tab.dirty !== true).slice(0, 24)
|
|
12520
|
+
if (clean.length === 0) return
|
|
12521
|
+
let result = null
|
|
12522
|
+
try {
|
|
12523
|
+
result = await G.api('fs.mtimes', { root: project.root, paths: clean.map((tab) => tab.path) })
|
|
12524
|
+
} catch {
|
|
12525
|
+
return
|
|
12526
|
+
}
|
|
12527
|
+
const files = result !== null && result !== undefined && result.files !== null && result.files !== undefined ? result.files : {}
|
|
12528
|
+
for (const tab of clean) {
|
|
12529
|
+
if (cancelled) break
|
|
12530
|
+
const info = files[tab.path]
|
|
12531
|
+
if (info === null || info === undefined || info.missing === true) continue
|
|
12532
|
+
if (Number(info.mtimeMs) === Number(tab.mtimeMs) && Number(info.size) === Number(tab.size)) continue
|
|
12533
|
+
await reloadTabFromDisk(tab.path)
|
|
12534
|
+
}
|
|
12535
|
+
} finally {
|
|
12536
|
+
busy = false
|
|
12537
|
+
}
|
|
12538
|
+
}
|
|
12539
|
+
const timer = window.setInterval(() => { void sync() }, 1600)
|
|
12540
|
+
const onVisible = () => { if (document.visibilityState === 'visible') void sync() }
|
|
12541
|
+
window.addEventListener('focus', onVisible)
|
|
12542
|
+
document.addEventListener('visibilitychange', onVisible)
|
|
12543
|
+
void sync()
|
|
12544
|
+
return () => {
|
|
12545
|
+
cancelled = true
|
|
12546
|
+
window.clearInterval(timer)
|
|
12547
|
+
window.removeEventListener('focus', onVisible)
|
|
12548
|
+
document.removeEventListener('visibilitychange', onVisible)
|
|
12549
|
+
}
|
|
12550
|
+
}, [project, reloadTabFromDisk])
|
|
12551
|
+
|
|
12420
12552
|
/* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
|
|
12421
12553
|
const flushEditorBuffers = useCallback(() => {
|
|
12422
12554
|
const buffers = editorBuffersRef.current
|
|
@@ -13140,6 +13272,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13140
13272
|
const consumeExitStateRef = useRef(false)
|
|
13141
13273
|
useEffect(() => {
|
|
13142
13274
|
if (G.isFloatMode()) return undefined
|
|
13275
|
+
if (G.instanceBoot === true) return undefined
|
|
13143
13276
|
let running = false
|
|
13144
13277
|
const consume = async () => {
|
|
13145
13278
|
if (running) return
|
|
@@ -13297,6 +13430,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13297
13430
|
const entryWorkspaceSyncedRef = useRef(false)
|
|
13298
13431
|
useEffect(() => {
|
|
13299
13432
|
if (entryWorkspaceSyncedRef.current) return
|
|
13433
|
+
/* 实例窗口:保持空工作区,不跟随主窗口/DSH 当前会话自动打开项目 */
|
|
13434
|
+
if (G.instanceBoot === true) {
|
|
13435
|
+
entryWorkspaceSyncedRef.current = true
|
|
13436
|
+
return
|
|
13437
|
+
}
|
|
13300
13438
|
/* 悬浮层(摸鱼):项目/会话由主窗口状态注入,不做「入口工作区」同步 */
|
|
13301
13439
|
if (G.isFloatMode()) {
|
|
13302
13440
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -13621,6 +13759,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13621
13759
|
const lastSessionCwdRef = useRef(null)
|
|
13622
13760
|
useEffect(() => {
|
|
13623
13761
|
if (sessionPinnedRef.current === true) return
|
|
13762
|
+
/* 实例窗口:不跟随会话 cwd 自动打开项目 */
|
|
13763
|
+
if (G.instanceBoot === true) {
|
|
13764
|
+
lastSessionCwdRef.current = sessionCwd
|
|
13765
|
+
return
|
|
13766
|
+
}
|
|
13624
13767
|
/* 悬浮层里项目由主窗口状态注入,不跟随(Web 版客户端自己的)会话 cwd 切换 */
|
|
13625
13768
|
if (G.isFloatMode()) {
|
|
13626
13769
|
lastSessionCwdRef.current = sessionCwd
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
|
|
8
8
|
<key>CFBundleExecutable</key><string>gufa-float</string>
|
|
9
9
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
10
|
-
<key>CFBundleShortVersionString</key><string>1.3.
|
|
11
|
-
<key>CFBundleVersion</key><string>1.3.
|
|
10
|
+
<key>CFBundleShortVersionString</key><string>1.3.112</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.112</string>
|
|
12
12
|
<key>LSUIElement</key><true/>
|
|
13
13
|
<key>NSHighResolutionCapable</key><true/>
|
|
14
14
|
<key>NSPrincipalClass</key><string>NSApplication</string>
|
|
Binary file
|
package/docs/KNOWN-PITFALLS.md
CHANGED
|
@@ -59,10 +59,17 @@
|
|
|
59
59
|
- 实现:复用插件自带的原生 helper(`desktop/float/GufaFloat.m`),payload 传 `{full:true, authUrl, appUrl}` —— helper 建普通标题栏窗口、Regular 激活策略、跳过摸鱼 localStorage/隐藏主窗/吸附,加载同一个 DSH Web GUI;鉴权复用它已有的 `connection.authenticatedUrl()` token 流程。
|
|
60
60
|
- 客户端 ⌘⇧N 必须先调 Host `app.newWindow`,失败才回退 `window.open`(Electron 的 setWindowOpenHandler 会 deny 并用外部浏览器打开 http(s),不是应用内窗口)。
|
|
61
61
|
- 新窗口与 Electron 主窗口共享的是 **同一个 Host/服务端**,但 UI 进程独立(WKWebView,不走 Electron preload);所以别让新窗口依赖 `window.dshDesktop` 之类的 Electron preload API。
|
|
62
|
-
- **实例窗口不继承主窗口项目**(用户明确要求新窗口用来操作别的工作区):helper full 模式只清空 localStorage 里的 `gufa-code:float/float-state/project/ui/tabs/mode`,URL 带 `?gufa-instance=1`;客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root`
|
|
62
|
+
- **实例窗口不继承主窗口项目**(用户明确要求新窗口用来操作别的工作区):helper full 模式只清空 localStorage 里的 `gufa-code:float/float-state/project/ui/tabs/mode`,URL 带 `?gufa-instance=1`;客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root` 挂载。`G.instanceBoot` 必须同时挡住**所有**会自动打开项目的 effect:boot 的 sessionCwd 分支、入口工作区同步、会话 cwd 跟随(`lastSessionCwdRef`)、`float.consumeExitState`,否则 DSH 恢复当前会话后会把工作区带进新窗口。
|
|
63
63
|
- helper 的 WKWebView data store 与摸鱼悬浮层共享;full 模式必须清残留标记,否则新窗口会误进摸鱼 UI 或恢复上次项目。
|
|
64
64
|
- **全屏继承**:客户端用 `innerWidth/innerHeight` 对比 `screen.width/height` 和 `screen.availWidth/availHeight` 判断当前是否全屏,payload 传 `fullscreen:true`,helper 在窗口显示后 `toggleFullScreen`;不要依赖 Electron preload 或 AX 查询(Host 在 Node 模式进程里拿不到 Electron)。
|
|
65
65
|
|
|
66
|
+
## 0.12 AI/外部修改后编辑器自动刷新(1.3.112)
|
|
67
|
+
|
|
68
|
+
- 不能只在 Git 签名变化时刷新资源管理器:已打开标签的**内容**不会自己变,用户必须关掉重开;点击文件树时 `openFile` 对已存在标签只 `setActivePath`,也不会重新读盘。
|
|
69
|
+
- 方案:Host 新增 `fs.mtimes`(批量 stat,只返回 mtimeMs/size,不读全文);客户端每 1.6s 对可见窗口里的已打开干净标签轮询,mtime/size 变了才 `fs.read` 并更新 tab;`dirty` 标签绝不覆盖。
|
|
70
|
+
- 更新 Monaco model 不能只靠 App 的 props 同步:编辑器聚焦时同步 effect 会故意跳过外部内容以避免覆盖输入。App 通过 `G.bus.emit('editor:external-reload', {path, content})` 通知 EditorPane 直接 `model.setValue`,用 `suppressChangeRef` 防止把这次更新当用户输入回传,并恢复光标/滚动;同时写 `lastPropContentRef` 避免后续 props 同步再灌一次。
|
|
71
|
+
- 点击已打开文件(文件树/搜索)时也要先 `reloadTabFromDisk`,否则用户点文件列表看不到 AI 改动。
|
|
72
|
+
|
|
66
73
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
67
74
|
|
|
68
75
|
**现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
|
package/host/fs.js
CHANGED
|
@@ -346,6 +346,23 @@ export function register(router, env) {
|
|
|
346
346
|
return { path: relativePath(root, absolute), entries: rows }
|
|
347
347
|
})
|
|
348
348
|
|
|
349
|
+
/* 批量取 mtime/size:客户端轮询已打开文件是否被 AI/外部修改,避免每个文件都 fs.read 全文 */
|
|
350
|
+
router.method('fs.mtimes', async (body) => {
|
|
351
|
+
const root = await projectOf(env, body)
|
|
352
|
+
const paths = Array.isArray(body.paths) ? body.paths.filter((value) => typeof value === 'string' && value !== '').slice(0, 100) : []
|
|
353
|
+
const files = {}
|
|
354
|
+
for (const path of paths) {
|
|
355
|
+
try {
|
|
356
|
+
const absolute = await resolveProjectPath(root, path)
|
|
357
|
+
const info = await stat(absolute)
|
|
358
|
+
files[path] = { mtimeMs: info.mtimeMs, size: info.size, missing: false }
|
|
359
|
+
} catch {
|
|
360
|
+
files[path] = { missing: true }
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return { files }
|
|
364
|
+
})
|
|
365
|
+
|
|
349
366
|
router.method('fs.read', async (body) => {
|
|
350
367
|
const root = await projectOf(env, body)
|
|
351
368
|
const absolute = await resolveProjectPath(root, body.path)
|
package/package.json
CHANGED
|
@@ -126,6 +126,13 @@ try {
|
|
|
126
126
|
['.babelrc', 'json'], ['.gitconfig', 'ini'],
|
|
127
127
|
]
|
|
128
128
|
for (const [file, expected] of languageCases) check(`languageOf ${file} -> ${expected}`, fs.languageOf(file) === expected, fs.languageOf(file))
|
|
129
|
+
console.log('fs.mtimes')
|
|
130
|
+
const mtimes = await call(router, 'fs.mtimes', { root, paths: ['src/main.ts', 'missing-file.txt'] })
|
|
131
|
+
check('fs.mtimes returns mtime/size', typeof mtimes.files['src/main.ts']?.mtimeMs === 'number' && mtimes.files['src/main.ts']?.size > 0)
|
|
132
|
+
check('fs.mtimes marks missing file', mtimes.files['missing-file.txt']?.missing === true)
|
|
133
|
+
const missingMtimes = await call(router, 'fs.mtimes', { root, paths: [] })
|
|
134
|
+
check('fs.mtimes handles empty list', missingMtimes.files !== null && typeof missingMtimes.files === 'object' && Object.keys(missingMtimes.files).length === 0)
|
|
135
|
+
|
|
129
136
|
console.log('fs.search')
|
|
130
137
|
await call(router, 'fs.create', { root, path: 'search.txt', kind: 'file' })
|
|
131
138
|
await call(router, 'fs.write', { root, path: 'search.txt', content: 'Alpha beta\nBETA gamma\nbeta BETA\n' })
|
package/src/client/20-editor.js
CHANGED
|
@@ -1228,6 +1228,53 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
1228
1228
|
/* ignore */
|
|
1229
1229
|
}
|
|
1230
1230
|
|
|
1231
|
+
/* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容 */
|
|
1232
|
+
try {
|
|
1233
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
1234
|
+
const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
|
|
1235
|
+
if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
|
|
1236
|
+
const target = modelsRef.current.get(detail.path)
|
|
1237
|
+
if (target === null || target === undefined) return
|
|
1238
|
+
let content = ''
|
|
1239
|
+
try {
|
|
1240
|
+
content = target.getValue()
|
|
1241
|
+
} catch {
|
|
1242
|
+
return
|
|
1243
|
+
}
|
|
1244
|
+
if (content === detail.content) return
|
|
1245
|
+
const active = modelPathRef.current === detail.path
|
|
1246
|
+
let position = null
|
|
1247
|
+
let scrollTop = 0
|
|
1248
|
+
if (active) {
|
|
1249
|
+
try {
|
|
1250
|
+
position = instance.getPosition()
|
|
1251
|
+
scrollTop = instance.getScrollTop()
|
|
1252
|
+
} catch {
|
|
1253
|
+
position = null
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
suppressChangeRef.current = true
|
|
1257
|
+
try {
|
|
1258
|
+
target.setValue(detail.content)
|
|
1259
|
+
} finally {
|
|
1260
|
+
suppressChangeRef.current = false
|
|
1261
|
+
}
|
|
1262
|
+
lastPropContentRef.current.set(detail.path, detail.content)
|
|
1263
|
+
if (active && position !== null && position !== undefined) {
|
|
1264
|
+
try {
|
|
1265
|
+
instance.setPosition(position)
|
|
1266
|
+
instance.setScrollTop(scrollTop)
|
|
1267
|
+
} catch {
|
|
1268
|
+
/* ignore */
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
})
|
|
1272
|
+
if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
|
|
1273
|
+
}
|
|
1274
|
+
} catch {
|
|
1275
|
+
/* ignore */
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1231
1278
|
G.__gufaEditorDebug = {
|
|
1232
1279
|
focus: () => {
|
|
1233
1280
|
try {
|
package/src/client/90-app.js
CHANGED
|
@@ -255,6 +255,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
255
255
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
256
256
|
const editorBuffersRef = useRef(new Map())
|
|
257
257
|
const tabsRef = useRef([])
|
|
258
|
+
const reloadTabFromDiskRef = useRef(null)
|
|
258
259
|
const flushTimerRef = useRef(null)
|
|
259
260
|
const selectionTimerRef = useRef(null)
|
|
260
261
|
const pendingSelectionRef = useRef(null)
|
|
@@ -481,6 +482,12 @@ G.GufaApp = function GufaApp(props) {
|
|
|
481
482
|
flushBuffersRef.current?.()
|
|
482
483
|
const existing = tabs.find((tab) => tab.path === path)
|
|
483
484
|
if (existing !== undefined) {
|
|
485
|
+
/* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
|
|
486
|
+
try {
|
|
487
|
+
await reloadTabFromDiskRef.current?.(path)
|
|
488
|
+
} catch {
|
|
489
|
+
/* ignore */
|
|
490
|
+
}
|
|
484
491
|
setActivePath(path)
|
|
485
492
|
return
|
|
486
493
|
}
|
|
@@ -567,6 +574,84 @@ G.GufaApp = function GufaApp(props) {
|
|
|
567
574
|
})
|
|
568
575
|
}, [])
|
|
569
576
|
|
|
577
|
+
/* 把某个已打开标签重新对齐磁盘内容(AI/外部修改检测、点击文件树时使用)。
|
|
578
|
+
有未保存修改(dirty)时绝不覆盖用户内容。 */
|
|
579
|
+
const reloadTabFromDisk = useCallback(async (path) => {
|
|
580
|
+
if (project === null) return false
|
|
581
|
+
const tab = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
|
|
582
|
+
if (tab === undefined || tab.kind === 'diff' || tab.kind === 'graph') return false
|
|
583
|
+
try {
|
|
584
|
+
const doc = await G.api('fs.read', { root: project.root, path })
|
|
585
|
+
const latest = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
|
|
586
|
+
if (latest === undefined || latest.dirty === true) return false
|
|
587
|
+
if (latest.revision === doc.revision && latest.content === doc.content) return false
|
|
588
|
+
editorBuffersRef.current.delete(path)
|
|
589
|
+
patchTab(path, {
|
|
590
|
+
content: doc.content,
|
|
591
|
+
revision: doc.revision,
|
|
592
|
+
savedRevision: doc.revision,
|
|
593
|
+
savedContent: doc.content,
|
|
594
|
+
dirty: false,
|
|
595
|
+
size: doc.size,
|
|
596
|
+
mtimeMs: doc.mtimeMs,
|
|
597
|
+
})
|
|
598
|
+
try {
|
|
599
|
+
G.bus.emit('editor:external-reload', { path, content: doc.content })
|
|
600
|
+
} catch {
|
|
601
|
+
/* ignore */
|
|
602
|
+
}
|
|
603
|
+
return true
|
|
604
|
+
} catch {
|
|
605
|
+
return false
|
|
606
|
+
}
|
|
607
|
+
}, [project, patchTab])
|
|
608
|
+
reloadTabFromDiskRef.current = reloadTabFromDisk
|
|
609
|
+
|
|
610
|
+
/* AI/外部进程修改磁盘文件:轮询已打开且未修改的标签,自动同步编辑器和标签内容。
|
|
611
|
+
1.6s 一次 fs.mtimes(只 stat),发现 mtime/size 变化才 fs.read 全文。 */
|
|
612
|
+
useEffect(() => {
|
|
613
|
+
if (project === null) return undefined
|
|
614
|
+
let cancelled = false
|
|
615
|
+
let busy = false
|
|
616
|
+
const sync = async () => {
|
|
617
|
+
if (busy || cancelled || document.visibilityState !== 'visible') return
|
|
618
|
+
busy = true
|
|
619
|
+
try {
|
|
620
|
+
const open = (tabsRef.current ?? []).filter((tab) => tab !== null && tab !== undefined
|
|
621
|
+
&& typeof tab.path === 'string' && tab.kind !== 'diff' && tab.kind !== 'graph')
|
|
622
|
+
const clean = open.filter((tab) => tab.dirty !== true).slice(0, 24)
|
|
623
|
+
if (clean.length === 0) return
|
|
624
|
+
let result = null
|
|
625
|
+
try {
|
|
626
|
+
result = await G.api('fs.mtimes', { root: project.root, paths: clean.map((tab) => tab.path) })
|
|
627
|
+
} catch {
|
|
628
|
+
return
|
|
629
|
+
}
|
|
630
|
+
const files = result !== null && result !== undefined && result.files !== null && result.files !== undefined ? result.files : {}
|
|
631
|
+
for (const tab of clean) {
|
|
632
|
+
if (cancelled) break
|
|
633
|
+
const info = files[tab.path]
|
|
634
|
+
if (info === null || info === undefined || info.missing === true) continue
|
|
635
|
+
if (Number(info.mtimeMs) === Number(tab.mtimeMs) && Number(info.size) === Number(tab.size)) continue
|
|
636
|
+
await reloadTabFromDisk(tab.path)
|
|
637
|
+
}
|
|
638
|
+
} finally {
|
|
639
|
+
busy = false
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const timer = window.setInterval(() => { void sync() }, 1600)
|
|
643
|
+
const onVisible = () => { if (document.visibilityState === 'visible') void sync() }
|
|
644
|
+
window.addEventListener('focus', onVisible)
|
|
645
|
+
document.addEventListener('visibilitychange', onVisible)
|
|
646
|
+
void sync()
|
|
647
|
+
return () => {
|
|
648
|
+
cancelled = true
|
|
649
|
+
window.clearInterval(timer)
|
|
650
|
+
window.removeEventListener('focus', onVisible)
|
|
651
|
+
document.removeEventListener('visibilitychange', onVisible)
|
|
652
|
+
}
|
|
653
|
+
}, [project, reloadTabFromDisk])
|
|
654
|
+
|
|
570
655
|
/* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
|
|
571
656
|
const flushEditorBuffers = useCallback(() => {
|
|
572
657
|
const buffers = editorBuffersRef.current
|
|
@@ -1290,6 +1375,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1290
1375
|
const consumeExitStateRef = useRef(false)
|
|
1291
1376
|
useEffect(() => {
|
|
1292
1377
|
if (G.isFloatMode()) return undefined
|
|
1378
|
+
if (G.instanceBoot === true) return undefined
|
|
1293
1379
|
let running = false
|
|
1294
1380
|
const consume = async () => {
|
|
1295
1381
|
if (running) return
|
|
@@ -1447,6 +1533,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1447
1533
|
const entryWorkspaceSyncedRef = useRef(false)
|
|
1448
1534
|
useEffect(() => {
|
|
1449
1535
|
if (entryWorkspaceSyncedRef.current) return
|
|
1536
|
+
/* 实例窗口:保持空工作区,不跟随主窗口/DSH 当前会话自动打开项目 */
|
|
1537
|
+
if (G.instanceBoot === true) {
|
|
1538
|
+
entryWorkspaceSyncedRef.current = true
|
|
1539
|
+
return
|
|
1540
|
+
}
|
|
1450
1541
|
/* 悬浮层(摸鱼):项目/会话由主窗口状态注入,不做「入口工作区」同步 */
|
|
1451
1542
|
if (G.isFloatMode()) {
|
|
1452
1543
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -1771,6 +1862,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1771
1862
|
const lastSessionCwdRef = useRef(null)
|
|
1772
1863
|
useEffect(() => {
|
|
1773
1864
|
if (sessionPinnedRef.current === true) return
|
|
1865
|
+
/* 实例窗口:不跟随会话 cwd 自动打开项目 */
|
|
1866
|
+
if (G.instanceBoot === true) {
|
|
1867
|
+
lastSessionCwdRef.current = sessionCwd
|
|
1868
|
+
return
|
|
1869
|
+
}
|
|
1774
1870
|
/* 悬浮层里项目由主窗口状态注入,不跟随(Web 版客户端自己的)会话 cwd 切换 */
|
|
1775
1871
|
if (G.isFloatMode()) {
|
|
1776
1872
|
lastSessionCwdRef.current = sessionCwd
|