Skip to content

feat: improve plugin ID guidance and type safety#818

Merged
tbouffard merged 1 commit intomainfrom
feat/guidance_plugin_id_with_new_types
May 7, 2025
Merged

feat: improve plugin ID guidance and type safety#818
tbouffard merged 1 commit intomainfrom
feat/guidance_plugin_id_with_new_types

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 7, 2025

  • Add type hints when retrieving plugins through IDE auto-completion
  • Enable built-in maxGraph plugin IDs to be suggested in development
  • Improve developer experience when working with the plugin system

Summary by CodeRabbit

  • Refactor
    • Improved type safety for plugin identifiers by introducing specific types for built-in and custom plugin IDs.
    • Updated relevant interfaces and method signatures to use the new plugin ID types for clearer and stricter typing.

- Add type hints when retrieving plugins through IDE auto-completion
- Enable built-in maxGraph plugin IDs to be suggested in development
- Improve developer experience when working with the plugin system
@tbouffard tbouffard added the enhancement New feature or request label May 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 7, 2025

Walkthrough

The changes introduce two new TypeScript type aliases, BuiltinPluginId and PluginId, to enumerate and type plugin identifiers more precisely. The pluginId property in the GraphPluginConstructor interface and the id parameter in the getPlugin method are updated to use the new PluginId type, enforcing stricter typing for plugin IDs.

Changes

File(s) Change Summary
packages/core/src/types.ts Added BuiltinPluginId and PluginId type aliases; updated GraphPluginConstructor.pluginId type.
packages/core/src/view/AbstractGraph.ts Updated getPlugin method signature to use PluginId instead of string for the id parameter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AbstractGraph
    participant Plugin

    Client->>AbstractGraph: getPlugin(pluginId: PluginId)
    AbstractGraph->>Plugin: Retrieve plugin instance by PluginId
    AbstractGraph-->>Client: Return plugin instance (typed as T)
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8895fb and f05cf06.

📒 Files selected for processing (2)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/view/AbstractGraph.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/view/AbstractGraph.ts (1)
packages/core/src/types.ts (2)
  • GraphPlugin (1178-1180)
  • PluginId (1169-1169)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (5)
packages/core/src/types.ts (3)

1148-1162: Well-defined enumeration of built-in plugin IDs for better developer guidance.

This new BuiltinPluginId type provides an explicit list of all built-in plugin IDs, which will enhance IDE auto-completion and make available plugin options discoverable during development.


1164-1169: Proper type union design that maintains extensibility.

The PluginId type elegantly combines built-in IDs with support for custom string-based IDs. The Record<never, never> intersection is a clever TypeScript technique to ensure type safety while still allowing custom string values that are distinct from the built-in ones.


1173-1173: Updated interface property to use the new more specific type.

Updating the pluginId property in the GraphPluginConstructor interface to use the new PluginId type completes the type safety improvement, ensuring that only valid plugin IDs can be assigned.

packages/core/src/view/AbstractGraph.ts (2)

56-56: Added import for new PluginId type.

Properly importing the new PluginId type to be used in the method signature.


497-497: Enhanced type safety for plugin retrieval.

Updating the getPlugin method to use the new PluginId type instead of the generic string type improves type safety and provides better IDE guidance when retrieving plugins. This change ensures alignment with the updated GraphPluginConstructor interface.

✨ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 7, 2025

@tbouffard tbouffard merged commit f9d1d3d into main May 7, 2025
7 checks passed
@tbouffard tbouffard deleted the feat/guidance_plugin_id_with_new_types branch May 7, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant