From 3a62b2223782a4111146c158af413606b821ded9 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:50:37 -0800 Subject: [PATCH] Add candid assist feature (#83) * add candid assist * use console * fix * fix * fix * readme --- Cargo.lock | 361 ++++++++++++++++++++++++++++---------------- Cargo.toml | 6 +- README.md | 14 +- src/command.rs | 9 +- src/exp.rs | 42 +++++- src/grammar.lalrpop | 8 +- src/helper.rs | 19 ++- src/main.rs | 5 +- src/token.rs | 2 + 9 files changed, 301 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8d885f..47c6954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,9 +56,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -91,15 +91,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.5" @@ -150,9 +141,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arbitrary" @@ -358,9 +349,9 @@ dependencies = [ [[package]] name = "candid" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d08367fb008cba20d2fe6e5c774aba244e087ac02d3887b72b039106b859fa0" +checksum = "39be580be172631a35cac2fc6c765f365709de459edb88121b3e7a80cce6c1ec" dependencies = [ "anyhow", "binread", @@ -388,20 +379,23 @@ dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] name = "candid_parser" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4756982955984c41f4652a265091725c88ff4ccf4e390d0a36edd08387b28f" +checksum = "36381de3ba8a312deb028552c0d63f7c7fe6e204f44bae4c58a3643308cfa9d5" dependencies = [ "anyhow", "arbitrary", "candid", "codespan-reporting", + "console", "convert_case", + "ctrlc", + "dialoguer", "fake", "hex", "lalrpop", @@ -433,9 +427,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.11" +version = "4.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" dependencies = [ "clap_builder", "clap_derive", @@ -443,9 +437,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.11" +version = "4.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" dependencies = [ "anstream", "anstyle", @@ -462,7 +456,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -502,6 +496,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.45.0", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -562,9 +569,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" +checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" dependencies = [ "cfg-if", "crossbeam-utils", @@ -572,9 +579,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" +checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" dependencies = [ "cfg-if", ] @@ -607,6 +614,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctrlc" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b467862cc8610ca6fc9a1532d7777cee0804e678ab45410897b9396495994a0b" +dependencies = [ + "nix", + "windows-sys 0.52.0", +] + [[package]] name = "curve25519-dalek-ng" version = "4.1.1" @@ -658,9 +675,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] @@ -707,6 +724,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dialoguer" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" +dependencies = [ + "console", + "shell-words", + "tempfile", + "thiserror", +] + [[package]] name = "diff" version = "0.1.13" @@ -839,9 +868,9 @@ dependencies = [ [[package]] name = "elsa" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714f766f3556b44e7e4776ad133fcc3445a489517c25c704ace411bb14790194" +checksum = "d98e71ae4df57d214182a2e5cb90230c0192c6ddfcaa05c36453d46a54713e10" dependencies = [ "stable_deref_trait", ] @@ -855,6 +884,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.33" @@ -894,9 +929,9 @@ checksum = "281e452d3bad4005426416cdba5ccfd4f5c1280e10099e21db27f7c1c28347fc" [[package]] name = "fake" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26221445034074d46b276e13eb97a265ebdb8ed8da705c4dddd3dd20b66b45d2" +checksum = "1c25829bde82205da46e1823b2259db6273379f626fc211f126f65654a2669be" dependencies = [ "deunicode", "rand", @@ -908,11 +943,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fd-lock" -version = "4.0.1" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93f7a0db71c99f68398f80653ed05afb0b00e062e1a20c7ff849c4edfabbbcc" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" dependencies = [ "cfg-if", "rustix", @@ -921,9 +962,9 @@ dependencies = [ [[package]] name = "fdeflate" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868" +checksum = "209098dd6dfc4445aa6111f0e98653ac323eaa4dfd212c9ca3931bf9955c31bd" dependencies = [ "simd-adler32", ] @@ -981,53 +1022,53 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", "futures-io", @@ -1235,9 +1276,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -1250,7 +1291,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -1338,15 +1379,15 @@ dependencies = [ [[package]] name = "ic-repl" -version = "0.6.1" +version = "0.6.2" dependencies = [ - "ansi_term", "anyhow", "base64", "candid", "candid_parser", "clap", "codespan-reporting", + "console", "crc32fast", "hex", "ic-agent", @@ -1372,7 +1413,6 @@ dependencies = [ "serde_json", "sha2 0.10.8", "shellexpand", - "terminal_size", "tokio", ] @@ -1519,13 +1559,13 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1712,7 +1752,7 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax 0.6.29", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -1726,9 +1766,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1874,9 +1914,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -2025,7 +2065,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2162,9 +2202,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" dependencies = [ "unicode-ident", ] @@ -2198,9 +2238,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2314,9 +2354,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ "base64", "bytes", @@ -2515,7 +2555,7 @@ checksum = "e5af959c8bf6af1aff6d2b463a57f71aae53d1332da58419e30ad8dc7011d951" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2556,18 +2596,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" dependencies = [ "serde", ] @@ -2584,13 +2624,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2608,9 +2648,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "6fbd975230bada99c8bb618e0c365c2eefa219158d5c6c29610fd09ff1833257" dependencies = [ "itoa", "ryu", @@ -2619,13 +2659,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2664,6 +2704,12 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shellexpand" version = "3.1.0" @@ -2731,16 +2777,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -2842,9 +2878,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" dependencies = [ "proc-macro2", "quote", @@ -2872,6 +2908,19 @@ dependencies = [ "libc", ] +[[package]] +name = "tempfile" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "term" version = "0.7.0" @@ -2892,41 +2941,31 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" -dependencies = [ - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -2944,9 +2983,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] @@ -2977,9 +3016,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -2989,7 +3028,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -3002,7 +3041,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3216,7 +3255,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", "wasm-bindgen-shared", ] @@ -3250,7 +3289,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3336,6 +3375,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3354,6 +3402,21 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -3384,6 +3447,12 @@ dependencies = [ "windows_x86_64_msvc 0.52.0", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -3396,6 +3465,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -3408,6 +3483,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -3420,6 +3501,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -3432,6 +3519,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -3444,6 +3537,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -3456,6 +3555,12 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -3486,22 +3591,22 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zerocopy" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d1d015b..8b2dbb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ic-repl" -version = "0.6.1" +version = "0.6.2" authors = ["DFINITY Team"] edition = "2021" default-run = "ic-repl" @@ -18,9 +18,8 @@ candid = { version = "0.10", features = ["all"] } candid_parser = { version = "0.1", features = ["all"] } rustyline = "13.0" rustyline-derive = "0.10" -ansi_term = "0.12" +console = "0.15" pretty_assertions = "1.4" -terminal_size = "0.3" codespan-reporting = "0.11" pretty = "0.12" pem = "3.0" @@ -47,4 +46,3 @@ qrcode = "0.13" image = { version = "0.24", default-features = false, features = ["png"] } libflate = "2.0" base64 = "0.21" - diff --git a/README.md b/README.md index 87d8d1a..04bcb5e 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,13 @@ ic-repl [--replica [local|ic|url] | --offline [--format [json|ascii|png]]] --con | identity ( | record { slot_index = ; key_id = })? // switch to identity , with optional pem file or HSM config | function ( ,* ) { ;* } // define a function := - | // any candid value - | * // variable with optional transformers - | fail // convert error message as text - | call (as )? . ( ,* ) // call a canister method, and store the result as a single value - | encode ( . )? ( ,* ) // encode candid arguments as a blob value. canister.__init_args represents init args - | decode (as . )? // decode blob as candid values - | ( ,* ) // function application + | // any candid value + | * // variable with optional transformers + | fail // convert error message as text + | call (as )? . (( ,* ))? // call a canister method, and store the result as a single value + | encode ( . )? (( ,* ))? // encode candid arguments as a blob value. canister.__init_args represents init args + | decode (as . )? // decode blob as candid values + | ( ,* ) // function application := | // variable name | _ // previous eval of exp is bind to `_` diff --git a/src/command.rs b/src/command.rs index a6e0aff..37a53e3 100644 --- a/src/command.rs +++ b/src/command.rs @@ -10,7 +10,6 @@ use pretty_assertions::{assert_eq, assert_ne}; use std::ops::Range; use std::sync::Arc; use std::time::Instant; -use terminal_size::{terminal_size, Width}; #[derive(Debug, Clone)] pub struct Commands(pub Vec<(Command, Range)>); @@ -95,11 +94,7 @@ impl Command { let v = val.eval(helper)?; let duration = time.elapsed(); bind_value(helper, "_".to_string(), v, is_call, true); - let width = if let Some((Width(w), _)) = terminal_size() { - w as usize - } else { - 80 - }; + let width = console::Term::stdout().size().1 as usize; println!("{:>width$}", format!("({duration:.2?})"), width = width); } Command::Identity(id, config) => { @@ -157,9 +152,7 @@ impl Command { let path = resolve_path(&std::env::current_dir()?, &file); let file = std::fs::File::create(path)?; let mut writer = BufWriter::new(&file); - //for item in helper.history.iter() { for (id, val) in helper.env.0.iter() { - //writeln!(&mut writer, "{};", item)?; writeln!(&mut writer, "let {id} = {val};")?; } } diff --git a/src/exp.rs b/src/exp.rs index 78f5a99..0066392 100644 --- a/src/exp.rs +++ b/src/exp.rs @@ -21,7 +21,7 @@ pub enum Exp { AnnVal(Box, Type), Call { method: Option, - args: Vec, + args: Option>, mode: CallMode, }, Decode { @@ -403,11 +403,15 @@ impl Exp { args_to_value(args) } Exp::Call { method, args, mode } => { - let mut res = Vec::with_capacity(args.len()); - for arg in args.into_iter() { - res.push(arg.eval(helper)?); - } - let args = IDLArgs { args: res }; + let args = if let Some(args) = args { + let mut res = Vec::with_capacity(args.len()); + for arg in args.into_iter() { + res.push(arg.eval(helper)?); + } + Some(IDLArgs { args: res }) + } else { + None + }; let opt_info = if let Some(method) = &method { let is_encode = matches!(mode, CallMode::Encode); Some(method.get_info(helper, is_encode)?) @@ -419,9 +423,33 @@ impl Exp { .. }) = &opt_info { + let args = if let Some(args) = args { + args + } else { + use candid_parser::assist::{input_args, Context}; + let mut ctx = Context::new(env.clone()); + let principals = helper.env.dump_principals(); + let mut completion = BTreeMap::new(); + completion.insert("principal".to_string(), principals); + ctx.set_completion(completion); + let args = input_args(&ctx, &func.args)?; + // Ideally, we should store the args in helper and call editor.readline_with_initial to display + // the full command in the editor. The tricky part is to know where to insert the args in text. + eprintln!("Generated arguments: {}", args); + eprintln!("Do you want to send this message? [y/N]"); + let mut input = String::new(); + std::io::stdin().read_line(&mut input)?; + if !["y", "yes"].contains(&input.to_lowercase().trim()) { + return Err(anyhow!("Abort")); + } + args + }; args.to_bytes_with_types(env, &func.args)? } else { - args.to_bytes()? + if args.is_none() { + return Err(anyhow!("cannot get method type, please provide arguments")); + } + args.unwrap().to_bytes()? }; match mode { CallMode::Encode => IDLValue::Blob(bytes), diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index b9836e4..2c095a8 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -27,6 +27,7 @@ extern { "service" => Token::Service, "oneway" => Token::Oneway, "query" => Token::Query, + "composite_query" => Token::CompositeQuery, "blob" => Token::Blob, "type" => Token::Type, "import" => Token::Import, @@ -96,9 +97,9 @@ pub Exp: Exp = { Arg => <>, Variable => <>, "fail" => Exp::Fail(Box::new(<>)), - "call" => Exp::Call{method:Some(method), args, mode: CallMode::Call}, - "call" "as" => Exp::Call{method:Some(method), args, mode: CallMode::Proxy(proxy)}, - "encode" => Exp::Call{method, args, mode: CallMode::Encode}, + "call" => Exp::Call{method:Some(method), args, mode: CallMode::Call}, + "call" "as" => Exp::Call{method:Some(method), args, mode: CallMode::Proxy(proxy)}, + "encode" => Exp::Call{method, args, mode: CallMode::Encode}, "decode" )?> => Exp::Decode{method, blob:Box::new(blob)}, "(" > ")" => Exp::Apply(func, args), } @@ -329,6 +330,7 @@ MethTyp: Binding = { FuncMode: FuncMode = { "oneway" => FuncMode::Oneway, "query" => FuncMode::Query, + "composite_query" => FuncMode::CompositeQuery, } // Also allows trailing separator diff --git a/src/helper.rs b/src/helper.rs index 97e97ca..77c2ee5 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -1,7 +1,6 @@ use crate::exp::Exp; use crate::token::{Token, Tokenizer}; use crate::utils::{random_value, str_to_principal}; -use ansi_term::Color; use candid::{ types::value::{IDLField, IDLValue, VariantValue}, types::{Function, Label, Type, TypeInner}, @@ -90,7 +89,6 @@ pub struct MyHelper { pub env: Env, pub func_env: FuncEnv, pub base_path: std::path::PathBuf, - pub history: Vec, pub messages: RefCell>, } @@ -102,7 +100,6 @@ impl MyHelper { hinter: HistoryHinter {}, colored_prompt: "".to_owned(), validator: MatchingBracketValidator::new(), - history: Vec::new(), config: Configs::from_dhall("{=}").unwrap(), canister_map: self.canister_map.clone(), identity_map: self.identity_map.clone(), @@ -130,7 +127,6 @@ impl MyHelper { env: Env::default(), func_env: FuncEnv::default(), base_path: std::env::current_dir().unwrap(), - history: Vec::new(), messages: Vec::new().into(), agent, agent_url, @@ -448,7 +444,7 @@ impl Highlighter for MyHelper { } fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { - let s = format!("{}", Color::White.dimmed().paint(hint)); + let s = format!("{}", console::style(hint).black().bright()); Owned(s) } @@ -577,6 +573,19 @@ pub fn find_init_args(env: &TypeEnv, actor: &Type) -> Option> { } } +impl Env { + pub fn dump_principals(&self) -> BTreeMap { + self.0 + .iter() + .filter_map(|(name, value)| match value { + IDLValue::Principal(id) => Some((name, id)), + _ => None, + }) + .map(|(name, id)| (name.clone(), id.to_text())) + .collect() + } +} + #[test] fn test_partial_parse() -> anyhow::Result<()> { use candid_parser::parse_idl_value; diff --git a/src/main.rs b/src/main.rs index 5f5d552..e4780bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use ansi_term::Color; use clap::Parser; use ic_agent::agent::http_transport::ReqwestTransport; use ic_agent::Agent; @@ -93,14 +92,14 @@ fn repl(opts: Opts) -> anyhow::Result<()> { loop { let identity = &rl.helper().unwrap().current_identity; let p = format!("{identity}@{replica} {count}> "); - rl.helper_mut().unwrap().colored_prompt = format!("{}", Color::Green.bold().paint(&p)); + rl.helper_mut().unwrap().colored_prompt = + format!("{}", console::style(&p).green().bold()); let input = rl.readline(&p); match input { Ok(line) => { rl.add_history_entry(&line)?; unwrap(pretty_parse::("stdin", &line), |cmd| { let helper = rl.helper_mut().unwrap(); - helper.history.push(line.clone()); unwrap(cmd.run(helper), |_| {}); }); } diff --git a/src/token.rs b/src/token.rs index c70cff0..3380aaf 100644 --- a/src/token.rs +++ b/src/token.rs @@ -49,6 +49,8 @@ pub enum Token { Oneway, #[token("query")] Query, + #[token("composite_query")] + CompositeQuery, #[token("blob")] Blob, #[token("type")]