leetcode-cli
leetcode-cli copied to clipboard
Add per-problem Cargo.toml and subdir structure for Rust LSP support
Summary
- For
lang = 'rust', generates subdir crates (e.g.,code/1-two_sum/src/lib.rs,Cargo.tomlwithprob-1-two_sumpackage,tests.dat). - Enables full rust-analyzer LSP in editors (autocomplete, diagnostics) without breaking LeetCode API submissions (still extracts code snippet).
- New config:
[code] enable_rust_crates = true(default; set false for flat files). - Backward compatible: Legacy configs load with default true; notes existing flat files.
- Enhancements: Sanitized names, commented deps in Cargo.toml, error handling.
Changes
- Updated paths in
helper.rs(conditional subdirs). - Added dir/Cargo.toml creation in
cmds/edit.rs. - Configurable via new field in
config/code.rs. - Docs: New README section on Rust setup.
Testing
- Manual:
leetcode edit 1creates structure;test 1/exec 1work. - LSP: Open dir in Helix/VS Code—full features.
- Flat fallback: Set
enable_rust_crates = falseand edit another problem.
Closes #204 . Ready for review!
If I'm not mistaken, rust LSP supports single file, see https://github.com/rust-lang/rust-analyzer/pull/8955, may I ask which editor (+rustc version) are you using?
Sorry @clearloop was on vacation! I use Helix Editor. I guess this is something I need to look into, I couldn't get it to work nicely before