Skip to content

feat(editor): add dot-notation path intellisense for sync registry - #205

Merged
Aarebecca merged 4 commits into
antvis:mainfrom
xxMudCloudxx:feat/sync-path-intellisense
Feb 25, 2026
Merged

Aarebecca merged 4 commits into
antvis:mainfrom
xxMudCloudxx:feat/sync-path-intellisense

Conversation

@xxMudCloudxx

Copy link
Copy Markdown
Contributor

📝 背景与目的 (Background)

之前的 SyncRegistry 在注册同步路径时仅使用普通的 string 类型,这导致开发者在编写代码时容易拼写错误,且无法获得 IDE 的智能提示。

本 PR 旨在引入类型安全的路径生成工具,为 SyncRegistry 提供基于 InfographicOptions 的点语法路径自动补全功能,同时保持对任意字符串路径的兼容性。

🛠️ 主要改动 (Changes)

  1. 新增类型工具:

    • 在 src/types/utils.ts 中新增了 Path<T>、Join、Prev 等泛型工具,用于递归生成对象的点语法路径(如 design.structure)。
    • 并在 src/types/index.ts 中导出了这些工具。
  2. 更新 Options 类型:

    • 在 src/options/types.ts 中,使用新工具定义了 InfographicOptionPath 类型。
    • 修复了之前的类型定义在递归过深或处理索引签名时可能导致的 TS 错误(通过 ValidKey 过滤)。
  3. 升级编辑器接口:

    • 更新 ISyncRegistry (src/editor/types/sync.ts) 和 IEditor (src/editor/types/editor.ts) 接口。
    • 将 register 方法的 path 参数类型修改为 InfographicOptionPath | (string & {})。
    • 这种写法既能提供智能提示,又通过 Hack 方式兼容了动态字符串路径。
  4. 重构与之相关的实现:

    • 更新了 SyncRegistry 类 (src/editor/managers/sync-registry.ts) 以匹配新的接口定义。
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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!

此拉取请求通过为 InfographicOptions 引入类型安全的点语法路径智能提示,增强了 SyncRegistry 的功能。此前,SyncRegistry 仅接受普通字符串作为路径,这容易导致拼写错误并缺乏 IDE 支持。本次更改引入了泛型类型工具来递归生成对象路径,更新了相关的接口和实现以利用这些新类型,并确保了与动态字符串路径的向后兼容性。这显著改善了开发人员体验,通过提供智能代码补全和减少配置路径错误。

Highlights

  • 新增类型工具: 在 src/utils/types.ts 中新增了 Path<T>、Join、Prev 等泛型工具,用于递归生成对象的点语法路径,并从 src/utils/index.ts 导出。
  • 更新选项类型: 在 src/options/types.ts 中,使用新工具定义了 InfographicOptionPath 类型,并修复了深层递归或索引签名可能导致的 TypeScript 错误。
  • 升级编辑器接口: 更新了 ISyncRegistry 和 IEditor 接口,将 register 方法的 path 参数类型修改为 InfographicOptionPath | (string & {}),以提供智能提示并兼容动态字符串路径。
  • 重构相关实现: 更新了 SyncRegistry 类以匹配新的接口定义。
  • 新增测试文件: 添加了 __tests__/unit/utils/types.test.ts,用于测试 Path 类型工具的各种场景。
Changelog
  • tests/unit/utils/types.test.ts
    • 新增了 Path 类型工具的单元测试文件。
  • src/editor/managers/sync-registry.ts
    • 导入了 InfographicOptionPath 并更新了 register 方法的 path 参数类型。
  • src/editor/types/editor.ts
    • 导入了 InfographicOptionPath 并更新了 registerSync 方法的 path 参数类型。
  • src/editor/types/sync.ts
    • 导入了 InfographicOptionPath 并更新了 ISyncRegistry 接口中 register 方法的 path 参数类型。
  • src/options/types.ts
    • 导入了 Path 类型工具并定义了新的 InfographicOptionPath 类型,用于生成信息图选项的类型安全路径。
  • src/utils/index.ts
    • 导出了 src/utils/types.ts 中新增的类型工具。
  • src/utils/types.ts
    • 新增了 Prev、StopType、Join、ValidKey 和 Path 等泛型类型工具,用于递归生成对象的点语法路径。
Activity
  • 拉取请求的作者提供了详细的背景和主要改动说明。
  • 新增了专门的测试文件,表明对新类型工具的实现进行了验证。
  • 目前没有其他评论或审查活动。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@xxMudCloudxx
xxMudCloudxx force-pushed the feat/sync-path-intellisense branch from cf35b32 to 9b46657 Compare February 15, 2026 00:10
@xxMudCloudxx xxMudCloudxx reopened this Feb 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 为 SyncRegistry 引入了类型安全的点语法路径,极大地改善了开发体验,值得称赞。整体实现非常巧妙,特别是利用了 TypeScript 的高级类型,并且配备了完善的类型测试。

我发现了几处可以改进的地方:

  1. 项目中似乎存在一个重复未使用的类型文件 src/types/utils.ts,建议移除。
  2. src/utils/types.ts 中的 Prev 类型在处理超过 5 的递归深度时行为可能不符合预期。
  3. 同样在 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)

high

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)

medium

这个文件 src/types/utils.ts 的内容似乎与 src/utils/types.ts 基本重复,并且项目中的所有相关导入都指向了 src/utils/types.ts。为了保持代码库的整洁和避免混淆,建议将这个未使用的文件删除。

src/utils/types.ts (15)

medium

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];
@xxMudCloudxx

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

这个 PR 引入了一个��常有用的功能:为 SyncRegistry 提供了类型安全的路径,通过智能提示和防止拼写错误,极大地改善了开发体验。使用 TypeScript 高级条件类型的实现令人印象深刻,并且结构良好。为类型辅助工具添加了 vitest 和 expectTypeOf 的单元测试,这是一个很好的实践,确保了这些复杂类型的正确性。

这些更改在接口和实现中得到了一致的应用。InfographicOptionPath | (string & {}) 的用法是一种聪明且标准的方式,可以同时实现类型安全和灵活性。

我发现 Prev 辅助类型中存在一个潜在问题,当对象结构更深时可能导致不正确的行为。我的反馈中包含了修复建议。总的来说,这是一次高质量的贡献。

Comment thread src/utils/types.ts Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.18%. Comparing base (d03fde1) to head (6de1fde).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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              
Flag Coverage Δ
infographic 46.18% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/editor/managers/sync-registry.ts 100.00% <100.00%> (ø)
src/editor/types/editor.ts 100.00% <100.00%> (ø)
src/editor/types/sync.ts 100.00% <100.00%> (ø)
src/options/types.ts 100.00% <ø> (ø)
src/utils/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@Aarebecca
Aarebecca merged commit a41681b into antvis:main Feb 25, 2026
1 check passed
Aarebecca pushed a commit to xxMudCloudxx/Infographic that referenced this pull request Feb 25, 2026
…ntvis#205)

* feat: add dot-notation path intellisense for sync registry

* test: add unit tests for Path type

* fix: lint error

* fix: improve Prev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants