Skip to content

Commit a5a667c

Browse files
authored
Merge pull request #10 from knitli/feat-integrate-ast-grep
minor fixes to language to fix a few issues
2 parents 9a06970 + 9586984 commit a5a667c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

crates/language/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ use thread_utils::RapidMap;
107107
pub use thread_ast_engine::language::Language;
108108
pub use thread_ast_engine::tree_sitter::LanguageExt;
109109

110+
const BASH_EXTENSION_PATTERN: [&str; 19] = [
111+
"bash", "bats", "sh", ".bashrc", "bash_aliases", "bats", "cgi", "command", "env",
112+
"fcgi", "ksh", "tmux", "tool", "zsh", "bash_logout", "bash_profile", "profile",
113+
"login", "logout"
114+
];
115+
110116
/// Implements standard [`Language`] and [`LanguageExt`] traits for languages that accept `$` in identifiers.
111117
///
112118
/// Used for languages like JavaScript, Python, and Rust where `$` can appear in variable names
@@ -781,7 +787,7 @@ macro_rules! execute_lang_method {
781787
S::Scala => Scala.$method($($pname,)*),
782788
#[cfg(feature = "swift")]
783789
S::Swift => Swift.$method($($pname,)*),
784-
#[cfg(feature = "typescript")]
790+
#[cfg(feature = "tsx")]
785791
S::Tsx => Tsx.$method($($pname,)*),
786792
#[cfg(feature = "typescript")]
787793
S::TypeScript => TypeScript.$method($($pname,)*),
@@ -835,9 +841,7 @@ const fn extensions(lang: SupportLang) -> &'static [&'static str] {
835841
use SupportLang::*;
836842
match lang {
837843
#[cfg(feature = "bash")]
838-
Bash => &[
839-
"bash", "bats", "cgi", "command", "env", "fcgi", "ksh", "sh", "tmux", "tool", "zsh",
840-
],
844+
Bash => &BASH_EXTENSION_PATTERN,
841845
#[cfg(feature = "c")]
842846
C => &["c", "h"],
843847
#[cfg(feature = "cpp")]
@@ -890,16 +894,15 @@ const fn extensions(lang: SupportLang) -> &'static [&'static str] {
890894
/// N.B do not confuse it with `FromStr` trait. This function is to guess language from file extension.
891895
fn from_extension(path: &Path) -> Option<SupportLang> {
892896
let ext = path.extension()?.to_str()?;
893-
897+
#[cfg(feature = "bash")]
898+
if BASH_EXTENSION_PATTERN.contains(&ext) {
899+
return Some(SupportLang::Bash)
900+
}
894901
// Fast path: try most common extensions first
895902
match ext {
896-
#[cfg(feature = "bash")]
897-
"bash" | "sh" | ".bashrc" | "bash_aliases" | "bats" | "cgi" | "command" | "env" | "fcgi" | "ksh" | "tmux" | "tool" | "zsh" | "bash_logout" | "bash_profile" | "profile" | "login" | "logout" => {
898-
return Some(SupportLang::Bash)
899-
}
900903
#[cfg(feature = "c")]
901904
"c" | "h" => return Some(SupportLang::C),
902-
#[cfg(feature = "csharp")]
905+
#[cfg(feature = "cpp")]
903906
"cpp" | "cc" | "cxx" => return Some(SupportLang::Cpp),
904907
#[cfg(feature = "css")]
905908
"css" => return Some(SupportLang::Css),

0 commit comments

Comments
 (0)