Skip to content

feat(rust-plugins): 🎸 auto import support inject at end#134

Merged
CCherry07 merged 5 commits intofarm-fe:mainfrom
faga295:feat/auto_import_inject_at_end
Jul 24, 2025
Merged

feat(rust-plugins): 🎸 auto import support inject at end#134
CCherry07 merged 5 commits intofarm-fe:mainfrom
faga295:feat/auto_import_inject_at_end

Conversation

@faga295
Copy link
Copy Markdown
Contributor

@faga295 faga295 commented Jun 29, 2025

auto import support inject at end

Summary by CodeRabbit

  • New Features
    • Added an option to control where auto-imported statements are inserted—either at the beginning or after the last existing import—via a new setting.
  • Improvements
    • Enhanced import parsing to track the position of existing import statements, enabling more precise placement of auto-imports.

liuzhaochen03 added 2 commits June 30, 2025 00:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 29, 2025

Walkthrough

A new optional boolean property, inject_at_end, was introduced across the TypeScript interface and Rust plugin options to control where auto-imports are injected in code files. Supporting changes update the import injection logic to allow insertion either at the beginning or after the last existing ESM import, utilizing new span-tracking in parsed imports.

Changes

File(s) Change Summary
rust-plugins/auto-import/options.d.ts Added optional injectAtEnd?: boolean to IPluginOptions interface.
rust-plugins/auto-import/src/lib.rs Added inject_at_end: Option<bool> to Options struct; added serde camelCase rename; updated transform method to use new option.
rust-plugins/auto-import/src/parser/inject_imports.rs Updated inject_imports function signature to accept inject_at_end boolean; changed import insertion logic accordingly.
rust-plugins/auto-import/src/parser/parse.rs Added span: Span field to ESMImport struct; updated import visitor to populate span from parsed imports; imported swc_common::Span.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Plugin (Rust)
    participant Parser
    participant Injector

    User->>Plugin (Rust): Provide options (may include inject_at_end)
    Plugin (Rust)->>Parser: Parse content for existing imports (collect spans)
    Parser-->>Plugin (Rust): Return ESMImport list with spans
    Plugin (Rust)->>Injector: Call inject_imports(content, imports, ..., inject_at_end)
    Injector->>Injector: Determine insertion index (start or after last import)
    Injector-->>Plugin (Rust): Return content with imports injected at chosen position
Loading

Poem

In fields of code where imports grow,
A bunny hops, deciding where they go.
At the start or at the end,
It’s up to you, dear coder friend!
With spans in paw and options bright,
The imports now can land just right.
🐇✨

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.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/fa/rm/farmfe_core, error: Permission denied (os error 13)
Downloading crates ...
Downloaded ahash v0.8.11
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)


📜 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 105218e and 78cb441.

📒 Files selected for processing (2)
  • rust-plugins/auto-import/options.d.ts (1 hunks)
  • rust-plugins/auto-import/src/lib.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • rust-plugins/auto-import/options.d.ts
  • rust-plugins/auto-import/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-x64-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-arm64-gnu
  • GitHub Check: call-rust-build / Build and Upload Artifacts - darwin-x64
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-arm64-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-x64-gnu
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-x64-musl
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-ia32-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-arm64-musl
  • GitHub Check: call-rust-build / Build and Upload Artifacts - darwin-arm64
✨ 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.

Copy link
Copy Markdown

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b594424 and a00ab93.

📒 Files selected for processing (4)
  • rust-plugins/auto-import/options.d.ts (1 hunks)
  • rust-plugins/auto-import/src/lib.rs (2 hunks)
  • rust-plugins/auto-import/src/parser/inject_imports.rs (2 hunks)
  • rust-plugins/auto-import/src/parser/parse.rs (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
rust-plugins/auto-import/src/parser/parse.rs (1)
Learnt from: fu050409
PR: farm-fe/plugins#115
File: rust-plugins/wasm/src/utils.rs:71-80
Timestamp: 2025-02-24T06:59:13.009Z
Learning: When generating JavaScript import statements from file paths in Rust, use `{:?}` format specifier instead of `{}` to ensure proper escaping of special characters in paths (e.g., `"".txt` → `\"\"`).
rust-plugins/auto-import/src/parser/inject_imports.rs (1)
Learnt from: fu050409
PR: farm-fe/plugins#115
File: rust-plugins/wasm/src/utils.rs:71-80
Timestamp: 2025-02-24T06:59:13.009Z
Learning: When generating JavaScript import statements from file paths in Rust, use `{:?}` format specifier instead of `{}` to ensure proper escaping of special characters in paths (e.g., `"".txt` → `\"\"`).
🧬 Code Graph Analysis (1)
rust-plugins/auto-import/src/lib.rs (1)
rust-plugins/auto-import/src/parser/inject_imports.rs (1)
  • inject_imports (57-145)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-arm64-gnu
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-arm64-musl
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-arm64-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - darwin-x64
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-x64-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - darwin-arm64
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-x64-musl
  • GitHub Check: call-rust-build / Build and Upload Artifacts - win32-ia32-msvc
  • GitHub Check: call-rust-build / Build and Upload Artifacts - linux-x64-gnu
🔇 Additional comments (8)
rust-plugins/auto-import/options.d.ts (1)

49-49: LGTM! Clean addition of the configuration option.

The optional boolean property is properly typed and maintains backward compatibility.

rust-plugins/auto-import/src/parser/parse.rs (3)

4-4: LGTM! Proper import of Span type.

The addition of swc_common::Span import is necessary for the new span tracking functionality.


71-71: LGTM! Essential addition for position tracking.

Adding the span field to ESMImport enables precise location tracking of import statements, which is crucial for the inject_at_end feature.


127-127: LGTM! Consistent span initialization across all constructors.

All ESMImport instantiations are properly updated to include the span field, ensuring consistent behavior across different import types.

Also applies to: 139-139, 152-152, 163-163

rust-plugins/auto-import/src/lib.rs (2)

95-95: LGTM! Proper configuration field addition.

The optional boolean field maintains backward compatibility while enabling the new inject_at_end functionality.


161-161: LGTM! Correct parameter passing with sensible default.

The function call properly passes the inject_at_end option with a default value of false, preserving existing behavior when the option is not specified.

rust-plugins/auto-import/src/parser/inject_imports.rs (2)

57-57: LGTM! Function signature correctly updated.

The addition of the inject_at_end parameter enables the new injection behavior while maintaining the existing API structure.


141-144: LGTM! Proper implementation of insertion logic.

The change from concatenation to insert_str at the computed index correctly implements the inject_at_end functionality. The approach of converting content to mutable string and inserting at the calculated position is sound.

Comment thread rust-plugins/auto-import/src/parser/inject_imports.rs Outdated
@CCherry07 CCherry07 merged commit b615fe8 into farm-fe:main Jul 24, 2025
17 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants