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

Add support for hidden_file_extensions key. #419

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/parsing/yaml_load.rs
Expand Up @@ -135,14 +135,17 @@ impl SyntaxDefinition {
top_level_scope,
);

let mut file_extensions = Vec::new();
for extension_key in &["file_extensions", "hidden_file_extensions"] {
if let Ok(v) = get_key(h, extension_key, |x| x.as_vec()) {
file_extensions.extend(v.iter().filter_map(|y| y.as_str().map(|s| s.to_owned())))
}
}

let defn = SyntaxDefinition {
name: get_key(h, "name", |x| x.as_str()).unwrap_or_else(|_| fallback_name.unwrap_or("Unnamed")).to_owned(),
scope: top_level_scope,
file_extensions: {
get_key(h, "file_extensions", |x| x.as_vec())
.map(|v| v.iter().filter_map(|y| y.as_str()).map(|x| x.to_owned()).collect())
.unwrap_or_else(|_| Vec::new())
},
file_extensions,
// TODO maybe cache a compiled version of this Regex
first_line_match: get_key(h, "first_line_match", |x| x.as_str())
.ok()
Expand Down Expand Up @@ -855,6 +858,7 @@ mod tests {
name: C
scope: source.c
file_extensions: [c, h]
hidden_file_extensions: [k, l]
hidden: true
variables:
ident: '[QY]+'
Expand Down Expand Up @@ -887,7 +891,7 @@ mod tests {
assert_eq!(defn2.name, "C");
let top_level_scope = Scope::new("source.c").unwrap();
assert_eq!(defn2.scope, top_level_scope);
let exts: Vec<String> = vec![String::from("c"), String::from("h")];
let exts: Vec<String> = vec!["c", "h", "k", "l"].into_iter().map(String::from).collect();
assert_eq!(defn2.file_extensions, exts);
assert!(defn2.hidden);
assert_eq!(defn2.variables.get("ident").unwrap(), "[QY]+");
Expand Down