feat(rust-plugins): 🎸 auto import support inject at end#134
feat(rust-plugins): 🎸 auto import support inject at end#134CCherry07 merged 5 commits intofarm-fe:mainfrom
Conversation
auto import support inject at end
remove print
WalkthroughA new optional boolean property, Changes
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
Poem
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)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) Caused by: 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (9)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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::Spanimport is necessary for the new span tracking functionality.
71-71: LGTM! Essential addition for position tracking.Adding the
spanfield toESMImportenables 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
ESMImportinstantiations are properly updated to include thespanfield, 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_endparameter 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_strat 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.
camelCase
auto import support inject at end
Summary by CodeRabbit