Skip to content

fix(gunshi): fix type error plugin onExtension, when extension is not define - #236

Merged
kazupon merged 1 commit into
mainfrom
fix/type-plugin
Jul 16, 2025
Merged

kazupon merged 1 commit into
mainfrom
fix/type-plugin

Conversation

@kazupon

@kazupon kazupon commented Jul 16, 2025

Copy link
Copy Markdown
Owner

Description

Linked Issues

Additional context

Summary by CodeRabbit

  • Bug Fixes
    • Ensured that the plugin system always provides a defined extension property, improving consistency across plugins.
  • Refactor
    • Simplified plugin type usage in the completion plugin by removing unnecessary extension-related types and properties.

@coderabbitai

coderabbitai Bot commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the plugin extension handling in the core plugin system to ensure the extension property is always defined, using a no-op default when not explicitly provided. Related tests are updated to expect a defined extension. The completion plugin is refactored to remove unused extension-related code and types.

Changes

File(s) Change Summary
packages/gunshi/src/plugin/core.ts Introduced NOOP_EXTENSION, ensured extension is always defined, updated plugin overloads and types.
packages/gunshi/src/plugin/core.test.ts Updated tests to expect extension to be defined instead of undefined.
packages/plugin-completion/src/index.ts Removed extension property and related types, updated function signature to use PluginWithoutExtension.

Suggested labels

refactoring

Poem

In the warren of code, a change hops in,
Extensions now defined, right from the begin.
No more undefined, just a no-op in place,
The plugins all smile, code’s neat in its space.
🐇✨ With a hop and a skip, the tests now all win!


📜 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 9e4d5f7 and 43c5d67.

📒 Files selected for processing (3)
  • packages/gunshi/src/plugin/core.test.ts (2 hunks)
  • packages/gunshi/src/plugin/core.ts (3 hunks)
  • packages/plugin-completion/src/index.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts,tsx,mjs}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
**/*.{js,ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
packages/gunshi/src/**/*.ts

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
🧠 Learnings (3)
packages/plugin-completion/src/index.ts (4)
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : Ensure changes work across Node.js, Deno, and Bun
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : All source code is in TypeScript with strict mode enabled
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : Type safety is a core feature - maintain strict TypeScript types throughout
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Test files are in 'packages/gunshi/test/' with '.test.ts' extension
packages/gunshi/src/plugin/core.ts (3)
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : Ensure changes work across Node.js, Deno, and Bun
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : All source code is in TypeScript with strict mode enabled
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Add tests for new features in the corresponding test file
packages/gunshi/src/plugin/core.test.ts (8)
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Test files are in 'packages/gunshi/test/' with '.test.ts' extension
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Add tests for new features in the corresponding test file
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : The project uses snapshot testing for renderer output - update snapshots when renderer behavior changes
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : Ensure changes work across Node.js, Deno, and Bun
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Mock external dependencies when needed in tests
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/test/**/*.test.ts : Use 'describe' and 'it' blocks for test organization
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : All source code is in TypeScript with strict mode enabled
Learnt from: CR
PR: kazupon/gunshi#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-04T11:05:35.037Z
Learning: Applies to packages/gunshi/src/**/*.ts : Type safety is a core feature - maintain strict TypeScript types throughout
🧬 Code Graph Analysis (2)
packages/plugin-completion/src/index.ts (2)
packages/plugin-completion/src/types.ts (1)
  • CompletionOptions (39-50)
packages/gunshi/src/plugin/core.ts (1)
  • PluginWithoutExtension (129-135)
packages/gunshi/src/plugin/core.ts (2)
packages/gunshi/src/types.ts (1)
  • DefaultGunshiParams (47-47)
packages/plugin-global/src/extension.ts (1)
  • extension (39-84)
🔇 Additional comments (7)
packages/gunshi/src/plugin/core.ts (3)

18-20: Well-implemented no-op extension constant.

The NOOP_EXTENSION constant provides a lightweight, appropriate default for plugins without explicit extensions. Using Object.create(null) is optimal as it creates an object without prototype overhead.


170-170: Good addition of onExtension support for plugins without explicit extensions.

Adding the optional onExtension callback parameter to the plugin overload without extensions maintains API consistency and allows all plugins to hook into the extension lifecycle, regardless of whether they define explicit extensions.


192-193: Excellent solution to ensure extension property is always defined.

The implementation change guarantees that every plugin has a defined extension property, eliminating the undefined case that was causing type errors. The fallback to NOOP_EXTENSION when no explicit extension is provided maintains backward compatibility while fixing the type safety issue.

packages/gunshi/src/plugin/core.test.ts (2)

179-179: Correct test assertion update for always-defined extension property.

The test assertion correctly expects extension to be defined for plugins without explicit extensions, which aligns with the core implementation changes that ensure all plugins have a defined extension property.


250-250: Appropriate test expectation for plugin extension property.

The test correctly expects the extension property to be defined, which validates the new behavior where plugins always have an extension property, even when using the no-op default.

packages/plugin-completion/src/index.ts (2)

13-19: Appropriate import and type updates for simplified plugin system.

The import changes correctly remove PluginWithExtension and add PluginWithoutExtension, reflecting the plugin's simplified implementation that no longer needs explicit extension handling since the core system manages this internally.


36-36: Correct return type change for simplified plugin implementation.

The return type change from PluginWithExtension<CompletionCommandContext> to PluginWithoutExtension properly reflects the removal of explicit extension handling, as the core plugin system now ensures all plugins have a defined extension property internally.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

@kazupon kazupon added the improvement Includes backwards-compatible fixes label Jul 16, 2025
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying gunshi with  Cloudflare Pages  Cloudflare Pages

Latest commit: 43c5d67
Status: ✅  Deploy successful!
Preview URL: https://641d4903.gunshi.pages.dev
Branch Preview URL: https://fix-type-plugin.gunshi.pages.dev

View logs

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@gunshi/bone

npm i https://pkg.pr.new/@gunshi/bone@236

@gunshi/definition

npm i https://pkg.pr.new/@gunshi/definition@236

gunshi

npm i https://pkg.pr.new/gunshi@236

@gunshi/plugin

npm i https://pkg.pr.new/@gunshi/plugin@236

@gunshi/plugin-completion

npm i https://pkg.pr.new/@gunshi/plugin-completion@236

@gunshi/plugin-dryrun

npm i https://pkg.pr.new/@gunshi/plugin-dryrun@236

@gunshi/plugin-global

npm i https://pkg.pr.new/@gunshi/plugin-global@236

@gunshi/plugin-i18n

npm i https://pkg.pr.new/@gunshi/plugin-i18n@236

@gunshi/plugin-renderer

npm i https://pkg.pr.new/@gunshi/plugin-renderer@236

@gunshi/resources

npm i https://pkg.pr.new/@gunshi/resources@236

@gunshi/shared

npm i https://pkg.pr.new/@gunshi/shared@236

commit: 43c5d67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Includes backwards-compatible fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant