Repository navigation
feat(editor): add dot-notation path intellisense for sync registry - #205
Conversation
Summary of ChangesHello @xxMudCloudxx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求通过为 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
cf35b32 to
9b46657
Compare
There was a problem hiding this comment.
Code Review
本次 PR 为 SyncRegistry 引入了类型安全的点语法路径,极大地改善了开发体验,值得称赞。整体实现非常巧妙,特别是利用了 TypeScript 的高级类型,并且配备了完善的类型测试。
我发现了几处可以改进的地方:
- 项目中似乎存在一个重复未使用的类型文件
src/types/utils.ts,建议移除。 src/utils/types.ts中的Prev类型在处理超过 5 的递归深度时行为可能不符合预期。- 同样在
src/utils/types.ts中,Join类型在处理空字符串键时存在一个 bug。
我在具体文件中留下了详细的建议。
I am having trouble creating individual review comments. Click here to see my feedback.
src/utils/types.ts (30-34)
Join 类型的实现在处理空字符串键时存在一个 bug。例如,对于路径 'a.'(代表对象 a 下的空字符串键 ''),Join<'a', ''> 应该生成 'a.',但当前的实现会错误地生成 'a'。当路径的子部分是包含 '' 的联合类型时,这个问题会更严重。建议简化 Join 的实现,以正确处理所有情况。
type Join<K, P> = K extends string | number
? P extends string | number
? `${K}.${P}`
: never
: never;
src/types/utils.ts (1-53)
这个文件 src/types/utils.ts 的内容似乎与 src/utils/types.ts 基本重复,并且项目中的所有相关导入都指向了 src/utils/types.ts。为了保持代码库的整洁和避免混淆,建议将这个未使用的文件删除。
src/utils/types.ts (15)
Prev 类型的定义 [never, 0, 1, 2, 3, 4, 5, ...0[]] 存在一个问题:当递归深度 D 大于 5 时,Prev[D] 会被解析为 0,这会导致实际的递归深度只有两层(例如 D=6 时,路径为 6 -> 0 -> never),可能不符合预期。建议将元组扩展到一个更合理的固定长度,以支持更深的嵌套,并移除容易引起误解的 ...0[]。
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
/gemini review |
There was a problem hiding this comment.
Code Review
这个 PR 引入了一个��常有用的功能:为 SyncRegistry 提供了类型安全的路径,通过智能提示和防止拼写错误,极大地改善了开发体验。使用 TypeScript 高级条件类型的实现令人印象深刻,并且结构良好。为类型辅助工具添加了 vitest 和 expectTypeOf 的单元测试,这是一个很好的实践,确保了这些复杂类型的正确性。
这些更改在接口和实现中得到了一致的应用。InfographicOptionPath | (string & {}) 的用法是一种聪明且标准的方式,可以同时实现类型安全和灵活性。
我发现 Prev 辅助类型中存在一个潜在问题,当对象结构更深时可能导致不正确的行为。我的反馈中包含了修复建议。总的来说,这是一次高质量的贡献。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #205 +/- ##
==========================================
+ Coverage 45.95% 46.18% +0.23%
==========================================
Files 338 338
Lines 27047 27048 +1
Branches 2202 2221 +19
==========================================
+ Hits 12430 12493 +63
+ Misses 14606 14544 -62
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…ntvis#205) * feat: add dot-notation path intellisense for sync registry * test: add unit tests for Path type * fix: lint error * fix: improve Prev
📝 背景与目的 (Background)
之前的
SyncRegistry在注册同步路径时仅使用普通的string类型,这导致开发者在编写代码时容易拼写错误,且无法获得 IDE 的智能提示。本 PR 旨在引入类型安全的路径生成工具,为
SyncRegistry提供基于InfographicOptions的点语法路径自动补全功能,同时保持对任意字符串路径的兼容性。🛠️ 主要改动 (Changes)
新增类型工具:
src/types/utils.ts中新增了Path<T>、Join、Prev等泛型工具,用于递归生成对象的点语法路径(如design.structure)。src/types/index.ts中导出了这些工具。更新 Options 类型:
src/options/types.ts中,使用新工具定义了InfographicOptionPath类型。ValidKey过滤)。升级编辑器接口:
ISyncRegistry(src/editor/types/sync.ts) 和IEditor(src/editor/types/editor.ts) 接口。register方法的path参数类型修改为InfographicOptionPath | (string & {})。重构与之相关的实现:
SyncRegistry类 (src/editor/managers/sync-registry.ts) 以匹配新的接口定义。