Skip to content

fix(desktop): 允许关闭虚拟或干净文档并跳过工作区外最近文件记录 - #2099

Merged
1lck merged 1 commit into
mainfrom
fix/virtual-external-document-close
Nov 17, 2026
Merged

1lck merged 1 commit into
mainfrom
fix/virtual-external-document-close

Conversation

@1lck

@1lck 1lck commented Nov 17, 2026

Copy link
Copy Markdown
Owner

关联 Issue / Linked issue

  • 无(用户反馈在 Windows 上打开外部依赖/反编译类文件时弹出 SpringApplication.java: 无法检查文件的外部变化 且编辑标签页与窗口无法关闭,诊断日志同时记录了跨盘符调用 filepath.Rel 导致的 editor_recent failed)

PR 类型 / Type

  • feat:新功能或用户可见的改进
  • fix:缺陷修复
  • docs:文档、Agent Note、Skill 等规则文件
  • release:稳定版发布准备

改动说明 / What changes

背景 / Why

在 Windows 上跳转到外部依赖或虚拟源码类文件时存在两个关联缺陷:

  1. 虚拟文档及外部读取失败文档无法关闭:
    • 关闭标签页或项目时,saveBeforeClose 只跳过了 d.scratch,没有跳过 d.virtual,因此仍调用 checkBeforeClose → scheduleDocumentChecks 对虚拟 URI 执行本地磁盘读取,引发 desktop.document.externalReadFailed 并置位 d.checkFailed = true 阻塞关闭。
    • unwatchDocument、drainDocumentWatch、scheduleDocumentChecks 与 saveProjectPass 也未全面跳过 d.virtual。
    • 对非虚拟的干净文档(!d.dirty() && !d.view.IsComposing() && !d.conflicted),只要磁盘读取检查报非 os.ErrNotExist 错误(d.checkFailed = true),scheduleDocumentChecks 也会无条件向 checkWaiters 回调 done(false),导致无未保存修改的标签页和 IDE 窗口被锁死无法关闭。
  2. 工作区外文件触发最近文件报错:
    • noteRecentFile 直接调用 filepath.Rel(p.root, d.path);当工作区位于 D: 盘而插件解压的只读依赖源码位于 C: 盘(AppData\Local)时,filepath.Rel 跨盘符必定失败并弹出 editor_recent failed(同盘符工作区外路径也会把 ../... 写入最近文件记录)。
    • 同时,openFile / openFileAt / openFileAtPosition / openStepDestination 未对传入路径做 filepath.Clean,在 Windows 上来自 URI 解码的斜杠路径可能导致位置映射键不一致。

改动 / Changes

  • desktop/internal/workbench/documents.go
    • openFile、openFileAt、openFileAtPosition 入口拦截空路径并执行 filepath.Clean(path)。
    • saveBeforeClose 对 d.virtual 直接回调 done(true) 返回,不再触发 checkBeforeClose。
    • saveProjectPass 在遍历未校验文档时跳过 candidate.virtual。
  • desktop/internal/workbench/navigation_history.go
    • openStepDestination 先对 destination.Document 执行 filepath.Clean,与 openFile 和 p.docs.locations 键保持一致。
  • desktop/internal/workbench/document_observation.go
    • unwatchDocument、drainDocumentWatch 忽略 d.virtual。
    • scheduleDocumentChecks 跳过 d.virtual 文档的磁盘检查,并在循环结束后释放其挂起的 checkWaiters(done(true))。
    • scheduleDocumentChecks 后台校验回调仅在 d.conflicted(含已删除文件的 conflictMissing 保护)或 (d.dirty() || d.view.IsComposing()) && d.checkFailed 时拒绝关闭(done(false));干净且未冲突的文档不因 d.checkFailed 阻断关闭。
  • desktop/internal/workbench/recent_files.go
    • noteRecentFile 改用 projectRelative(p.root, d.path);位于工作区外的文档直接返回,不写入最近文件也不触发 recentFailed。
  • desktop/internal/workbench/document_observation_test.go
    • 新增 TestVirtualDocumentClosesWithoutExternalCheckOrError、TestCleanDocumentClosesWhenExternalReadFails。
  • desktop/internal/workbench/editor_essentials_test.go
    • 新增 TestEditorEssentialsOutsideProjectFileDoesNotFailRecentFiles。
  • shared/platform-feature-matrix/features/workspace-document-sync.json、shared/platform-feature-matrix/features/editor-recent-files.json
    • 补充上述行为说明与回归测试证据路径(verificationStatus 保持 pending)。

不在本 PR 范围内 / Out of scope

  • 无

类型专属:fix

复现与根因

  • 复现步骤、实际结果、期望结果:
    1. 打开项目(例如 Windows 下 D: 盘工程),通过虚拟文档打开 .class URI(如 jdt://...)或使一个干净本地文件的后台外部读取检查失败,随后点击关闭标签页或关闭项目;修复前会提示 无法检查文件的外部变化。 且标签页/项目无法关闭;修复后虚拟文档跳过磁盘读取并正常关闭,干净未冲突文档不受读取失败锁死(已删除文档和带未保存改动的脏文档仍受保护)。
    2. 在当前项目外(模拟跨盘符依赖源码目录)打开文件;修复前会将 ../... 路径记入最近文件(在 Windows 跨盘符时触发 filepath.Rel 错误);修复后静默跳过且不污染最近文件列表。
  • 根因(引入该行为的提交或 PR,用 git log -S 查):
  • 影响平台:桌面端全平台(macOS / Windows / Linux 共用 Viva desktop/internal/workbench)。

检查项

  • 已先写回归测试,确认它在修复前失败、修复后通过;测试路径与修复前的失败输出:
    • desktop/internal/workbench/document_observation_test.go(TestVirtualDocumentClosesWithoutExternalCheckOrError 修复前输出 virtual document ran disk check: readCalls=1 checkFailed=true;TestCleanDocumentClosesWhenExternalReadFails 修复前输出 clean document could not be closed after external read error; notice="clean.txt: 无法检查文件的外部变化。")
    • desktop/internal/workbench/editor_essentials_test.go(TestEditorEssentialsOutsideProjectFileDoesNotFailRecentFiles 修复前输出 outside file leaked into recent files)
  • [N/A] 无法自动化时,已写明手动复现与验证步骤:已通过上述自动化回归测试覆盖。
  • 已搜索被修改函数、类型、契约字段的全部调用方:openFile / openFileAt / openFileAtPosition、openStepDestination、saveBeforeClose、saveProjectPass、noteRecentFile、unwatchDocument、drainDocumentWatch、scheduleDocumentChecks 的所有工作台调用方均已核对;p.docs.opening 与 p.docs.locations 全部读写点已检查。
  • 已检查另一平台是否有同类缺陷:macOS / Windows / Linux 共用同一份 Go desktop/internal/workbench 实现,一并修复。
  • 只改了修复所需的代码,没有夹带重构。
  • [N/A] 修复改变了行为约束或容易复发,已在 .agents/notes/implemented/bug-fix/ 记录:.agents/notes/implemented/bug-fix/2026-09-15-external-document-changes-and-guarded-save.md 已记录“文件被删除时保留内容”和“虚拟文档不套用本地文件保证”约束,本次实现是使代码符合既有约束。

范围检查 / Scope checks

功能矩阵 / Feature matrix

  • 已更新 shared/platform-feature-matrix/features/workspace-document-sync.json 与 shared/platform-feature-matrix/features/editor-recent-files.json 的说明与测试证据,Windows 验证状态仍保持 pending。
  • 已运行 node scripts/platform-feature-matrix/generate-platform-feature-matrix.mjs、./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh(197 项通过)与 ./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD。
  • 没有提交 .artifacts/ 下生成的矩阵视图。
  • [N/A] 没有更新矩阵的理由:已同步更新受影响的功能矩阵条目。

插件归属 / Plugin ownership

  • 已在仓库根目录运行 develop-lithe 第三节自查命令,结果为空。
  • 新增测试仅使用测试构造的临时文件及通用 URI scheme,未读取具体插件包、检出或真实插件 ID。
  • 没有为具体插件新建或更新宿主功能矩阵条目。
  • 插件文案与资源说明未进入 shared/i18n/、docs/ci-builds.md、Agent Note 或 Skill。
  • [N/A] 修改了通用扩展点、可能影响已发布插件的,已在受影响插件的仓库运行它的测试:未修改插件扩展点或协议。

UI 验证 / UI evidence

N/A:纯桌面工作台文档生命周期与路径处理逻辑修复,无布局、控件、样式或文案改动。

统一日志系统 / Structured logging

N/A:未新增、修改或删除日志事件、字段或级别;保留既有 editor.document.open_failed 与 app.notification.operation_failed 目录事件。

界面文案 / i18n

  • 未新增或修改用户可见文案,仍复用共享 i18n。
  • 插件文案未写入 shared/i18n/。
  • 已运行 node scripts/i18n/verify-app-language-localization.mjs 与 node scripts/i18n/generate-i18n.mjs --check(11412/11412 通过)。

逻辑归属 / Logic placement

  • 修改均位于宿主平台文件系统/路径适配与原生文档监听生命周期边界:projectRelative 封装 OS filepath.Rel / filepath.IsAbs、filepath.Clean 处理原生路径分隔符、document_observation.go / documents.go 编排原生目录监听与 editorview 关闭异步回调;共享文档状态转移仍由 Core document.lifecycle 与 editor.recent 负责。
  • [N/A] 修改平台层已有的可共享逻辑时已迁入 Core:本次未修改可共享纯规则。
  • 宿主和 Core 未按工具或插件名增加分支。

性能与内存 / Performance and memory

N/A:未新增后台线程、缓存、队列或轮询;虚拟文档与工作区外最近文件改为提前返回,反而减少了无效后台 I/O。

设置 / Settings

N/A:未涉及设置项、设置页或工具配置读写。

插件契约 / Plugin contract

N/A:未涉及 Rust Core 插件契约、能力版本或宿主方法。

发行包与资源 / Bundle and resources

N/A:未新增或修改运行时资源、缓存、下载物或打包步骤。

无用代码与重构 / Dead code and refactoring

  • 本次改动未产生新的无用代码。
  • 未顺手处理无关重构。

验证 / Verification

命令或操作 平台 结果
./scripts/desktop/desktop-go.sh vet ./internal/workbench macOS (arm64) 通过
./scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestVirtualDocumentClosesWithoutExternalCheckOrError|TestCleanDocumentClosesWhenExternalReadFails|TestEditorEssentialsOutsideProjectFileDoesNotFailRecentFiles' macOS (arm64) 通过(1.940s)
./.agents/skills/write-stable-tests/scripts/test-stability-macos.sh --package ./internal/workbench -- --filter 'TestVirtualDocumentClosesWithoutExternalCheckOrError|TestCleanDocumentClosesWhenExternalReadFails|TestEditorEssentialsOutsideProjectFileDoesNotFailRecentFiles' macOS (arm64) 通过(310 ms / 50 ms / 80 ms)
./scripts/desktop/desktop-go.sh test ./internal/workbench macOS (arm64) 通过(214.234s)
./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/main macOS (arm64) 通过
node scripts/i18n/verify-app-language-localization.mjs && node scripts/i18n/generate-i18n.mjs --check macOS (arm64) 通过(11412/11412)
./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh && ./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD macOS (arm64) 通过(197 项)
插件零依赖 rg 自查 macOS (arm64) 通过(结果为空)

未能执行的检查和原因:

  • 变基 origin/main(05f9958a7)前曾运行全包 ./scripts/desktop/desktop-go.sh test ./...(除既有的 internal/localshell bash 终端挂断两条测试失败外全部通过)与 ./scripts/desktop/desktop-go.sh test -race ./internal/workbench(通过,305.556s);变基后仅补充了 navigation_history.go 的 filepath.Clean 与功能矩阵 JSON,并在新基线上运行了 vet、test ./internal/workbench 与稳定性计时检查。
  • Windows 原生跨盘符跳转与窗口关闭实机验证未在本机执行(当前为 macOS 环境)。

提交前确认 / Final checks

  • 分支从最新的 main 创建;目标分支:main
  • 以 Draft 提交,本地验证通过后标记 ready
  • 没有无关改动,没有提交 .build/、target/、dist/、.artifacts/ 等产物,没有凭据、个人路径和未脱敏的日志或截图
  • 本次构建、测试启动的子进程已全部关闭,无 Lithe 进程残留

@1lck
1lck marked this pull request as ready for review November 17, 2026 10:25
@1lck
1lck requested a review from xiaoyumuxi as a code owner November 17, 2026 10:25
@ghfind-review ghfind-review Bot added the review: high ghfind author score; see https://ghfind.com label Nov 17, 2026
@1lck
1lck requested a review from Mucheen as a code owner November 17, 2026 10:25
@1lck
1lck force-pushed the fix/virtual-external-document-close branch from 33ecd32 to e121889 Compare November 17, 2026 10:38
@1lck
1lck merged commit b16a1bf into main Nov 17, 2026
5 of 6 checks passed
@1lck
1lck deleted the fix/virtual-external-document-close branch November 17, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: high ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant