Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
(wip) Query refactor #249
Browse files Browse the repository at this point in the history
  • Loading branch information
hadronized committed Apr 14, 2024
1 parent 8bad5cf commit bc9826b
Show file tree
Hide file tree
Showing 17 changed files with 813 additions and 614 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ktsctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ kak-tree-sitter-config = { version = "0.4.0-dev", path = "../kak-tree-sitter-con
log = "0.4.21"
simple_logger = "4.3.3"
thiserror = "1.0.57"
unicode-segmentation = "1.11.0"
2 changes: 1 addition & 1 deletion ktsctl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum Cmd {
},

/// Get information on installed resources.
Info {
Query {
/// Get information about a specific language.
#[clap(short, long)]
lang: Option<String>,
Expand Down
45 changes: 21 additions & 24 deletions ktsctl/src/commands/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
error::HellNo,
git,
process::Process,
report::{Report, ReportIcon},
resources::Resources,
ui::{report::Report, status_icon::StatusIcon},
};

/// Main flags to fetch, compile and/or install resources.
Expand Down Expand Up @@ -81,7 +81,7 @@ impl Manager {
match lang_config.grammar.source {
Source::Local { ref path } => {
Report::new(
ReportIcon::Info,
StatusIcon::Info,
format!(
"using local grammar {lang} at {path}",
path = path.display()
Expand All @@ -105,13 +105,13 @@ impl Manager {
let sources_path = self.resources.sources_dir(url);

if self.flags.sync {
let report = Report::new(ReportIcon::Sync, format!("syncing {lang} grammar"));
let report = Report::new(StatusIcon::Sync, format!("syncing {lang} grammar"));
self.sync_git_grammar(&report, lang, lang_config, &sources_path, url, pin)?;
return Ok(());
}

if self.flags.fetch {
let report = Report::new(ReportIcon::Fetch, format!("cloning {lang} grammar…"));
let report = Report::new(StatusIcon::Fetch, format!("cloning {lang} grammar…"));
Self::git_clone(&report, lang, &sources_path, url, pin)?;
report.success(format!("cloned {lang} grammar"));
}
Expand All @@ -121,13 +121,13 @@ impl Manager {
.lang_build_dir(&sources_path, &lang_config.grammar.path);

if self.flags.compile {
let report = Report::new(ReportIcon::Compile, format!("compiling {lang} grammar"));
let report = Report::new(StatusIcon::Compile, format!("compiling {lang} grammar"));
Self::compile_git_grammar(&report, lang, lang_config, &lang_build_dir)?;
report.success(format!("built {lang} grammar"));
}

if self.flags.install {
let report = Report::new(ReportIcon::Install, format!("installing {lang} grammar"));
let report = Report::new(StatusIcon::Install, format!("installing {lang} grammar"));
self.install_git_grammar(&report, lang, &lang_build_dir, pin)?;
report.success(format!("installed {lang} grammar"));
}
Expand All @@ -149,14 +149,14 @@ impl Manager {
return Ok(());
}

Self::git_clone(&report, lang, fetch_path, url, pin)?;
Self::git_clone(report, lang, fetch_path, url, pin)?;

let lang_build_dir = self
.resources
.lang_build_dir(fetch_path, &lang_config.grammar.path);

Self::compile_git_grammar(&report, lang, lang_config, &lang_build_dir)?;
self.install_git_grammar(&report, lang, &lang_build_dir, pin)?;
Self::compile_git_grammar(report, lang, lang_config, &lang_build_dir)?;
self.install_git_grammar(report, lang, &lang_build_dir, pin)?;

report.success(format!("synchronized {lang} grammar"));
Ok(())
Expand All @@ -169,7 +169,7 @@ impl Manager {
url: &str,
pin: &str,
) -> Result<(), HellNo> {
let cloned = git::clone(&report, lang, fetch_path, url)?;
let cloned = git::clone(report, fetch_path, url)?;

if let git::Clone::Cloned = cloned {
report.success(format!(
Expand All @@ -194,7 +194,7 @@ impl Manager {
lang_build_dir: &Path,
) -> Result<(), HellNo> {
// ensure the build dir exists
fs::create_dir_all(&lang_build_dir).map_err(|err| HellNo::CannotCreateDir {
fs::create_dir_all(lang_build_dir).map_err(|err| HellNo::CannotCreateDir {
dir: lang_build_dir.to_owned(),
err,
})?;
Expand All @@ -213,7 +213,7 @@ impl Manager {
report.info(format!("compiled {lang} grammar"));

// link into {lang}.so
let report = Report::new(ReportIcon::Link, format!("linking {lang} grammar",));
let report = Report::new(StatusIcon::Link, format!("linking {lang} grammar",));
let args: Vec<_> = lang_config
.grammar
.link_args
Expand All @@ -234,8 +234,6 @@ impl Manager {
lang_build_dir: &Path,
pin: &str,
) -> Result<(), HellNo> {
let report = Report::new(ReportIcon::Install, format!("installing {lang} grammar"));

let lang_so = format!("{lang}.so");
let source_path = lang_build_dir.join(lang_so);
let grammar_dir = self.resources.data_dir().join(format!("grammars/{lang}"));
Expand All @@ -260,7 +258,7 @@ impl Manager {
match lang_config.queries.source {
Some(Source::Local { ref path }) => {
Report::new(
ReportIcon::Info,
StatusIcon::Info,
format!(
"using local queries {lang} at {path}",
path = path.display()
Expand All @@ -269,12 +267,12 @@ impl Manager {
}

Some(Source::Git { ref url, ref pin }) => {
self.manage_git_queries(lang, &lang_config, url, pin)?
self.manage_git_queries(lang, lang_config, url, pin)?
}

None => {
Report::new(
ReportIcon::Error,
StatusIcon::Info,
format!("no query configuration for {lang}; will be using the grammar directory"),
);
}
Expand All @@ -293,19 +291,19 @@ impl Manager {
let sources_path = self.resources.sources_dir(url);

if self.flags.sync {
let report = Report::new(ReportIcon::Sync, format!("syncing {lang} queries"));
let report = Report::new(StatusIcon::Sync, format!("syncing {lang} queries"));
self.sync_git_queries(&report, lang, lang_config, &sources_path, url, pin)?;
report.success(format!("synchronized {lang} queries"));
return Ok(());
}

if self.flags.fetch {
let report = Report::new(ReportIcon::Fetch, format!("cloning {lang} queries"));
let report = Report::new(StatusIcon::Fetch, format!("cloning {lang} queries"));
Self::git_clone(&report, lang, &sources_path, url, pin)?;
}

if self.flags.install {
let report = Report::new(ReportIcon::Install, format!("installing {lang} queries"));
let report = Report::new(StatusIcon::Install, format!("installing {lang} queries"));
let query_dir = sources_path.join(&lang_config.queries.path);
self.install_git_queries(&report, &query_dir, lang, pin)?;
}
Expand All @@ -327,11 +325,11 @@ impl Manager {
return Ok(());
}

Self::git_clone(&report, lang, fetch_path, url, pin)?;
Self::git_clone(report, lang, fetch_path, url, pin)?;

let path = &lang_config.queries.path;
let query_dir = fetch_path.join(path);
self.install_git_queries(&report, &query_dir, lang, pin)?;
self.install_git_queries(report, &query_dir, lang, pin)?;

report.success(format!("synchronized {lang} grammar"));
Ok(())
Expand All @@ -345,8 +343,7 @@ impl Manager {
pin: &str,
) -> Result<(), HellNo> {
// ensure the queries directory exists
let install_path = self.resources.queries_dir(lang, pin);
let report = Report::new(ReportIcon::Install, format!("installing {lang} queries"));
let install_path = self.resources.queries_pin_dir(lang, pin);

fs::create_dir_all(&install_path).map_err(|err| HellNo::CannotCreateDir {
dir: install_path.clone(),
Expand Down
Loading

0 comments on commit bc9826b

Please sign in to comment.