{"record":{"id":"c7e210538d683f95","repo":"ast-grep/ast-grep","slug":"not-implemented-tree-sitter-parser-is-not-impleme","errorCode":null,"errorMessage":"not implemented: tree-sitter parser is not implemented when feature flag is off.","messagePattern":"not implemented: tree-sitter parser is not implemented when feature flag is off\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/language/src/parsers.rs","lineNumber":15,"sourceCode":"//! This mod maintains a list of tree-sitter parsers crate.\n//! When feature flag is on, this mod will import all dependent crates.\n//! However, tree-sitter bs cannot be compiled by wasm-pack.\n//! In this case, we can use a blank implementation by turning feature flag off.\n//! And use other implementation.\n\nmacro_rules! conditional_lang {\n  ($lang: ident, $flag: literal, $field: ident) => {{\n    #[cfg(feature=$flag)]\n    {\n      $lang::$field.into()\n    }\n    #[cfg(not(feature=$flag))]\n    {\n      unimplemented!(\"tree-sitter parser is not implemented when feature flag is off.\")\n    }\n  }};\n  ($lang: ident, $flag: literal) => {\n    conditional_lang!($lang, $flag, LANGUAGE)\n  };\n}\n\nuse ast_grep_core::tree_sitter::TSLanguage;\n\npub fn language_bash() -> TSLanguage {\n  conditional_lang!(tree_sitter_bash, \"tree-sitter-bash\")\n}\npub fn language_c() -> TSLanguage {\n  conditional_lang!(tree_sitter_c, \"tree-sitter-c\")\n}\npub fn language_cpp() -> TSLanguage {\n  conditional_lang!(tree_sitter_cpp, \"tree-sitter-cpp\")\n}","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/ast-grep/ast-grep/blob/fc2b1530db74de49131b725221de98036a552a9f/crates/language/src/parsers.rs#L1-L33","documentation":"The conditional_lang! macro in crates/language/src/parsers.rs expands to `unimplemented!(\"tree-sitter parser is not implemented when feature flag is off.\")` when the language's cargo feature is disabled. The language enum value cannot be constructed without its tree-sitter parser, so converting it panics instead of returning a compile-time or runtime error.","triggerScenarios":"Requesting a language (e.g. via from_str/into through the conditional_lang! macro) whose crate feature flag is not enabled in the build, such as using a custom-language or non-default language without the matching `feature` in Cargo.toml.","commonSituations":"Installing ast-grep with default features then writing rules for a language behind an opt-in feature; building a trimmed-down custom ast-grep (npx/scarb/custom builds) that excluded a parser; language registered in sgconfig.yml custom_languages but parser feature disabled.","solutions":["Enable the corresponding cargo feature for the language, e.g. `cargo install ast-grep --features <lang>` or add `features = [\"<lang>\"]` to the dependency in Cargo.toml, then rebuild.","If using a custom build, add the language's tree-sitter parser feature to the build configuration and reinstall.","Remove or gate rules/custom languages that target the disabled feature so the macro's enabled branch is used instead."],"exampleFix":"// before (Cargo.toml)\nast-grep = { version = \"0.x\", default-features = true }\n// after\nast-grep = { version = \"0.x\", features = [\"swift\"] } // enable the parser feature for the language you use","handlingStrategy":"validation","validationCode":"# check the feature is enabled before shipping rules for a language\ncargo metadata --no-deps --format-version 1 | jq '.packages[].features' | grep <lang>\n# or in build.rs / CI:\nif ! grep -q '\"<lang>\"' Cargo.toml; then echo \"language feature <lang> not enabled\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"// wrap language conversion so a panic becomes an error:\nlet lang = std::panic::catch_unwind(|| to_language(name))\n  .map_err(|_| anyhow!(\"language '{}' requires its tree-sitter feature flag enabled\", name));","preventionTips":["Enable the feature for every language your rules target in Cargo.toml / install flags.","For custom builds, keep the feature list in sync with custom_languages in sgconfig.yml.","Test the built binary against each configured language in CI."],"tags":["feature-flag","tree-sitter","unimplemented","build-config","panic"],"backgroundTag":"missing-feature-flag","analyzedSha":"fc2b1530db74de49131b725221de98036a552a9f","analyzedAt":"2026-09-05T18:06:27.540Z","contentChangedAt":"2026-09-05T18:06:27.540Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}