From 74dc51b3edc588af9b24b410456ae557fe5d5f1d Mon Sep 17 00:00:00 2001 From: Irevoire Date: Sat, 8 Jan 2022 05:43:48 +0100 Subject: [PATCH] feat(tree-sitter): enable tree-sitter for .zshrc and .bashrc --- helix-core/src/syntax.rs | 9 +++++++-- languages.toml | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 5d37c219dd25..7da434891a4f 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -308,8 +308,13 @@ impl Loader { .and_then(|n| n.to_str()) .and_then(|file_name| self.language_config_ids_by_file_type.get(file_name)) .or_else(|| { - path.extension() - .and_then(|extension| extension.to_str()) + // we can't use the `extension` methods here because it ignore + // empty file name with only an extension like `.bashrc`. + path.file_name() + .map(|file_name| file_name.to_str()) + .flatten() + .map(|file_name| file_name.rsplit('.').next()) + .flatten() .and_then(|extension| self.language_config_ids_by_file_type.get(extension)) }); diff --git a/languages.toml b/languages.toml index 3e2e7b15c730..0f622dffd5f5 100644 --- a/languages.toml +++ b/languages.toml @@ -212,8 +212,8 @@ indent = { tab-width = 2, unit = " " } name = "bash" scope = "source.bash" injection-regex = "bash" -file-types = ["sh", "bash"] -shebangs = ["sh", "bash", "dash"] +file-types = ["sh", "bash", "zsh", "bashrc", "zshrc"] +shebangs = ["sh", "bash", "dash", "zsh"] roots = [] comment-token = "#"