Skip to content

Commit

Permalink
server args, completions subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dfgordon committed Sep 21, 2024
1 parent 03cff30 commit 9be418b
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 4,809 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
TAG=$GITHUB_SHA
fi
mv ./target/$TARGET/release/a2kit$EXE ./a2kit$EXE
tar -czf ./artifacts/a2kit-$TARGET-$TAG.tar.gz completions a2kit$EXE
tar -czf ./artifacts/a2kit-$TARGET-$TAG.tar.gz a2kit$EXE
for i in ${SERVERS[@]}; do
mv ./target/$TARGET/release/${i}$EXE ./artifacts/${i}-${TARGET}$EXE
done
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.3.0] - 2024-09-21

### New Features

* Language server arguments to ease integration with Neovim
* Subcommand to generate shell completions

### Removed Features

* Shell completions will not be packaged with each release since they can be generated on the fly

## [3.2.0] - 2024-09-15

### Fixes
Expand Down
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "a2kit"
version = "3.2.0"
version = "3.3.0"
edition = "2021"
readme = "README.md"
license = "MIT"
Expand All @@ -11,11 +11,6 @@ homepage = "https://github.com/dfgordon/a2kit"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
clap = {version="4.5.2",features=["cargo"]}
clap_complete = "4.5.2"
regex = "1.10"

[dependencies]
log = "0.4.17"
glob = "0.3.1"
Expand All @@ -31,6 +26,7 @@ tree-sitter-merlin6502 = "3.0.0"
lsp-types = "0.95.0"
lsp-server = "0.7.6"
clap = {version="4.5.4",features=["cargo"]}
clap_complete = "4.5.4"
tempfile = "3.6.0"
json = "0.12"
serde = "1.0.116"
Expand Down
72 changes: 2 additions & 70 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,6 @@
use clap::ValueEnum;

include!("src/cli.rs");

const ALIASES: [(&str,&[&str]);4] = [
("(catalog)", &["(ls)","(dir)","(cat)"]),
("(delete)" , &["(del)","(era)"]),
("(tokenize)" , &["(tok)"]),
("(detokenize)" , &["(dtok)"])
];

fn refine_zsh(script: &str) -> String {
let aliases = std::collections::HashMap::from(ALIASES);
let eq_patt = regex::RegexBuilder::new(r"^'--(\w+)=\[").multi_line(true).build().expect("regex parsing error");
let alias_patt = regex::Regex::new(r"^\(\w+\)$").expect("regex parsing error");
let intermediate = eq_patt.replace_all(script, "'--$1+[");
let mut new_script = String::new();
let mut accum = String::new();
let mut curr_cmd = String::new();
let mut alias_list : &[&str] = aliases.get("(catalog)").unwrap();
for line in intermediate.lines() {
match alias_patt.find(line) {
Some(res) if aliases.contains_key(res.as_str()) => {
accum = line.to_string();
accum += "\n";
alias_list = aliases.get(res.as_str()).unwrap();
curr_cmd = res.as_str().to_string();
},
_ => {
if accum.len() > 0 {
accum += line;
accum += "\n";
if line==";;" {
new_script += &accum;
for alias in alias_list {
new_script += &accum.replace(&curr_cmd,alias);
}
accum = "".to_string();
}
} else {
new_script += line;
new_script += "\n";
}
}
}
}
return new_script;
}
// This was used for generating shell completions to be included with each release.
// We now provide a subcommand to generate them on the fly.

fn main() -> Result<(), std::io::Error> {
if std::env::var("DOCS_RS").is_err() {
let outdir = match std::env::var_os("CARGO_MANIFEST_DIR") {
None => return Ok(()),
Some(root) => std::path::Path::new(&root).join("completions"),
};

let mut cmd = build_cli();

for &shell in clap_complete::Shell::value_variants() {
clap_complete::generate_to(shell, &mut cmd, "a2kit", &outdir)?;
match shell {
clap_complete::Shell::Zsh => {
let s = std::fs::read(outdir.join("_a2kit")).expect("zsh completions missing");
let script = String::from_utf8(s).expect("clap_complete output not UTF8");
let refined = refine_zsh(&script);
std::fs::write(outdir.join("_a2kit"),refined)?;
},
_ => {}
}
}
}

Ok(())
}
5 changes: 0 additions & 5 deletions completions/README.md

This file was deleted.

Loading

0 comments on commit 9be418b

Please sign in to comment.