Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add Support for Just #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions zee-grammar/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,19 @@ pub fn fetch_and_build_tree_sitter_parsers(
mode_configs.into_par_iter().try_for_each(|config| {
if let Some(ref grammar) = config.grammar {
let fetched = fetch_grammar(grammar)?;
let built = build_grammar(grammar, defaults)?;
let built = build_grammar(
grammar,
defaults,
match &config.grammar {
Some(cfg) => match &cfg.source {
GrammarSource::Git {
scheme_dir: scm, ..
} => scm,
_ => &None,
},
None => &None,
},
)?;
log::info!(
"{:>12} {} grammar {}",
if fetched || built {
Expand Down Expand Up @@ -142,7 +154,11 @@ fn fetch_grammar(grammar: &GrammarConfig) -> Result<bool> {
Ok(revision_changed)
}

fn build_grammar(grammar: &GrammarConfig, defaults: &Dir) -> Result<bool> {
fn build_grammar(
grammar: &GrammarConfig,
defaults: &Dir,
scheme_dir: &Option<String>,
) -> Result<bool> {
let (grammar_dir, subpath) = match grammar.source {
GrammarSource::Local { ref path } => (path.clone(), None),
GrammarSource::Git {
Expand All @@ -169,7 +185,7 @@ fn build_grammar(grammar: &GrammarConfig, defaults: &Dir) -> Result<bool> {
bail!("Directory {grammar_dir:?} is empty.",);
};

copy_tree_sitter_queries(&grammar.grammar_id, &grammar_dir, defaults)?;
copy_tree_sitter_queries(&grammar.grammar_id, &grammar_dir, defaults, scheme_dir)?;

// Build the tree sitter library
let paths = TreeSitterPaths::new(grammar_dir.clone(), subpath);
Expand Down Expand Up @@ -347,7 +363,12 @@ fn tree_sitter_library_path(grammar_id: &str) -> Result<PathBuf> {
Ok(library_path)
}

fn copy_tree_sitter_queries(grammar_id: &str, source: &Path, defaults: &Dir) -> Result<()> {
fn copy_tree_sitter_queries(
grammar_id: &str,
source: &Path,
defaults: &Dir,
scheme_dir: &Option<String>,
) -> Result<()> {
let query_dir_dest = tree_sitter_query_dir(grammar_id)?;
std::fs::create_dir_all(&query_dir_dest).with_context(|| {
format!(
Expand Down Expand Up @@ -396,7 +417,12 @@ fn copy_tree_sitter_queries(grammar_id: &str, source: &Path, defaults: &Dir) ->
}

// Otherwise, copy it from the git repo, if available
let query_src = source.join(QUERY_DIR).join(query_filename);
let query_src = source
.join(match scheme_dir {
Some(dir) => dir,
None => QUERY_DIR,
})
.join(query_filename);
if query_src.exists() {
log_on_error(
grammar_id,
Expand Down
2 changes: 2 additions & 0 deletions zee-grammar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub enum GrammarSource {
remote: String,
#[serde(rename = "rev")]
revision: String,
#[serde(default, rename = "scm")]
scheme_dir: Option<String>,
path: Option<PathBuf>,
},
}
Expand Down
26 changes: 26 additions & 0 deletions zee/config/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,32 @@
),
),

// Just Build System
Mode(
name: "Just Build System",
scope: "source.justfile",
injection_regex: "just(file)?",
patterns: [
Name(".justfile"),
Name("justfile"),
],
comment: Some(Comment(token: "# ")),
indentation: Indentation(
width: 4,
unit: Space,
),
grammar: Some(
Grammar(
id: "just",
source: Git(
git: "https://github.com/IndianBoy42/tree-sitter-just",
rev: "8af0aab79854aaf25b620a52c39485849922f766",
scm: Some("queries/just"),
),
)
),
),

// Markdown
Mode(
name: "Markdown",
Expand Down