diff --git a/README.md b/README.md index c80ae9d..39c61dc 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ SUBCOMMANDS: ## Example -For example, given this config (could be found at `~/.leetcode/leetcode.toml`): +To configure leetcode-cli, create a file at `~/.leetcode/leetcode.toml`): ```toml [code] @@ -186,6 +186,14 @@ pub fn three_sum(nums: Vec) -> Vec> {
+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: + +```toml +[code] +inject_before = ["#includepick ```sh diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 03e138e..fc3da47 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -356,7 +356,7 @@ impl Cache { ) -> Result { trace!("Exec problem filter —— Test or Submit"); let (json, [url, refer]) = self.pre_run_code(run.clone(), rfid, test_case).await?; - trace!("Pre run code result {:#?}, {}, {}", json, url, refer); + trace!("Pre-run code result {:#?}, {}, {}", json, url, refer); let text = self .0 @@ -367,7 +367,7 @@ impl Cache { .await?; let run_res: RunCode = serde_json::from_str(&text).map_err(|e| { - anyhow!("json error: {e}, plz double check your session and csrf config.") + anyhow!("JSON error: {e}, please double check your session and csrf config.") })?; trace!("Run code result {:#?}", run_res); diff --git a/src/cmds/edit.rs b/src/cmds/edit.rs index 9be45ec..73a9878 100644 --- a/src/cmds/edit.rs +++ b/src/cmds/edit.rs @@ -93,6 +93,11 @@ impl Command for EditCommand { file_code.write_all(p_desc_comment.as_bytes())?; file_code.write_all(question_desc.as_bytes())?; } + if let Some(inject_before) = &conf.code.inject_before { + for line in inject_before { + file_code.write_all((line.to_string() + "\n").as_bytes())?; + } + } if conf.code.edit_code_marker { file_code.write_all( (conf.code.comment_leading.clone() @@ -112,6 +117,11 @@ impl Command for EditCommand { .as_bytes(), )?; } + if let Some(inject_after) = &conf.code.inject_after { + for line in inject_after { + file_code.write_all((line.to_string() + "\n").as_bytes())?; + } + } if test_flag { let mut file_tests = File::create(&test_path)?; diff --git a/src/config/code.rs b/src/config/code.rs index 0384608..f8e6cea 100644 --- a/src/config/code.rs +++ b/src/config/code.rs @@ -22,6 +22,10 @@ pub struct Code { pub start_marker: String, #[serde(default, skip_serializing)] pub end_marker: String, + #[serde(rename(serialize = "inject_before"), alias = "inject_before", default)] + pub inject_before: Option>, + #[serde(rename(serialize = "inject_after"), alias = "inject_after", default)] + pub inject_after: Option>, #[serde(default, skip_serializing)] pub comment_problem_desc: bool, #[serde(default, skip_serializing)] @@ -43,6 +47,8 @@ impl Default for Code { edit_code_marker: false, start_marker: "".into(), end_marker: "".into(), + inject_before: None, + inject_after: None, comment_problem_desc: false, comment_leading: "".into(), test: true, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy