leetcode-cli icon indicating copy to clipboard operation
leetcode-cli copied to clipboard

Add per-problem Cargo.toml and subdir structure for Rust LSP support

Open Antonio-Bennett opened this issue 2 months ago • 2 comments

Summary

  • For lang = 'rust', generates subdir crates (e.g., code/1-two_sum/src/lib.rs, Cargo.toml with prob-1-two_sum package, 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 1 creates structure; test 1/exec 1 work.
  • LSP: Open dir in Helix/VS Code—full features.
  • Flat fallback: Set enable_rust_crates = false and edit another problem.

Closes #204 . Ready for review!

Antonio-Bennett avatar Sep 23 '25 20:09 Antonio-Bennett

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?

clearloop avatar Oct 02 '25 04:10 clearloop

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

Antonio-Bennett avatar Oct 15 '25 04:10 Antonio-Bennett