Skip to content

Commit b3c1d6a

Browse files
author
Antonio Bennett
committed
Docs: Add language-specific configuration section to README
- Focus on Rust LSP support with subdir/Cargo.toml details, config option, and usage. - Positions Rust first; extensible for other languages.
1 parent 96981de commit b3c1d6a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ pub fn three_sum(nums: Vec<i32>) -> Vec<Vec<i32>> {
192192

193193
</details>
194194

195+
## Language-Specific Configuration
196+
197+
### Rust
198+
For `lang = 'rust'`, leetcode-cli generates per-problem crate structures to enable full LSP support (e.g., rust-analyzer in editors like Helix or VS Code).
199+
200+
- **Structure**: `code/{fid}-{slug}/src/lib.rs` (code), `tests.dat` (test cases), and `Cargo.toml` (basic crate config with commented dependencies for common crates like `itertools` or `regex`).
201+
- **Example**: For problem 1 ("Two Sum"), creates `code/1-two_sum/` with `prob-1-two_sum` as package name.
202+
- **Config Option**: Set `enable_rust_crates = false` in `[code]` to fall back to flat files (e.g., `1.two-sum.rs`).
203+
- **Usage**: Run `leetcode edit 1`, then open the dir: `hx code/1-two_sum/` for LSP features (autocomplete, diagnostics, etc.).
204+
- **Migration**: If flat files exist, the tool notes them—manually move content to `lib.rs` if needed.
205+
- **Local Testing**: Edit `Cargo.toml` to add deps, then `cargo check` or `cargo test` (tests.dat can be adapted for unit tests).
206+
207+
This keeps submissions unchanged (sends code snippet to LeetCode API) while improving local editing.
208+
209+
For other languages, files remain flat. Future support for similar setups (e.g., Python virtualenvs) can be added via config.
210+
195211
<br>
196212

197213
Some linting tools/lsps will throw errors unless the necessary libraries are imported. leetcode-cli can generate this boilerplate automatically if the `inject_before` key is set. Similarly, if you want to test out your code locally, you can automate that with `inject_after`. For c++ this might look something like:

0 commit comments

Comments
 (0)