From 85851c699a439a504ff8a80a7920c50a129cc554 Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sun, 17 Aug 2025 17:51:19 +0100 Subject: [PATCH 1/3] super add --- crates/irust/src/irust.rs | 5 +- crates/irust/src/irust/engine.rs | 10 +- .../irust/src/irust/script/script_manager.rs | 2 + crates/irust_api/src/lib.rs | 1 + script_examples/Cargo.lock | 348 ++++++++++++++++-- script_examples/Cargo.toml | 3 +- script_examples/super_add/Cargo.toml | 14 + script_examples/super_add/src/main.rs | 282 ++++++++++++++ script_examples/super_add/src/main.rs.bkp | 94 +++++ 9 files changed, 724 insertions(+), 35 deletions(-) create mode 100644 script_examples/super_add/Cargo.toml create mode 100644 script_examples/super_add/src/main.rs create mode 100644 script_examples/super_add/src/main.rs.bkp diff --git a/crates/irust/src/irust.rs b/crates/irust/src/irust.rs index 053e41da..f865b607 100644 --- a/crates/irust/src/irust.rs +++ b/crates/irust/src/irust.rs @@ -118,7 +118,9 @@ impl IRust { self.printer.print_prompt_if_set()?; // Scripts might want run some startup commands, give them a chance here - self.run_scripts_startup_cmds()?; + dbg!("Startup commands"); + // self.run_scripts_startup_cmds()?; + dbg!("after Startup commands"); Ok(()) } @@ -133,6 +135,7 @@ impl IRust { pub fn run(&mut self) -> Result<()> { self.printer.enable_raw_mode(); + dbg!("aazeae"); self.prepare()?; let mut server = if self.options.local_server { diff --git a/crates/irust/src/irust/engine.rs b/crates/irust/src/irust/engine.rs index ccb9256e..9cc242ac 100644 --- a/crates/irust/src/irust/engine.rs +++ b/crates/irust/src/irust/engine.rs @@ -209,7 +209,8 @@ impl IRust { let buffer = self.buffer.to_string(); if let Some(cmd) = self.output_event_hook(&buffer) { - return self.execute(cmd); + dbg!("a"); + return dbg!(self.execute(cmd)); } self.execute(Command::Parse(buffer))?; @@ -822,6 +823,13 @@ impl IRust { let output = PrinterItem::String(output, color).into(); self.print_output(output) } + Command::CargoAddCommand(args) => { + let mut dep: Vec = crate::utils::split_args(args); + dep.remove(0); //drop :add + self.wait_add(self.repl.add_dep(&dep)?, "Add")?; + self.wait_add(self.repl.build()?, "Build")?; + Ok(()) + } } } diff --git a/crates/irust/src/irust/script/script_manager.rs b/crates/irust/src/irust/script/script_manager.rs index 8c373e0c..f73c8646 100644 --- a/crates/irust/src/irust/script/script_manager.rs +++ b/crates/irust/src/irust/script/script_manager.rs @@ -35,6 +35,7 @@ impl ScriptManager { ) .ok()?; } + dbg!("a"); // read conf if available let script_conf_path = crate::utils::irust_dirs::config_dir()? @@ -68,6 +69,7 @@ impl ScriptManager { }) } + dbg!("azz"); Some(ScriptManager { sm, startup_cmds }) } } diff --git a/crates/irust_api/src/lib.rs b/crates/irust_api/src/lib.rs index d88ddfd4..a5948dca 100644 --- a/crates/irust_api/src/lib.rs +++ b/crates/irust_api/src/lib.rs @@ -80,6 +80,7 @@ Output => () pub enum Command { AcceptSuggestion, Continue, + CargoAddCommand(String), DeleteNextWord, DeleteTillEnd, DeleteUntilChar(char, bool), diff --git a/script_examples/Cargo.lock b/script_examples/Cargo.lock index 4d58a60c..ae280cbc 100644 --- a/script_examples/Cargo.lock +++ b/script_examples/Cargo.lock @@ -25,9 +25,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" dependencies = [ "serde", ] @@ -38,18 +38,45 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "convert_case" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "crossterm" version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.9.2", "crossterm_winapi", - "filedescriptor", "libc", - "mio", + "mio 0.8.11", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags 2.9.2", + "crossterm_winapi", + "derive_more", + "document-features", + "filedescriptor", + "mio 1.0.4", "parking_lot", + "rustix", "serde", "signal-hook", "signal-hook-mio", @@ -65,6 +92,27 @@ dependencies = [ "winapi", ] +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dirs" version = "5.0.1" @@ -83,7 +131,16 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", ] [[package]] @@ -92,6 +149,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + [[package]] name = "filedescriptor" version = "0.8.2" @@ -153,7 +220,7 @@ dependencies = [ name = "irust_animation" version = "0.1.0" dependencies = [ - "crossterm", + "crossterm 0.27.0", "irust_api", "rscript", ] @@ -162,7 +229,7 @@ dependencies = [ name = "irust_api" version = "0.31.9" dependencies = [ - "crossterm", + "crossterm 0.29.0", "rscript", "serde", ] @@ -185,9 +252,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libloading" @@ -205,11 +272,23 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.9.2", "libc", "redox_syscall", ] +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + +[[package]] +name = "litrs" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" + [[package]] name = "lock_api" version = "0.4.11" @@ -241,7 +320,19 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.59.0", ] [[package]] @@ -278,14 +369,24 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "prettyplease" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" +dependencies = [ + "proc-macro2", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -331,6 +432,19 @@ dependencies = [ "serde", ] +[[package]] +name = "rustix" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +dependencies = [ + "bitflags 2.9.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.60.2", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -348,18 +462,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", @@ -387,12 +501,13 @@ dependencies = [ [[package]] name = "signal-hook-mio" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" dependencies = [ "libc", - "mio", + "mio 0.8.11", + "mio 1.0.4", "signal-hook", ] @@ -411,11 +526,21 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "super_add" +version = "0.1.0" +dependencies = [ + "irust_api", + "prettyplease", + "rscript", + "syn", +] + [[package]] name = "syn" -version = "2.0.55" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -482,6 +607,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -510,13 +641,37 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -525,13 +680,46 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -540,42 +728,138 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "winnow" version = "0.5.40" diff --git a/script_examples/Cargo.toml b/script_examples/Cargo.toml index e24a9abe..909413ed 100644 --- a/script_examples/Cargo.toml +++ b/script_examples/Cargo.toml @@ -7,7 +7,8 @@ members = [ "./ipython", "./fun", "./irust_animation", - "./mixed_cmds" + "./mixed_cmds", + "./super_add", ] [workspace.dependencies] diff --git a/script_examples/super_add/Cargo.toml b/script_examples/super_add/Cargo.toml new file mode 100644 index 00000000..175cc5a8 --- /dev/null +++ b/script_examples/super_add/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "super_add" +version = "0.1.0" +authors = [] +edition = "2024" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +irust_api.workspace = true +rscript.workspace = true + +syn = { version = "2.0", features = ["full", "visit-mut"] } +prettyplease = "0.2" diff --git a/script_examples/super_add/src/main.rs b/script_examples/super_add/src/main.rs new file mode 100644 index 00000000..17fdce37 --- /dev/null +++ b/script_examples/super_add/src/main.rs @@ -0,0 +1,282 @@ +use irust_api::{Command, OutputEvent, Shutdown}; +use rscript::scripting::Scripter; +use rscript::{Hook, VersionReq}; +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; +use std::time::{SystemTime, UNIX_EPOCH}; +use syn::{visit_mut::VisitMut, File, Item, Visibility}; + +// Cargo.toml dependencies needed: +// [dependencies] +// irust_api = "*" +// rscript = "*" +// syn = { version = "2.0", features = ["full", "visit-mut"] } +// prettyplease = "0.2" + +#[derive(Debug)] +struct TempCrateModifier { + temp_path: PathBuf, +} + +impl TempCrateModifier { + /// Create a new temporary copy of the crate with all items made public + fn new(source_path: &Path) -> Result> { + let temp_path = create_temp_copy(source_path)?; + dbg!("created", &temp_path); + make_all_items_public(&temp_path)?; + + Ok(TempCrateModifier { temp_path }) + } + + /// Get the path to the temporary crate + fn path(&self) -> &Path { + &self.temp_path + } +} + +impl Drop for TempCrateModifier { + fn drop(&mut self) {} +} + +fn create_temp_copy(source: &Path) -> Result> { + let temp_base = env::temp_dir(); + let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_nanos(); + let temp_name = format!("irust_super_add_{}", timestamp); + let temp_path = temp_base.join(temp_name); + + fs::create_dir_all(&temp_path)?; + copy_dir_recursive(source, &temp_path)?; + + Ok(temp_path) +} + +fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<(), Box> { + if !dst.exists() { + fs::create_dir_all(dst)?; + } + + for entry in fs::read_dir(src)? { + let entry = entry?; + let src_path = entry.path(); + let dst_path = dst.join(entry.file_name()); + + if src_path.is_dir() { + // Skip common directories that shouldn't be copied + if let Some(dir_name) = src_path.file_name() { + let dir_str = dir_name.to_string_lossy(); + if matches!( + dir_str.as_ref(), + "target" | ".git" | "node_modules" | ".cargo" + ) { + continue; + } + } + copy_dir_recursive(&src_path, &dst_path)?; + } else { + fs::copy(&src_path, &dst_path)?; + } + } + + Ok(()) +} + +fn make_all_items_public(dir: &Path) -> Result<(), Box> { + visit_rust_files(dir, &mut |file_path| process_rust_file(file_path)) +} + +fn visit_rust_files(dir: &Path, callback: &mut F) -> Result<(), Box> +where + F: FnMut(&Path) -> Result<(), Box>, +{ + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + + if path.is_dir() { + visit_rust_files(&path, callback)?; + } else if path.extension().map_or(false, |ext| ext == "rs") { + callback(&path)?; + } + } + Ok(()) +} + +fn process_rust_file(file_path: &Path) -> Result<(), Box> { + let content = fs::read_to_string(file_path)?; + + // Parse the Rust file into an AST + let mut ast: File = match syn::parse_str(&content) { + Ok(ast) => ast, + Err(_) => { + // Skip files that can't be parsed (might be proc macro files, etc.) + return Ok(()); + } + }; + + // Apply the visibility transformer + let mut transformer = PublicityTransformer::new(); + transformer.visit_file_mut(&mut ast); + + // Only rewrite if changes were made + if transformer.changes_made > 0 { + let modified_content = prettyplease::unparse(&ast); + fs::write(file_path, modified_content)?; + } + + Ok(()) +} + +struct PublicityTransformer { + changes_made: usize, +} + +impl PublicityTransformer { + fn new() -> Self { + Self { changes_made: 0 } + } + + fn make_public(&mut self, vis: &mut Visibility) { + if !matches!(vis, Visibility::Public(_)) { + *vis = Visibility::Public(syn::token::Pub::default()); + self.changes_made += 1; + } + } +} + +impl VisitMut for PublicityTransformer { + fn visit_item_mut(&mut self, item: &mut Item) { + match item { + Item::Const(item_const) => { + self.make_public(&mut item_const.vis); + } + Item::Enum(item_enum) => { + self.make_public(&mut item_enum.vis); + } + Item::Fn(item_fn) => { + self.make_public(&mut item_fn.vis); + } + Item::Mod(item_mod) => { + self.make_public(&mut item_mod.vis); + } + Item::Static(item_static) => { + self.make_public(&mut item_static.vis); + } + Item::Struct(item_struct) => { + self.make_public(&mut item_struct.vis); + // Also make struct fields public + if let syn::Fields::Named(ref mut fields) = item_struct.fields { + for field in &mut fields.named { + self.make_public(&mut field.vis); + } + } + } + Item::Trait(item_trait) => { + self.make_public(&mut item_trait.vis); + } + Item::Type(item_type) => { + self.make_public(&mut item_type.vis); + } + Item::Union(item_union) => { + self.make_public(&mut item_union.vis); + // Make union fields public too + for field in &mut item_union.fields.named { + self.make_public(&mut field.vis); + } + } + Item::Use(item_use) => { + self.make_public(&mut item_use.vis); + } + _ => {} + } + + // Continue visiting nested items + syn::visit_mut::visit_item_mut(self, item); + } +} + +#[derive(Debug, Default)] +struct SuperAdd { + temp_crates: Vec, +} + +impl Scripter for SuperAdd { + fn name() -> &'static str { + "SuperAdd" + } + + fn script_type() -> rscript::ScriptType { + rscript::ScriptType::Daemon + } + + fn hooks() -> &'static [&'static str] { + &[OutputEvent::NAME, Shutdown::NAME] + } + + fn version_requirement() -> rscript::VersionReq { + VersionReq::parse(">=1.50.0").expect("correct version requirement") + } +} + +fn main() { + let _ = SuperAdd::execute(&mut |hook_name| SuperAdd::run(&mut SuperAdd::default(), hook_name)); +} + +impl SuperAdd { + fn run(&mut self, hook_name: &str) { + match hook_name { + OutputEvent::NAME => { + let hook: OutputEvent = Self::read(); + let input = hook.1.trim(); + + if input.starts_with(":add") && input.contains("--path") { + // Parse the path from the command + let path_str = if let Some(path_part) = input.split("--path").nth(1) { + path_part.trim().split_whitespace().next().unwrap_or("") + } else { + "" + }; + + if !path_str.is_empty() { + let source_path = PathBuf::from(path_str); + + if source_path.exists() { + match TempCrateModifier::new(&source_path) { + Ok(temp_crate) => { + let temp_path = temp_crate.path().to_string_lossy(); + + // Create the modified command with the temp path + let modified_command = input.replace(path_str, &temp_path); + + // Store the temp crate to keep it alive + self.temp_crates.push(temp_crate); + + // Send the modified command + let cmd = Command::CargoAddCommand(modified_command); + Self::write::(&Some(cmd)); + return; + } + Err(e) => { + eprintln!("SuperAdd: Failed to create temp crate copy: {}", e); + } + } + } else { + eprintln!("SuperAdd: Path does not exist: {}", path_str); + } + } + } + + // If we get here, either it's not an :add --path command or something went wrong + Self::write::(&None); + } + + Shutdown::NAME => { + // Clean up all temp crates + self.temp_crates.clear(); + Self::write::(&None); + } + + _ => unreachable!(), + } + } +} diff --git a/script_examples/super_add/src/main.rs.bkp b/script_examples/super_add/src/main.rs.bkp new file mode 100644 index 00000000..30233493 --- /dev/null +++ b/script_examples/super_add/src/main.rs.bkp @@ -0,0 +1,94 @@ +use irust_api::{Command, OutputEvent, Shutdown}; +use rscript::scripting::Scripter; +use rscript::{Hook, VersionReq}; +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; + +fn copy_dir_to_temp(source: &Path) -> Result> { + // Create a unique temporary directory name + let temp_base = env::temp_dir(); + let temp_name = format!("temp_copy_{}", std::process::id()); + let temp_path = temp_base.join(temp_name); + + // Create the temporary directory + fs::create_dir_all(&temp_path)?; + + // Copy the source directory contents to temp directory + copy_dir_recursive(source, &temp_path)?; + + Ok(temp_path) +} + +fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<(), Box> { + if !dst.exists() { + fs::create_dir_all(dst)?; + } + + for entry in fs::read_dir(src)? { + let entry = entry?; + let src_path = entry.path(); + let dst_path = dst.join(entry.file_name()); + + if src_path.is_dir() { + copy_dir_recursive(&src_path, &dst_path)?; + } else { + fs::copy(&src_path, &dst_path)?; + } + } + + Ok(()) +} + +#[derive(Debug, Default)] +struct SuperAdd {} + +impl Scripter for SuperAdd { + fn name() -> &'static str { + "SuperAdd" + } + + fn script_type() -> rscript::ScriptType { + rscript::ScriptType::Daemon + } + + fn hooks() -> &'static [&'static str] { + &[OutputEvent::NAME] + } + + fn version_requirement() -> rscript::VersionReq { + VersionReq::parse(">=1.50.0").expect("correct version requirement") + } +} + +fn main() { + let _ = SuperAdd::execute(&mut |hook_name| SuperAdd::run(&mut SuperAdd {}, hook_name)); +} + +impl SuperAdd { + fn run(&mut self, hook_name: &str) { + match hook_name { + OutputEvent::NAME => { + let hook: OutputEvent = Self::read(); + let input = hook.1; + if input.starts_with(":add") && input.contains("--path") { + let path = input + .split("--path") + .last() + .expect("path argument not found"); + // copy the directory in path to a temp directory + + let copy_dep = copy_dir_to_temp(&std::path::PathBuf::from(path)) + .expect("failed to copy directory"); + } else { + Self::write(&None); + } + } + _ => unreachable!(), + } + } + + fn clean_up(&self, _hook: Shutdown) -> Option { + None + } +} From 4683e7161d816db9a8f61e603db37632ec5f6dcb Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Mon, 18 Aug 2025 07:41:15 +0100 Subject: [PATCH 2/3] super add --- crates/irust/src/irust.rs | 5 +--- crates/irust/src/irust/engine.rs | 10 +------- .../irust/src/irust/script/script_manager.rs | 2 -- crates/irust_api/src/lib.rs | 1 - script_examples/super_add/src/main.rs | 25 ++++++++----------- 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/crates/irust/src/irust.rs b/crates/irust/src/irust.rs index f865b607..053e41da 100644 --- a/crates/irust/src/irust.rs +++ b/crates/irust/src/irust.rs @@ -118,9 +118,7 @@ impl IRust { self.printer.print_prompt_if_set()?; // Scripts might want run some startup commands, give them a chance here - dbg!("Startup commands"); - // self.run_scripts_startup_cmds()?; - dbg!("after Startup commands"); + self.run_scripts_startup_cmds()?; Ok(()) } @@ -135,7 +133,6 @@ impl IRust { pub fn run(&mut self) -> Result<()> { self.printer.enable_raw_mode(); - dbg!("aazeae"); self.prepare()?; let mut server = if self.options.local_server { diff --git a/crates/irust/src/irust/engine.rs b/crates/irust/src/irust/engine.rs index 9cc242ac..ccb9256e 100644 --- a/crates/irust/src/irust/engine.rs +++ b/crates/irust/src/irust/engine.rs @@ -209,8 +209,7 @@ impl IRust { let buffer = self.buffer.to_string(); if let Some(cmd) = self.output_event_hook(&buffer) { - dbg!("a"); - return dbg!(self.execute(cmd)); + return self.execute(cmd); } self.execute(Command::Parse(buffer))?; @@ -823,13 +822,6 @@ impl IRust { let output = PrinterItem::String(output, color).into(); self.print_output(output) } - Command::CargoAddCommand(args) => { - let mut dep: Vec = crate::utils::split_args(args); - dep.remove(0); //drop :add - self.wait_add(self.repl.add_dep(&dep)?, "Add")?; - self.wait_add(self.repl.build()?, "Build")?; - Ok(()) - } } } diff --git a/crates/irust/src/irust/script/script_manager.rs b/crates/irust/src/irust/script/script_manager.rs index f73c8646..8c373e0c 100644 --- a/crates/irust/src/irust/script/script_manager.rs +++ b/crates/irust/src/irust/script/script_manager.rs @@ -35,7 +35,6 @@ impl ScriptManager { ) .ok()?; } - dbg!("a"); // read conf if available let script_conf_path = crate::utils::irust_dirs::config_dir()? @@ -69,7 +68,6 @@ impl ScriptManager { }) } - dbg!("azz"); Some(ScriptManager { sm, startup_cmds }) } } diff --git a/crates/irust_api/src/lib.rs b/crates/irust_api/src/lib.rs index a5948dca..d88ddfd4 100644 --- a/crates/irust_api/src/lib.rs +++ b/crates/irust_api/src/lib.rs @@ -80,7 +80,6 @@ Output => () pub enum Command { AcceptSuggestion, Continue, - CargoAddCommand(String), DeleteNextWord, DeleteTillEnd, DeleteUntilChar(char, bool), diff --git a/script_examples/super_add/src/main.rs b/script_examples/super_add/src/main.rs index 17fdce37..486219d4 100644 --- a/script_examples/super_add/src/main.rs +++ b/script_examples/super_add/src/main.rs @@ -5,14 +5,7 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; use std::time::{SystemTime, UNIX_EPOCH}; -use syn::{visit_mut::VisitMut, File, Item, Visibility}; - -// Cargo.toml dependencies needed: -// [dependencies] -// irust_api = "*" -// rscript = "*" -// syn = { version = "2.0", features = ["full", "visit-mut"] } -// prettyplease = "0.2" +use syn::{File, Item, Visibility, visit_mut::VisitMut}; #[derive(Debug)] struct TempCrateModifier { @@ -23,7 +16,6 @@ impl TempCrateModifier { /// Create a new temporary copy of the crate with all items made public fn new(source_path: &Path) -> Result> { let temp_path = create_temp_copy(source_path)?; - dbg!("created", &temp_path); make_all_items_public(&temp_path)?; Ok(TempCrateModifier { temp_path }) @@ -36,7 +28,9 @@ impl TempCrateModifier { } impl Drop for TempCrateModifier { - fn drop(&mut self) {} + fn drop(&mut self) { + let _ = fs::remove_dir_all(&self.temp_path); + } } fn create_temp_copy(source: &Path) -> Result> { @@ -95,7 +89,7 @@ where if path.is_dir() { visit_rust_files(&path, callback)?; - } else if path.extension().map_or(false, |ext| ext == "rs") { + } else if path.extension().is_some_and(|ext| ext == "rs") { callback(&path)?; } } @@ -219,7 +213,8 @@ impl Scripter for SuperAdd { } fn main() { - let _ = SuperAdd::execute(&mut |hook_name| SuperAdd::run(&mut SuperAdd::default(), hook_name)); + let mut super_add = SuperAdd::default(); + let _ = SuperAdd::execute(&mut |hook_name| SuperAdd::run(&mut super_add, hook_name)); } impl SuperAdd { @@ -232,7 +227,7 @@ impl SuperAdd { if input.starts_with(":add") && input.contains("--path") { // Parse the path from the command let path_str = if let Some(path_part) = input.split("--path").nth(1) { - path_part.trim().split_whitespace().next().unwrap_or("") + path_part.split_whitespace().next().unwrap_or("") } else { "" }; @@ -243,7 +238,7 @@ impl SuperAdd { if source_path.exists() { match TempCrateModifier::new(&source_path) { Ok(temp_crate) => { - let temp_path = temp_crate.path().to_string_lossy(); + let temp_path = temp_crate.path().to_string_lossy().to_string(); // Create the modified command with the temp path let modified_command = input.replace(path_str, &temp_path); @@ -252,7 +247,7 @@ impl SuperAdd { self.temp_crates.push(temp_crate); // Send the modified command - let cmd = Command::CargoAddCommand(modified_command); + let cmd = Command::Parse(modified_command); Self::write::(&Some(cmd)); return; } From 81ed92e8339981a9caeaac8691952d2dc06a59da Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Mon, 18 Aug 2025 07:41:52 +0100 Subject: [PATCH 3/3] cleanup --- script_examples/super_add/src/main.rs.bkp | 94 ----------------------- 1 file changed, 94 deletions(-) delete mode 100644 script_examples/super_add/src/main.rs.bkp diff --git a/script_examples/super_add/src/main.rs.bkp b/script_examples/super_add/src/main.rs.bkp deleted file mode 100644 index 30233493..00000000 --- a/script_examples/super_add/src/main.rs.bkp +++ /dev/null @@ -1,94 +0,0 @@ -use irust_api::{Command, OutputEvent, Shutdown}; -use rscript::scripting::Scripter; -use rscript::{Hook, VersionReq}; -use std::env; -use std::fs; -use std::path::{Path, PathBuf}; - -fn copy_dir_to_temp(source: &Path) -> Result> { - // Create a unique temporary directory name - let temp_base = env::temp_dir(); - let temp_name = format!("temp_copy_{}", std::process::id()); - let temp_path = temp_base.join(temp_name); - - // Create the temporary directory - fs::create_dir_all(&temp_path)?; - - // Copy the source directory contents to temp directory - copy_dir_recursive(source, &temp_path)?; - - Ok(temp_path) -} - -fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<(), Box> { - if !dst.exists() { - fs::create_dir_all(dst)?; - } - - for entry in fs::read_dir(src)? { - let entry = entry?; - let src_path = entry.path(); - let dst_path = dst.join(entry.file_name()); - - if src_path.is_dir() { - copy_dir_recursive(&src_path, &dst_path)?; - } else { - fs::copy(&src_path, &dst_path)?; - } - } - - Ok(()) -} - -#[derive(Debug, Default)] -struct SuperAdd {} - -impl Scripter for SuperAdd { - fn name() -> &'static str { - "SuperAdd" - } - - fn script_type() -> rscript::ScriptType { - rscript::ScriptType::Daemon - } - - fn hooks() -> &'static [&'static str] { - &[OutputEvent::NAME] - } - - fn version_requirement() -> rscript::VersionReq { - VersionReq::parse(">=1.50.0").expect("correct version requirement") - } -} - -fn main() { - let _ = SuperAdd::execute(&mut |hook_name| SuperAdd::run(&mut SuperAdd {}, hook_name)); -} - -impl SuperAdd { - fn run(&mut self, hook_name: &str) { - match hook_name { - OutputEvent::NAME => { - let hook: OutputEvent = Self::read(); - let input = hook.1; - if input.starts_with(":add") && input.contains("--path") { - let path = input - .split("--path") - .last() - .expect("path argument not found"); - // copy the directory in path to a temp directory - - let copy_dep = copy_dir_to_temp(&std::path::PathBuf::from(path)) - .expect("failed to copy directory"); - } else { - Self::write(&None); - } - } - _ => unreachable!(), - } - } - - fn clean_up(&self, _hook: Shutdown) -> Option { - None - } -}