Add basic autocomplete
This commit is contained in:
parent
df610c7e03
commit
296ac24d81
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -144,6 +144,8 @@ dependencies = [
|
||||
"rand",
|
||||
"regex",
|
||||
"shellwords",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -283,6 +285,12 @@ version = "0.6.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0a5f7c728f5d284929a1cccb5bc19884422bfe6ef4d6c409da2c41838983fcf"
|
||||
|
||||
[[package]]
|
||||
name = "shellwords"
|
||||
version = "1.1.0"
|
||||
@ -299,6 +307,28 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.24.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4faebde00e8ff94316c01800f9054fd2ba77d30d9e922541913051d1d978918b"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
|
@ -41,6 +41,8 @@ evalexpr = "7"
|
||||
kakplugin = {path = "./kakplugin/"}
|
||||
linked-hash-map = "0.5.4"
|
||||
linked_hash_set = "0.1.4"
|
||||
strum_macros = "0.24"
|
||||
strum = { version = "0.24", features = ["derive"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
@ -212,3 +212,24 @@ pub fn get_var(var_name: &str) -> Result<String, KakError> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Prints a list of shell script candidates for kakoune to ingest
|
||||
pub fn generate_shell_script_candidates<S>(variants: &[S]) -> Result<(), KakError>
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
let token_to_complete = get_var("kak_token_to_complete")?.parse::<u8>()?;
|
||||
|
||||
match token_to_complete {
|
||||
0 => {
|
||||
for v in variants {
|
||||
println!("{}", v.as_ref());
|
||||
}
|
||||
}
|
||||
1_u8..=u8::MAX => {
|
||||
// We can't see which command was selected, so none of these will do anything
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
15
src/main.rs
15
src/main.rs
@ -21,6 +21,8 @@ mod utils;
|
||||
// mod xargs;
|
||||
use clap::{Parser, Subcommand};
|
||||
use kakplugin::{display_message, get_var, KakError};
|
||||
use std::env;
|
||||
use strum::VariantNames;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(about, version, author)]
|
||||
@ -34,7 +36,8 @@ struct Cli {
|
||||
// kak_response_fifo_name: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
#[derive(Subcommand, Debug, strum::EnumVariantNames)]
|
||||
#[strum(serialize_all = "kebab_case")]
|
||||
enum Commands {
|
||||
#[clap(about = "Sorts selections based on content or content regex match")]
|
||||
Sort(sort::Options),
|
||||
@ -57,6 +60,16 @@ enum Commands {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// First, check if we are just getting candidates to run the program. kak_command_fifo is not needed for this
|
||||
let args = env::args().collect::<Vec<_>>();
|
||||
if args.len() == 2 && args[1] == "shell-script-candidates" {
|
||||
match kakplugin::generate_shell_script_candidates(Commands::VARIANTS) {
|
||||
Err(e) => eprintln!("{e:?}"),
|
||||
Ok(()) => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if get_var("kak_command_fifo")
|
||||
.and(get_var("kak_response_fifo"))
|
||||
.is_err()
|
||||
|
Loading…
Reference in New Issue
Block a user