Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Apr 2, 2025

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

  • 新增功能
    • 集成实时拼写检查功能,在编辑器中自动检测并标记拼写错误。
    • 引入后台处理支持,通过远程处理实现平稳、高效的拼写检测。

@weareoutman weareoutman requested a review from Copilot April 2, 2025 02:17
@coderabbitai
Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

本次提交新增了拼写检查相关的功能。首先,在 packages/brick-playground/package.json 中添加了两个新的依赖项:@next-shared/spell-checkcomlink。接着,在 src/index.ts 中整合了拼写检查逻辑,包括新增常量、创建异步拼写检查函数以及调整 debounce 函数的位置,以在内容发生变化时触发拼写检查。最后,新增了两个文件,用于实现和管理远程拼写检查工作者,利用 comlink 暴露和封装跨线程调用的功能。

Changes

文件 更改摘要
packages/brick-playground/package.json dependencies 中新增依赖项 @next-shared/spell-check (^0.1.1) 和 comlink (^4.4.2)
packages/brick-playground/src/index.ts 新增拼写检查逻辑:添加 SPELL_CHECKKNOWN_WORDS 常量、创建 debouncedSpellCheck 异步函数,并移动 debounce 函数位置,同时在内容变化事件中调用拼写检查
packages/brick-playground/src/spellCheck.worker.ts,
packages/brick-playground/src/spellCheckRemoteWorker.ts
新增实现远程拼写检查工作者的功能:在 spellCheck.worker.ts 中新增 SpellCheckWorker 类及其 spellCheck 方法;在 spellCheckRemoteWorker.ts 中新增 RemoteSpellCheckWorker 接口和 getRemoteSpellCheckWorkergetWorker 函数,用于封装远程工人管理与通信

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/brick-playground/src/index.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

packages/brick-playground/src/spellCheck.worker.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

packages/brick-playground/src/spellCheckRemoteWorker.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for spell checking in the playground by integrating a remote spell check web worker via Comlink. Key changes include:

  • Adding a remote worker wrapper in spellCheckRemoteWorker.ts to initialize and cache the worker.
  • Implementing spell check logic within spellCheck.worker.ts.
  • Integrating spell check and a debounced trigger into the main editor in index.ts.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
packages/brick-playground/src/spellCheckRemoteWorker.ts Adds a remote worker wrapper for handling spell check requests
packages/brick-playground/src/spellCheck.worker.ts Implements the worker that executes the spell check function
packages/brick-playground/src/index.ts Integrates the remote spell check and debounced spell checking within the editor
Files not reviewed (1)
  • packages/brick-playground/package.json: Language not supported
Comments suppressed due to low confidence (1)

packages/brick-playground/src/index.ts:15

  • The import is referencing a .js file, but the actual file is a TypeScript file. Consider updating the import to use the correct extension or adjusting the module resolution configuration.
import { getRemoteSpellCheckWorker } from "./spellCheckRemoteWorker.js";

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/brick-playground/src/index.ts (2)

23-37: 已知词汇列表设计合理

常量 KNOWN_WORDS 包含了一系列不应被拼写检查器标记为错误的技术术语和专有名词。这是一个很好的做法,可以减少误报。随着项目发展,可能需要定期更新此列表。考虑将此列表移至配置文件或单独的模块,以便于维护。

可以考虑将这个列表移动到单独的配置文件中:

-const KNOWN_WORDS = [
-  "microapp",
-  "minmax",
-  "ctrl",
-  "dagre",
-  "rankdir",
-  "ranksep",
-  "nodesep",
-  "topo",
-  "plaintext",
-  "debuggable",
-  "async",
-  "searchable",
-];
+import { KNOWN_WORDS } from "./spellCheckConfig.js";

493-504: 优化 debounce 函数声明

debounce 函数声明使用了一般的 Function 类型,这在 TypeScript 中通常不推荐,因为它太宽泛。

另外,考虑返回一个带有取消功能的函数,这样可以在需要时手动取消延迟的操作,提高灵活性。

建议修改为以下形式:

-function debounce(func: Function, timeout = 300) {
+function debounce<T extends (...args: any[]) => any>(func: T, timeout = 300): (...args: Parameters<T>) => void {
  let timer = -1;
  return (...args: unknown[]) => {
    if (timer !== -1) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      timer = -1;
      func(...args);
    }, timeout) as unknown as number;
  };
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 493-493: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0acbe9b and 944151b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • packages/brick-playground/package.json (1 hunks)
  • packages/brick-playground/src/index.ts (3 hunks)
  • packages/brick-playground/src/spellCheck.worker.ts (1 hunks)
  • packages/brick-playground/src/spellCheckRemoteWorker.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/brick-playground/src/index.ts (1)
packages/brick-playground/src/spellCheckRemoteWorker.ts (1)
  • getRemoteSpellCheckWorker (16-24)
🪛 Biome (1.9.4)
packages/brick-playground/src/index.ts

[error] 493-493: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (20.x)
🔇 Additional comments (6)
packages/brick-playground/package.json (1)

28-29: 依赖项添加合理

新增的两个依赖项 @next-shared/spell-checkcomlink 直接支持拼写检查功能的实现。Comlink 的版本 4.4.2 是较新且稳定的版本,适合用于跨线程通信。

packages/brick-playground/src/spellCheck.worker.ts (1)

1-15: Worker 实现简洁有效

代码实现了一个简单明了的 Web Worker 类,通过 Comlink 库暴露 SpellCheckWorker 类,使主线程能够异步调用拼写检查功能而不阻塞 UI。istanbul ignore file 注释正确地将此文件排除在测试覆盖率统计之外,这对于 Worker 文件是合适的做法。

packages/brick-playground/src/spellCheckRemoteWorker.ts (1)

1-31: 单例模式实现良好

代码采用了良好的单例模式来管理 Worker 实例,确保只创建一个 Worker,并通过 Promise 机制提供异步访问。这种实现方式有效地避免了创建多个 Worker 实例的开销,同时保持了代码的整洁性。

Comlink 的 wrap 函数用于包装 Worker,使得可以像调用普通函数一样调用 Worker 中的方法,简化了跨线程通信的复杂性。

packages/brick-playground/src/index.ts (3)

15-15: 导入路径注意事项

导入路径使用了 .js 扩展名,与源文件的 .ts 扩展名不同。这在 TypeScript 项目中是常见的模式,因为编译后的文件会是 JS 文件。确保构建系统正确处理了这些导入路径转换。


249-271: 拼写检查实现优雅

拼写检查功能的实现非常优雅。使用 debounce 防止频繁调用,异步获取 Worker,然后将拼写检查的结果转换为 Monaco 编辑器的标记。代码结构清晰,容易理解。

异步操作处理得当,使用 await 等待 Worker 准备就绪和拼写检查完成。将标记位置从字符索引转换为行列位置的代码也很规范。


279-279: 正确集成到现有逻辑中

在编辑器内容更改事件处理程序中调用 debouncedSpellCheck(),确保了拼写检查能够在用户输入后触发,同时不会影响其他现有功能。

@cypress
Copy link

cypress bot commented Apr 2, 2025

next-core    Run #11124

Run Properties:  status check passed Passed #11124  •  git commit 00442624b5 ℹ️: Merge 944151b2bf01125808c5d161c1fe26ce28fb0449 into 0acbe9bca1d56c68e8f2aecc851c...
Project next-core
Branch Review steve/v3-playground-spell-check
Run status status check passed Passed #11124
Run duration 00m 23s
Commit git commit 00442624b5 ℹ️: Merge 944151b2bf01125808c5d161c1fe26ce28fb0449 into 0acbe9bca1d56c68e8f2aecc851c...
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 16
View all changes introduced in this branch ↗︎

@weareoutman weareoutman merged commit a40bcc1 into v3 Apr 2, 2025
8 checks passed
@weareoutman weareoutman deleted the steve/v3-playground-spell-check branch April 2, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants