### Getting started: install Task, clone repo, setup, build, test Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/contributing.md Commands to set up the development environment: install Task on macOS, clone the repository, install language dependencies, build the Rust core, and run all tests. Requires Task, Rust stable, Python 3.10+ with uv, and Node.js 18+ with pnpm. ```bash # Install Task (macOS) brew install go-task # Clone the repository git clone https://github.com/xberg-io/tree-sitter-language-pack.git cd tree-sitter-language-pack # Install all language dependencies task setup # Build the Rust core task build # Run all tests task test ``` -------------------------------- ### installed_languages example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of listing installed languages. ```zig const result = instance.installed_languages(); ``` -------------------------------- ### Setup command: task setup Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/CONTRIBUTING.md Run this command to install dependencies and pre-commit hooks via poly. Requires Git, Rust stable (via rustup), and a C compiler (clang or gcc). ```bash task setup ``` -------------------------------- ### Quick start Kotlin example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/packages/kotlin-android/README.md Load the Python parser and process source code, printing the detected language and the number of functions found in the structure. ```kotlin import io.xberg.tslp.android.ProcessConfig import io.xberg.tslp.android.TreeSitterLanguagePack fun main() { val config = ProcessConfig(language = "python") val result = TreeSitterLanguagePack.process("def hello():\n print('world')\n", config) println("Language: ${result.language}") println("Functions: ${result.structure.size}") } ``` -------------------------------- ### init() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to init() with a default PackConfig. ```python init(PackConfig()) ``` -------------------------------- ### ts_pack_node_start_position example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_node_start_position. Returns the start Point as a TS_PACKAlefHandle. ```c TS_PACKAlefHandle result = ts_pack_node_start_position(instance); ``` -------------------------------- ### init() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-dart.md Example call to init() with a default PackConfig. ```dart init(PackConfig()); ``` -------------------------------- ### ts_pack_node_start_byte example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_node_start_byte. Returns the inclusive start byte offset as a uintptr_t. ```c uintptr_t result = ts_pack_node_start_byte(instance); ``` -------------------------------- ### Quick start Rust example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-core/README.md Shows how to load a Python parser, process source code, and access structure and metrics. Also demonstrates direct parser access with get_parser. Parsers are downloaded on first use and cached. ```rust use tree_sitter_language_pack::{ProcessConfig, get_parser, process}; fn main() -> Result<(), tree_sitter_language_pack::Error> { // Parsers are downloaded on first use and cached for every later call. let config = ProcessConfig::new("python").all(); let result = process("def hello():\n print('world')\n", &config)?; println!("Language: {}", result.language); println!("Functions: {}", result.structure.len()); println!("Lines: {}", result.metrics.total_lines); // Or drop down to the tree-sitter parser directly. let mut parser = get_parser("python")?; if let Some(tree) = parser.parse("def hello(): pass") { println!("{}", tree.root_node().to_sexp()); } Ok(()) } ``` -------------------------------- ### configure() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to configure() with a default PackConfig. ```python configure(PackConfig()) ``` -------------------------------- ### ts_pack_get_highlights_query() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to get the highlights query for a language. ```c const char* result = ts_pack_get_highlights_query("value"); ``` -------------------------------- ### new_download_manager example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of creating a download manager with a version string. ```zig const result = try new_download_manager("value"); ``` -------------------------------- ### configure() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-dart.md Example call to configure() with a default PackConfig. ```dart configure(PackConfig()); ``` -------------------------------- ### startPosition() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-java.md Returns the start Point (row, column) of the node. ```java public Point startPosition() throws TreeSitterLanguagePackRsException ``` ```java var result = instance.startPosition(); ``` -------------------------------- ### Node.StartPosition() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Returns the start Point (row, column) of the node. ```go func (o *Node) StartPosition() *Point ``` ```go result := instance.StartPosition() ``` -------------------------------- ### Node.StartByte() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Returns the inclusive start byte offset of the node as a uint. ```go func (o *Node) StartByte() uint ``` ```go result := instance.StartByte() ``` -------------------------------- ### download() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to download() with an empty list of names. ```python result = download([]) ``` -------------------------------- ### Quick Start TypeScript example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-core-node/README.md Process Python source code with the process function, returning language, structure, imports, and metrics. ```typescript import { ProcessConfig, process } from "@xberg-io/tree-sitter-language-pack"; function main() { const config: ProcessConfig = { language: "python" }; const result = process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config); console.log(result.language); console.log(result.structure); console.log(result.structure?.[0]?.kind); console.log(result.imports); console.log(result.metrics?.totalLines); console.log(result.metrics?.errorCount); } void main(); ``` -------------------------------- ### get_parser() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets a Parser pre-configured for the given language. Calls get_language and configures a new parser. Returns Error.LanguageNotFound or Error.ParserSetup on failure. The example uses try and the string "value". ```zig pub fn get_parser(name: []const u8) Error!Parser ``` ```zig const result = try get_parser("value"); ``` -------------------------------- ### Detect language from .py extension using detect_language_from_extension Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/python/language-detection/detect_ext_python.md Use detect_language_from_extension from tree_sitter_language_pack to get the language for a given file extension. This example passes 'py' and prints the result. The function is called directly without any setup or prerequisites. ```python from tree_sitter_language_pack import detect_language_from_extension def main() -> None: ext = "py" result = detect_language_from_extension(ext) print(result) main() ``` -------------------------------- ### ts_pack_init() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_init with a config handle. ```c ts_pack_init(0); ``` -------------------------------- ### Install plugin in GitHub Copilot CLI Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/ai-coding-assistants.md Install the plugin in GitHub Copilot CLI by adding the marketplace and then installing the plugin. ```text copilot plugin marketplace add https://github.com/xberg-io/tree-sitter-language-pack copilot plugin install tree-sitter-language-pack@tree-sitter-language-pack ``` -------------------------------- ### download_all/0 example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Example call to download_all/0, returning {:ok, result}. ```elixir {:ok, result} = download_all() ``` -------------------------------- ### ts-pack init examples Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/cli.mdx Examples of initializing with default settings and with a list of languages. After init, run ts-pack download to fetch the listed parsers. ```bash ts-pack init ts-pack init --languages python,javascript,typescript,rust ``` -------------------------------- ### StartPosition() method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-csharp.md Returns the start Point (row, column) of this node. ```csharp public Point StartPosition() ``` ```csharp var result = instance.StartPosition(); ``` -------------------------------- ### download() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-dart.md Example call to download() with an empty list of names. ```dart final result = download([]); ``` -------------------------------- ### DownloadManager.new() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example of creating a DownloadManager with a version string. ```python result = DownloadManager.new("value") ``` -------------------------------- ### LanguageRegistry.getLanguage() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-typescript.md Example of getting a language by name from a LanguageRegistry instance. ```typescript const result = instance.getLanguage("value"); ``` -------------------------------- ### ts_pack_get_tags_query() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to get the tags query for a language. ```c const char* result = ts_pack_get_tags_query("value"); ``` -------------------------------- ### init() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-java.md Initializes the language pack with the given configuration, applying custom cache directory and downloading all languages and groups. Recommended entry point to pre-warm the cache. Returns error if configuration cannot be applied or downloads fail. ```java public static void init(PackConfig config) throws TreeSitterLanguagePackRsException ``` ```java init(new PackConfig()); ``` -------------------------------- ### Install via cargo-binstall Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Install the prebuilt binary using cargo-binstall. ```sh cargo binstall ts-pack-cli ``` -------------------------------- ### prefetch() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Example call to prefetch() with an empty list of languages. ```kotlin prefetch([]) ``` -------------------------------- ### download_all_best_effort example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of downloading all libraries best-effort. ```zig const result = try instance.download_all_best_effort(); ``` -------------------------------- ### ts_pack_get_locals_query() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to get the locals query for a language. ```c const char* result = ts_pack_get_locals_query("value"); ``` -------------------------------- ### DownloadManager.installed_languages() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example of calling installed_languages() on a DownloadManager instance. ```python result = instance.installed_languages() ``` -------------------------------- ### ts_pack_get_injections_query() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to get the injections query for a language. ```c const char* result = ts_pack_get_injections_query("value"); ``` -------------------------------- ### get_parser signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Gets a Parser pre-configured for the given language. Calls get_language and configures a new parser in one step. Raises Error.LanguageNotFound if the language is not recognized, or Error.ParserSetup if the language cannot be applied to the parser. ```ruby def self.get_parser(name) ``` ```ruby result = get_parser("value") ``` -------------------------------- ### init_() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-swift.md Initializes the language pack with the given configuration. Applies custom cache directory and downloads all languages and groups specified in the config. Recommended entry point to pre-warm the cache before use. Throws an error if configuration cannot be applied or downloads fail. ```swift public static func init_(config: PackConfig) throws ``` ```swift try init_(PackConfig()) ``` -------------------------------- ### init() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Initializes the language pack with a given configuration, applying cache directory and downloading all languages and groups. Recommended for pre-warming the cache. ```elixir @spec init(config) :: {:ok, term()} | {:error, term()} def init(config) ``` ```elixir :ok = init(%{}) ``` -------------------------------- ### process() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-dart.md Example call to process() with a source string and a default ProcessConfig. ```dart final result = process("value", ProcessConfig()); ``` -------------------------------- ### startPosition() - Get start point Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-swift.md Returns the start Point (row, column) of the node. ```swift public func startPosition() -> Point ``` ```swift let result = instance.startPosition() ``` -------------------------------- ### start_position() - Get start point Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Returns the start Point (row, column) of the node. ```elixir def start_position(obj) ``` ```elixir {:ok, result} = instance.start_position() ``` -------------------------------- ### init() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Initialize the language pack with the given configuration. Applies any custom cache directory, then downloads all languages and groups specified in the config. This is the recommended entry point when you want to pre-warm the cache before use. Returns an error if configuration cannot be applied or if downloads fail. ```zig pub fn init(config: []const u8) Error!void ``` ```zig try init(.{}); ``` -------------------------------- ### Install PHP extension installer with Composer Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/getting-started/installation.mdx Install mlocati/php-extension-installer first so Composer can download and register the compiled .so/.dll. Requires PHP 8.2+. ```bash composer require mlocati/php-extension-installer ``` -------------------------------- ### LanguageRegistry.create() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-java.md Example call to the create() method. Returns a LanguageRegistry. ```java var result = LanguageRegistry.create(); ``` -------------------------------- ### GetParser signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Gets a Parser pre-configured for the given language. Convenience function that calls get_language and configures a new parser. Returns Error.LanguageNotFound if not recognized or Error.ParserSetup if the language cannot be applied. ```go func GetParser(name string) (*Parser, error) ``` ```go result, err := GetParser("value") if err != nil { return err } ``` -------------------------------- ### ts-pack init command examples Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/configuration.mdx Shows how to create a language-pack.toml interactively, with specific languages, or with a custom cache directory. ```bash # Interactive ts-pack init # With specific languages ts-pack init --languages python,javascript,typescript,rust # With custom cache directory ts-pack init --cache-dir ./local-cache --languages python ``` -------------------------------- ### startPosition() - Get start point Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Returns the start Point (row, column) as a Point. ```kotlin fun startPosition(): Point ``` ```kotlin val result = instance.startPosition() ``` -------------------------------- ### getHighlightsQuery() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Example call to getHighlightsQuery() with a sample language. ```kotlin val result = getHighlightsQuery("value") ``` -------------------------------- ### start_byte() - Get start byte offset Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Returns the inclusive start byte offset of the node. ```elixir def start_byte(obj) ``` ```elixir {:ok, result} = instance.start_byte() ``` -------------------------------- ### process() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Example call to process() with a simple source string and default ProcessConfig. ```kotlin val result = process("value", ProcessConfig()) ``` -------------------------------- ### Node#start_position() - Get start position Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Returns the start Point (row, column) of the node. ```ruby def start_position() ``` ```ruby result = instance.start_position() ``` -------------------------------- ### downloaded_languages/0 example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Example call to downloaded_languages/0, returning {:ok, result}. ```elixir {:ok, result} = downloaded_languages() ``` -------------------------------- ### clean_cache example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of cleaning the cache. ```zig try instance.clean_cache(); ``` -------------------------------- ### startByte() - Get start byte offset Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-swift.md Returns the inclusive start byte offset of the node as a UInt. ```swift public func startByte() -> UInt ``` ```swift let result = instance.startByte() ``` -------------------------------- ### process() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to process() with a source string and default ProcessConfig. ```python result = process("value", ProcessConfig()) ``` -------------------------------- ### startByte() - Get start byte offset Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Returns the inclusive start byte offset of this node as a Long. ```kotlin fun startByte(): Long ``` ```kotlin val result = instance.startByte() ``` -------------------------------- ### new_parser() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of constructing a new parser using new_parser(). ```zig const result = new_parser(); ``` -------------------------------- ### Init method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-csharp.md Init initializes the language pack with the given configuration, applying a custom cache directory and downloading all languages and groups specified in the config. It is the recommended entry point to pre-warm the cache before use. Throws an error if configuration cannot be applied or downloads fail. ```csharp public static void Init(PackConfig config) ``` ```csharp TreeSitterLanguagePackConverter.Init(new PackConfig()); ``` -------------------------------- ### Node#start_byte() - Get start byte offset Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Returns the inclusive start byte offset of the node as an Integer. ```ruby def start_byte() ``` ```ruby result = instance.start_byte() ``` -------------------------------- ### start_position() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Returns the start Point (row, column). ```rust pub fn start_position(&self) -> Point ``` ```rust let result = instance.start_position(); ``` -------------------------------- ### download() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Example of using download() to ensure specific languages are available. Returns the number of distinct languages available after the call. ```rust use tree_sitter_language_pack::download; let count = download(&["python", "rust", "typescript"]).unwrap(); println!("Ensured {} languages", count); ``` -------------------------------- ### get_parser() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Gets a Parser pre-configured for the given language. Convenience function that calls get_language and configures a new parser. Returns Error::LanguageNotFound or Error::ParserSetup on failure. ```rust use tree_sitter_language_pack::get_parser; let mut parser = get_parser("rust")?; let tree = parser.parse("fn main() {}").expect("parse failed"); assert!(!tree.root_node().has_error()); # Ok::<(), tree_sitter_language_pack::Error>(()) ``` -------------------------------- ### Quick start with WasmProcessConfig and process Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-core-wasm/README.md TypeScript example showing how to use the WASM package to parse Python code. It creates a WasmProcessConfig, calls process, and logs language, structure, imports, and metrics. ```typescript import { WasmProcessConfig, process } from "@xberg-io/tree-sitter-language-pack-wasm"; function main() { const config: WasmProcessConfig = (() => { const _u0 = WasmProcessConfig.default(); _u0.language = "python"; return _u0; })(); const result = process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config); console.log(result.language); console.log(result.structure); console.log(result.structure[0].kind); console.log(result.imports); console.log(result.metrics.totalLines); console.log(result.metrics.errorCount); } void main(); ``` -------------------------------- ### init() usage example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Example usage of init() to pre-warm the cache by downloading specified languages. ```rust use tree_sitter_language_pack::{PackConfig, init}; let config = PackConfig { cache_dir: None, languages: Some(vec!["python".to_string(), "rust".to_string()]), groups: None, }; init(&config).unwrap(); ``` -------------------------------- ### Node.startByte() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-wasm.md Returns the inclusive start byte offset of this node. ```typescript const result = instance.startByte(); ``` -------------------------------- ### getParser() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-swift.md Gets a Parser pre-configured for the given language. Convenience function that calls get_language and configures a new parser. Throws Error.LanguageNotFound if not recognized or Error.ParserSetup if the language cannot be applied. ```swift public static func getParser(name: String) throws -> Parser ``` ```swift let result = try getParser("value") ``` -------------------------------- ### Install via Scoop Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Windows users can install the same binary through Scoop. ```powershell scoop bucket add xberg https://github.com/xberg-io/scoop-bucket scoop install ts-pack ``` -------------------------------- ### Start MCP server over HTTP Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Starts the MCP server with HTTP transport, binding to 127.0.0.1 on port 8011. Suitable for remote agents or team setups. ```sh ts-pack mcp --transport http --host 127.0.0.1 --port 8011 ``` -------------------------------- ### downloadAll() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-swift.md Downloads all available languages from the remote manifest. The signature and example are shown together. Returns the total number of languages now available (statically compiled plus downloaded and cached). Throws an error if the manifest cannot be fetched or the bundle download fails. ```swift public static func downloadAll() throws -> UInt ``` ```swift let result = try downloadAll() ``` -------------------------------- ### ts_pack_configure() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_configure with a config handle. ```c ts_pack_configure(0); ``` -------------------------------- ### parse() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of parsing a source string. ```zig const result = instance.parse("value"); ``` -------------------------------- ### Node.startByte() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-java.md Returns the inclusive start byte offset of this node. ```java public long startByte() throws TreeSitterLanguagePackRsException ``` ```java var result = instance.startByte(); ``` -------------------------------- ### DownloadManager.download_all_best_effort() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example of calling download_all_best_effort() on a DownloadManager instance. ```python result = instance.download_all_best_effort() ``` -------------------------------- ### init() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-typescript.md Initializes the language pack with the given configuration, applying custom cache directory and downloading all languages and groups. Recommended entry point to pre-warm the cache before use. ```typescript function init(config: PackConfig): void ``` ```typescript init(new PackConfig()); ``` -------------------------------- ### ts_pack_download() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_download with a names string. ```c uintptr_t result = ts_pack_download(NULL); ``` -------------------------------- ### Node start_byte signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Returns the inclusive start byte offset of this node. ```rust pub fn start_byte(&self) -> usize ``` ```rust let result = instance.start_byte(); ``` -------------------------------- ### start_position() method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Returns the start Point (row, column) of the node. ```python def start_position(self) -> Point ``` ```python result = instance.start_position() ``` -------------------------------- ### prefetch() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Example of using prefetch() to prefetch grammars for a set of languages. Downloads any not loadable from disk, then loads them into the registry. ```rust use tree_sitter_language_pack::prefetch; prefetch(&["rust", "python", "go"])?; # Ok::<(), tree_sitter_language_pack::Error>(()) ``` -------------------------------- ### Install plugin in Claude Code Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/ai-coding-assistants.md Install the plugin in Claude Code by adding the marketplace and then installing the plugin. Run these commands in the Claude Code CLI. ```text /plugin marketplace add xberg-io/tree-sitter-language-pack /plugin install tree-sitter-language-pack@tree-sitter-language-pack ``` -------------------------------- ### startPosition() method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-wasm.md Returns the start Point (row, column) of the node. ```typescript startPosition(): Point ``` ```typescript const result = instance.startPosition(); ``` -------------------------------- ### ts_pack_prefetch() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_prefetch with a languages string. ```c ts_pack_prefetch(NULL); ``` -------------------------------- ### start_byte() method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Returns the inclusive start byte offset of the node as an int. ```python def start_byte(self) -> int ``` ```python result = instance.start_byte() ``` -------------------------------- ### download_all() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Example of using download_all() to download all available languages. Returns the total number of languages now available. ```rust use tree_sitter_language_pack::download_all; let count = download_all().unwrap(); println!("{} languages available", count); ``` -------------------------------- ### StartByte() method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-csharp.md Returns the inclusive start byte offset of this node as a ulong. ```csharp public ulong StartByte() ``` ```csharp var result = instance.StartByte(); ``` -------------------------------- ### All method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Enables every analysis feature, including data extraction. Chunking is not an analysis feature and stays off; enable it with with_chunking. The example calls the method on an instance. ```go func (o *ProcessConfig) All() *ProcessConfig ``` ```go result := instance.All() ``` -------------------------------- ### TreeCursor.goto_first_child() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to the goto_first_child() method. ```python result = instance.goto_first_child() ``` -------------------------------- ### WithParseTimeoutMs method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Cancels the parse if it exceeds timeout_ms milliseconds of wall clock. Pass nil to restore the default (no timeout). See RECOMMENDED_PARSE_TIMEOUT_MS for a starting value. The example passes 42. ```go func (o *ProcessConfig) WithParseTimeoutMs(timeoutMs uint64) *ProcessConfig ``` ```go result := instance.WithParseTimeoutMs(42) ``` -------------------------------- ### WithMaxSourceBytes method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Rejects source longer than max_bytes instead of parsing it. Pass nil to restore the default unbounded behaviour. See RECOMMENDED_MAX_SOURCE_BYTES for a starting value. The example passes 42. ```go func (o *ProcessConfig) WithMaxSourceBytes(maxBytes uint) *ProcessConfig ``` ```go result := instance.WithMaxSourceBytes(42) ``` -------------------------------- ### Minimal method signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Disables all analysis features, only metrics are computed. The example calls the method on an instance. ```go func (o *ProcessConfig) Minimal() *ProcessConfig ``` ```go result := instance.Minimal() ``` -------------------------------- ### Initialize language pack with Init() Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-go.md Initializes the language pack by applying custom cache directory and downloading all languages and groups specified in the config. Recommended entry point to pre-warm the cache before use. Returns an error if configuration cannot be applied or downloads fail. ```go func Init(config PackConfig) error ``` ```go if err := Init(PackConfig{}); err != nil { return err } ``` -------------------------------- ### getLanguage() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-dart.md Gets a tree-sitter Language by name using the global registry. Resolves language aliases (e.g., ```dart final result = getLanguage("value"); ``` -------------------------------- ### getParser(name: string): Parser Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-wasm.md Gets a Parser pre-configured for the given language, combining getLanguage and parser setup. ```APIDOC ## getParser(name: string): Parser ### Description Get a `Parser` pre-configured for the given language. This is a convenience function that calls `get_language` and configures a new parser in one step. ### Signature ```typescript function getParser(name: string): Parser ``` ### Parameters - `name` (string) - Required - The name ### Returns `Parser` ### Errors Throws `Error` with a descriptive message. Returns `Error.LanguageNotFound` if the language is not recognized, or `Error.ParserSetup` if the language cannot be applied to the parser. ### Example ```typescript const result = getParser("value"); ``` ``` -------------------------------- ### get_parser(name) Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Gets a Parser pre-configured for the given language, combining get_language and parser setup in one step. ```APIDOC ## get_parser(name) ### Description Get a `Parser` pre-configured for the given language. This is a convenience function that calls `get_language` and configures a new parser in one step. ### Signature ```ruby def self.get_parser(name) ``` ### Parameters - **name** (String) - Required - The name ### Returns `Parser` ### Errors Raises `Error`. Returns `Error.LanguageNotFound` if the language is not recognized, or `Error.ParserSetup` if the language cannot be applied to the parser. ### Example ```ruby result = get_parser("value") ``` ``` -------------------------------- ### Install CLI with cargo-binstall Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/README.md Installs the prebuilt ts-pack-cli binary via cargo-binstall. ```sh # Or install the prebuilt binary via cargo-binstall: cargo binstall ts-pack-cli ``` -------------------------------- ### ts_pack_process() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-c.md Example call to ts_pack_process with a source string and a config handle. ```c TS_PACKAlefHandle result = ts_pack_process("value", 0); ``` -------------------------------- ### Go: Load kitty and parse a simple snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_kitty.md This Go example loads the kitty language pack and parses a simple snippet. It uses the ProcessConfig with Language set to 'kitty' and calls Process with the input 'font_size 12\n'. The result is printed with fmt.Printf. This is a smoke test to verify the language pack loads and parses correctly. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `kitty`, } result, err := tspack.Process(`font_size 12 `, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### get_tags_query() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets the tags query for a language, if bundled. Returns the contents of tags.scm as a static string, or null if not bundled. ```zig pub fn get_tags_query(language: []const u8) ?[]u8 ``` ```zig const result = get_tags_query("value"); ``` -------------------------------- ### Tree.walk() Example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-typescript.md Example call to walk() on a Tree instance. ```typescript const result = instance.walk(); ``` -------------------------------- ### get_locals_query() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets the locals query for a language, if bundled. Returns the contents of locals.scm as a static string, or null if not bundled. ```zig pub fn get_locals_query(language: []const u8) ?[]u8 ``` ```zig const result = get_locals_query("value"); ``` -------------------------------- ### get_injections_query() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets the injections query for a language, if bundled. Returns the contents of injections.scm as a static string, or null if not bundled. ```zig pub fn get_injections_query(language: []const u8) ?[]u8 ``` ```zig const result = get_injections_query("value"); ``` -------------------------------- ### ts-pack info example and output Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/cli.mdx Example of showing details for Python, followed by the output when the parser is downloaded. Before download, 'Cache path' shows the cache directory instead. ```bash ts-pack info python ``` ```text Language: python Known: true Downloaded: true Cache path: /home/user/.cache/tree-sitter-language-pack/v1.14.3/libs/libtree_sitter_python.so ``` -------------------------------- ### manifest_languages/0 example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Example call to manifest_languages/0, returning {:ok, result}. ```elixir {:ok, result} = manifest_languages() ``` -------------------------------- ### reset() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Example of resetting the parser. ```zig instance.reset(); ``` -------------------------------- ### get_highlights_query() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets the highlights query for a language, if bundled. Returns the contents of highlights.scm as a static string, or null if not bundled. ```zig pub fn get_highlights_query(language: []const u8) ?[]u8 ``` ```zig const result = get_highlights_query("value"); ``` -------------------------------- ### TreeCursor.node() - Get current node Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Returns the Node at the cursor's current position. Example shows calling node() on an instance. ```kotlin fun node(): Node ``` ```kotlin val result = instance.node() ``` -------------------------------- ### Python programmatic configuration with init() and configure() Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/configuration.mdx Use init() and configure() with a single optional PackConfig, not keyword arguments. init() can pre-download specific languages, download by group (only 'all' exists), or combine both. configure() sets a custom cache directory and must be called before first parse. Calling init() with no argument applies an empty PackConfig. ```python from tree_sitter_language_pack import PackConfig, configure, init # Pre-download specific languages init(PackConfig(languages=["python", "javascript", "rust"])) # Download by language group. manifest_groups() lists the names that exist; # the published manifest defines only "all". init(PackConfig(groups=["all"])) # Combine languages and groups init(PackConfig(languages=["python"], groups=["all"])) # Set custom cache directory (call before first parse) configure(PackConfig(cache_dir="/opt/ts-pack-cache")) # With no argument, init() applies an empty PackConfig init() ``` -------------------------------- ### Detect language from empty extension in C# Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/csharp/error-handling/error_detect_extension_empty.md Use TreeSitterLanguagePackConverter.DetectLanguageFromExtension with an empty string to get a null result. The example prints the result to the console. ```csharp using System; using TreeSitterLanguagePack; var result = TreeSitterLanguagePackConverter.DetectLanguageFromExtension(""); Console.WriteLine(result); ``` -------------------------------- ### ts-pack completions examples Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/cli.mdx Examples of generating completion scripts for bash, zsh, and fish. ```bash ts-pack completions bash >> ~/.bash_completion ts-pack completions zsh > ~/.zsh/completions/_ts-pack ts-pack completions fish > ~/.config/fish/completions/ts-pack.fish ``` -------------------------------- ### Node#kind() - Get node kind name Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Returns the node's kind name as a String. The signature and example are shown together. ```ruby def kind() ``` ```ruby result = instance.kind() ``` -------------------------------- ### ts-pack process command examples Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/plugin/skills/tree-sitter-language-pack/SKILL.md Shows how to run the code-intelligence pipeline. Defaults to structure, imports, and exports when no feature flags are given. Use --all for everything, --chunk-size for syntax-aware chunks, and --diagnostics for syntax diagnostics. ```bash # Defaults to structure + imports + exports when no feature flags are given: ts-pack process src/app.ts # Pick features explicitly: ts-pack process src/app.ts --structure --imports --symbols --docstrings # Everything: ts-pack process src/app.ts --all # Syntax-aware chunks (bytes) for an LLM: ts-pack process src/app.ts --chunk-size 2000 # Syntax diagnostics: ts-pack process src/app.ts --diagnostics ``` -------------------------------- ### configure() example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-rust.md Example of using configure() to set a custom cache directory. The cache_dir is a base directory; the crate appends tree-sitter-language-pack/v{version}/libs to it. ```rust use std::path::PathBuf; use tree_sitter_language_pack::{PackConfig, configure}; let config = PackConfig { cache_dir: Some(PathBuf::from("/tmp/my-parsers")), languages: None, groups: None, }; configure(&config).unwrap(); ``` -------------------------------- ### get_tags_query for rust in Python Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/python/query/tags_query_rust.md Calls get_tags_query with the language name 'rust' and prints the returned query string. The example assumes the tree_sitter_language_pack module is installed. ```python from tree_sitter_language_pack import get_tags_query def main() -> None: language = "rust" result = get_tags_query(language) print(result) main() ``` -------------------------------- ### Go: Load D and Parse Snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_d.md Initializes a ProcessConfig for the D language, processes the D code 'void main() {}', and prints the result. Panics on error. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `d`, } result, err := tspack.Process(`void main() {}`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Detect Bash from shebang with detectLanguageFromContent Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/wasm/language-detection/detect_content_bash_shebang.md Use detectLanguageFromContent from @xberg-io/tree-sitter-language-pack-wasm to detect the language of content starting with #!/bin/bash. The example logs the detection result to the console. ```typescript import { detectLanguageFromContent } from "@xberg-io/tree-sitter-language-pack-wasm"; function main() { const result = detectLanguageFromContent("#!/bin/bash\necho hi"); console.log(result); } void main(); ``` -------------------------------- ### Quick Start commands Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Common ts-pack commands for initializing config, listing languages, downloading, checking status, adding languages, and cloning parser sources. ```sh # Initialize a language-pack.toml config ts-pack init # List available languages ts-pack list # Download specific languages for offline use ts-pack download python rust javascript # Check download status ts-pack status # Add languages to your config ts-pack add python rust javascript # Clone parser sources ts-pack clone ``` -------------------------------- ### Install the npm package Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/crates/ts-pack-core-node/README.md Install the @xberg-io/tree-sitter-language-pack package via npm. ```bash npm install @xberg-io/tree-sitter-language-pack ``` -------------------------------- ### Go: Load and Parse a Simple Snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_go.md Use this snippet to smoke-test the Go language pack. It creates a ProcessConfig with Language set to `go`, calls Process on the string `package main`, and prints the result. The example is safe to run and has no side effects. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `go`, } result, err := tspack.Process(`package main`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Get cache directory path with TreeSitterLanguagePack.cache_dir() Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/elixir/download/download_cache_dir.md Calls TreeSitterLanguagePack.cache_dir() to retrieve the cache directory path and prints it with IO.inspect. The example is safe and has no side effects. ```elixir result = TreeSitterLanguagePack.cache_dir() IO.inspect(result) ``` -------------------------------- ### Detect language from nested path using detect_language_from_path Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/python/language-detection/detect_path_nested.md Use detect_language_from_path to get the language of a file from a nested path. The example passes 'src/main.py' and prints the result. ```python from tree_sitter_language_pack import detect_language_from_path def main() -> None: path = "src/main.py" result = detect_language_from_path(path) print(result) main() ``` -------------------------------- ### Go: Load qmldir and Parse a Simple Snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_qmldir.md Use this Go snippet to smoke test the qmldir language pack. It configures the processor for the 'qmldir' language and processes the input 'module Example'. The result is printed with fmt.Printf. Requires the tree-sitter-language-pack Go package. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `qmldir`, } result, err := tspack.Process(`module Example`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Tree::rootNode() - Get root node Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-php.md Returns the root Node of the parsed syntax tree. The signature shows the method declaration, and the example calls it on an instance. ```php public function rootNode(): Node ``` ```php $result = $instance->rootNode(); ``` -------------------------------- ### Tree.walk() usage example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-python.md Example call to walk() on an instance of Tree. ```python result = instance.walk() ``` -------------------------------- ### getLanguage() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Gets a tree-sitter Language by name using the global registry. Resolves aliases and auto-downloads if enabled. Throws Error.LanguageNotFound or Error.Download on failure. ```kotlin @Throws(Error::class) fun getLanguage(name: String): Language ``` ```kotlin val result = getLanguage("value") ``` -------------------------------- ### Go: Load PRQL and Parse Snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_prql.md Initializes the tree-sitter language pack for PRQL and processes the input 'x'. Prints the result or panics on error. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `prql`, } result, err := tspack.Process(`x`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Tree#root_node - Get root node Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-ruby.md Returns the root Node of the parsed syntax tree. The signature shows the method definition, and the example calls it on an instance. ```ruby def root_node() ``` ```ruby result = instance.root_node() ``` -------------------------------- ### Detect language from path 'app.js' using detectLanguageFromPath Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/wasm/language-detection/detect_path_js_root.md Imports `detectLanguageFromPath` from `@xberg-io/tree-sitter-language-pack-wasm` and calls it with 'app.js', logging the result. The example is safe and requires no additional setup. ```typescript import { detectLanguageFromPath } from "@xberg-io/tree-sitter-language-pack-wasm"; function main() { const result = detectLanguageFromPath("app.js"); console.log(result); } void main(); ``` -------------------------------- ### prefetch/1 example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Example call to prefetch/1 with an empty list, expecting :ok. ```elixir :ok = prefetch([]) ``` -------------------------------- ### Detect language for .js extension with detect_language_from_extension Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/python/language-detection/detect_ext_javascript.md Use detect_language_from_extension to get the language for a file extension. This example passes 'js' and prints the result. The function is imported from tree_sitter_language_pack. ```python from tree_sitter_language_pack import detect_language_from_extension def main() -> None: ext = "js" result = detect_language_from_extension(ext) print(result) main() ``` -------------------------------- ### Get Python Language in Kotlin (Android) Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/kotlin-android/registry/get_language_python.md Use TreeSitterLanguagePack.getLanguage("python") to retrieve a Language object for Python. The example prints the language object to the console. ```kotlin import io.xberg.tslp.android.* fun main() { val language = TreeSitterLanguagePack.getLanguage("python") println(language) } ``` -------------------------------- ### Get cache directory path with TreeSitterLanguagePack.cacheDir() Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/java/download/download_cache_dir.md Calls the static method cacheDir() from the TreeSitterLanguagePack class and prints the returned path. The example is marked as safe with no side effects. ```java import io.xberg.treesitterlanguagepack.*; public final class Example { public static void main(String[] args) throws Exception { var result = TreeSitterLanguagePack.cacheDir(); System.out.println(result); } } ``` -------------------------------- ### init() method usage Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-php.md Initializes the language pack and pre-warms the cache by downloading languages specified in the PackConfig. ```php init(new PackConfig()); ``` -------------------------------- ### Tree.walk/1 example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-elixir.md Example call to Tree.walk/1, returning a tuple with :ok and the result. ```elixir {:ok, result} = instance.walk() ``` -------------------------------- ### getParser() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-kotlin-android.md Gets a Parser pre-configured for the given language. Convenience function that calls get_language and configures a new parser. Throws Error.LanguageNotFound or Error.ParserSetup on failure. ```kotlin @Throws(Error::class) fun getParser(name: String): Parser ``` ```kotlin val result = getParser("value") ``` -------------------------------- ### getParser() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-wasm.md Gets a Parser pre-configured for the given language. Convenience function that calls get_language and configures a new parser. Throws Error.LanguageNotFound or Error.ParserSetup on failure. ```typescript function getParser(name: string): Parser ``` ```typescript const result = getParser("value"); ``` -------------------------------- ### get_language() signature and example Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/reference/api-zig.md Gets a tree-sitter Language by name using the global registry. Resolves aliases (e.g., "shell" to "bash") and auto-downloads if the download feature is enabled. Returns Error.LanguageNotFound or Error.Download on failure. The example uses try and the string "value". ```zig pub fn get_language(name: []const u8) Error!Language ``` ```zig const result = try get_language("value"); ``` -------------------------------- ### Start MCP server with custom config Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/content/docs/guides/mcp-server.mdx Point the server at a language-pack.toml config file to set default languages and download preferences for all tool calls. ```bash ts-pack mcp --config /path/to/language-pack.toml ``` -------------------------------- ### Python: Load templ and parse a simple snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/python/smoke/smoke_templ.md Use this smoke test to verify that the templ language pack is installed and can parse a minimal source string. It calls `process` with a config specifying `language: "templ"` and prints the result. No additional setup is required beyond having the package installed. ```python from tree_sitter_language_pack import process def main() -> None: source = "x" config = {"language": "templ"} result = process(source, config) print(result) main() ``` -------------------------------- ### Go: Load Arduino and Parse Snippet Source: https://github.com/xberg-io/tree-sitter-language-pack/blob/main/docs-site/src/snippets/generated/go/smoke/smoke_arduino.md Use this Go snippet to smoke test the Arduino language pack. It sets the language to 'arduino' and processes the snippet 'void setup() {}', printing the result or panicking on error. ```go package main import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go" ) func main() { config := tspack.ProcessConfig{ Language: `arduino`, } result, err := tspack.Process(`void setup() {}`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result) } ```