### Quick Start Development Setup Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/CONTRIBUTING.md Perform a one-time setup to install dependencies, clone grammar sources, and build the project in development mode. ```bash # One-time setup - installs all dependencies task setup # Clone grammar sources task clone # Build in dev mode (a few languages, fast iteration) task build:dev ``` -------------------------------- ### C/FFI: Installation and Quick Start Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Explains how to install the C/FFI binding by including a header file and linking against the compiled library. Provides a C quick start example for initializing a registry, checking language availability, parsing code, and inspecting the resulting tree, including manual memory management. ```bash gcc -o program program.c -L. -lts_pack_ffi ``` ```c #include "ts_pack.h" #include #include int main(void) { TsPackRegistry* reg = ts_pack_registry_new(); if (!reg) { fprintf(stderr, "Error: %s\n", ts_pack_last_error()); return 1; } // Check for Python if (!ts_pack_has_language(reg, "python")) { fprintf(stderr, "Python not available\n"); ts_pack_registry_free(reg); return 1; } // Parse code const char* code = "def hello(): pass"; TsPackTree* tree = ts_pack_parse_string(reg, "python", code, strlen(code)); if (!tree) { fprintf(stderr, "Parse error: %s\n", ts_pack_last_error()); ts_pack_registry_free(reg); return 1; } // Inspect tree char* root_type = ts_pack_tree_root_node_type(tree); printf("Root: %s\n", root_type); ts_pack_free_string(root_type); // Cleanup ts_pack_tree_free(tree); ts_pack_registry_free(reg); return 0; } ``` -------------------------------- ### PHP: Install and Quick Start Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Shows how to install the PHP binding using Composer and provides a quick start example for listing available languages, parsing code into an S-expression string, and processing code with a typed configuration object. ```bash composer require kreuzberg-dev/tree-sitter-language-pack ``` ```php import * as tsp from "https://cdn.jsdelivr.net/npm/@kreuzberg/tree-sitter-language-pack-wasm"; ``` ```javascript import * as tsp from "@kreuzberg/tree-sitter-language-pack-wasm"; // List languages const langs = tsp.availableLanguages(); console.log(`${langs.length} languages available`); // Parse code const tree = tsp.parseString("python", "def hello(): pass"); console.log(tsp.treeRootNodeType(tree)); // "module" console.log(tsp.treeHasErrorNodes(tree)); // false tsp.freeTree(tree); // Process code (config is JS object) const result = tsp.process("def hello(): pass", { language: "python" }); console.log(`Functions: ${result.structure.length}`); ``` -------------------------------- ### Quick Start: Parse Python Code Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/packages/python/README.md Demonstrates how to get a Python parser, parse a simple Python code snippet, and print the resulting syntax tree in S-expression format. Ensure the 'tree-sitter-language-pack' is installed. ```python from tree_sitter_language_pack import get_parser parser = get_parser("python") tree = parser.parse(b"def hello(): pass") print(tree.root_node.sexp()) ``` -------------------------------- ### Go Quick Start Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Demonstrates basic usage of the Go bindings, including registry creation, string parsing, and code processing. Remember to close the registry and tree when done. ```go package main import ( "fmt" tspack "github.com/kreuzberg-dev/tree-sitter-language-pack/packages/go" ) func main() { reg, _ := tspack.NewRegistry() defer reg.Close() tree, _ := reg.ParseString("python", "def hello(): pass") defer tree.Close() fmt.Println(tree.RootNodeType()) // "module" fmt.Println(tree.ContainsNodeType("function_definition")) // true config := tspack.NewProcessConfig("python") result, _ := reg.Process("def hello(): pass", config) fmt.Printf("Functions: %d\n", len(result.Metadata.Structure)) } ``` -------------------------------- ### Elixir Quick Start Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Shows how to list available languages using the Elixir bindings. ```elixir # List languages langs = TreeSitterLanguagePack.available_languages() IO.puts("#{length(langs)} languages available") ``` -------------------------------- ### Ruby Quick Start Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Demonstrates using the Ruby bindings, which are module-level functions. Configuration and results are handled as JSON strings. ```ruby require "tree_sitter_language_pack" # List languages langs = TreeSitterLanguagePack.available_languages puts "#{langs.length} languages available" # Parse code tree = TreeSitterLanguagePack.parse_string("python", "def hello(): pass") puts tree.root_node_type # "module" puts tree.has_error_nodes # false puts tree.contains_node_type("function_definition") # true # Process code (returns JSON string) config = { language: "python", structure: true }.to_json result_json = TreeSitterLanguagePack.process("def hello(): pass", config) result = JSON.parse(result_json) puts "Functions: #{result['structure'].length}" ``` -------------------------------- ### Java Quick Start Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Illustrates using the Java bindings with try-with-resources for automatic resource management. Configuration and results are handled as JSON strings. ```java import dev.kreuzberg.treesitterlanguagepack.*; public class Main { public static void main(String[] args) { try (var registry = new TsPackRegistry()) { var languages = registry.availableLanguages(); System.out.printf("%d languages available%n", languages.size()); try (var tree = registry.parseString("python", "def hello(): pass")) { System.out.println(tree.rootNodeType()); // "module" System.out.println(tree.rootChildCount()); // 1 System.out.println(tree.containsNodeType("function_definition")); // true } String configJson = "{\"language\":\"python\",\"structure\":true}"; String resultJson = registry.process("def hello(): pass", configJson); System.out.println(resultJson); } } } ``` -------------------------------- ### Go Quickstart Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/snippets/go/quickstart.md This Go snippet demonstrates how to initialize a parser for the Go language, parse a simple Go code string, and retrieve the root node's kind. ```go package main import ( "fmt" "log" "github.com/kreuzberg-dev/tree-sitter-language-pack/packages/go" ) func main() { parser, err := tspack.GetParser("go") if err != nil { log.Fatal(err) } defer parser.Free() tree := parser.Parse("package main\nfunc hello() {}") defer tree.Free() root := tree.RootNode() defer root.Free() kind := root.Kind() if kind != nil { fmt.Println("Root:", *kind) } } ``` -------------------------------- ### Install tree-sitter-language-pack for Go Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Get the Go package using `go get`. Requires Go 1.26+ and uses cgo. ```bash go get github.com/kreuzberg-dev/tree-sitter-language-pack/packages/go ``` -------------------------------- ### C# Quick Start Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Shows how to use the static TsPackClient in C# for listing languages, parsing code, and processing with a typed configuration object. ```csharp using TreeSitterLanguagePack; // List languages string[] langs = TsPackClient.AvailableLanguages(); Console.WriteLine($"{langs.Length} languages available"); // Parse code using var tree = TsPackClient.Parse("python", "def hello(): pass"); Console.WriteLine(tree.RootNodeType()); // "module" // Process code var config = new ProcessConfig { Language = "python", Structure = true }; var result = TsPackClient.Process("def hello(): pass", config); Console.WriteLine($"Functions: {result.Structure.Count}"); ``` -------------------------------- ### Dart Quickstart Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/snippets/dart/quickstart.md Initializes the Tree-sitter Language Pack, retrieves a Python parser, parses a simple Python function, and prints the kind of the root node. ```dart import 'package:tree_sitter_language_pack/tree_sitter_language_pack.dart'; import 'package:tree_sitter_language_pack/src/tree_sitter_language_pack_bridge_generated/frb_generated.dart' show RustLib; void main() async { await RustLib.init(); final parser = await TreeSitterLanguagePackBridge.getParser('python'); final tree = await parser.parse(source: "def hello():\n print('world')\n"); final root = await tree!.rootNode(); print('Root kind: ${await root.kind()}'); } ``` -------------------------------- ### Project Setup and Build Commands Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/contributing.md Installs language dependencies, builds the Rust core, and runs all tests for the project. ```bash # Install all language dependencies task setup # Build the Rust core task build # Run all tests task test ``` -------------------------------- ### Pre-bake Parsers into Docker Image Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/configuration.md Example Dockerfile demonstrating how to install the package and pre-download parsers to bake them into the image. ```dockerfile FROM python:3.11-slim RUN pip install tree-sitter-language-pack # Pre-download parsers (bakes into image) RUN python -c "from tree_sitter_language_pack import download; download(['python', 'javascript', 'rust'])" COPY . /app WORKDIR /app # Parsing now offline, no network calls CMD ["python", "app.py"] ``` -------------------------------- ### Quick Start: Parse Python Code Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-core/README.md Demonstrates how to get a parser for Python, parse a simple function, and print its S-expression representation. ```rust use tree_sitter_language_pack::{get_language, get_parser}; let mut parser = get_parser("python").expect("language available"); let tree = parser.parse("def hello(): pass", None).unwrap(); println!("{}", tree.root_node().to_sexp()); ``` -------------------------------- ### Quick Start: Get Python Parser and Parse Code Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-core-node/README.md Demonstrates how to get a parser for a specific language (Python in this case) and use it to parse a code string. The resulting syntax tree can then be inspected. ```typescript import { getParser } from "@kreuzberg/tree-sitter-language-pack"; const parser = getParser("python"); const tree = parser.parse("def hello(): pass"); console.log(tree.rootNode.toString()); ``` -------------------------------- ### Go Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `Process` function from the Go bindings. ```go registry.Process(source, config) ``` -------------------------------- ### CLI Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Install the tree-sitter-language-pack CLI using a curl script. ```bash curl -fsSL https://raw.githubusercontent.com/kreuzberg-dev/tree-sitter-language-pack/main/install.sh | bash ``` -------------------------------- ### Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/python-api.md Install the tree-sitter-language-pack using pip. ```APIDOC ## Installation ### Description Install the tree-sitter-language-pack using pip. ### Method `pip` ### Endpoint N/A ### Request Example ```bash pip install tree-sitter-language-pack ``` ``` -------------------------------- ### Verify Go installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Import the Go package and print the language count to verify the installation. ```go import tslp "github.com/kreuzberg-dev/tree-sitter-language-pack/packages/go" func main() { fmt.Println(tslp.LanguageCount()) // 306 } ``` -------------------------------- ### C (FFI) Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Install the tree-sitter-language-pack for C using a shared library and header. ```text Shared library + header ``` -------------------------------- ### Install PHP Package Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Install the tree-sitter-language-pack for PHP using Composer. ```sh composer require kreuzberg-dev/tree-sitter-language-pack ``` -------------------------------- ### Install CLI from Source Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/cli-reference.md Installs the tree-sitter language pack CLI from the local source code using Cargo. ```bash cargo install --path crates/ts-pack-cli ``` -------------------------------- ### Import Examples (Python) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/code-intelligence.md Examples illustrating how import statements are represented in the results. ```python # import os # {"source": "os", "names": [], "is_wildcard": true} # from pathlib import Path # {"source": "pathlib", "names": ["Path"], "is_wildcard": false} ``` -------------------------------- ### CI/CD Cache Parsers Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/guides/cli.md Demonstrates how to use ts-pack within a CI/CD pipeline to install the CLI, cache downloaded parsers, and perform analysis. ```yaml - name: Install ts-pack run: cargo install ts-pack-cli - name: Cache parsers uses: actions/cache@v4 with: path: ~/.cache/tree-sitter-language-pack key: tslp-${{ hashFiles('language-pack.toml') }} - name: Download parsers run: ts-pack download - name: Analyze run: ts-pack process src/main.py --all ``` -------------------------------- ### Verify Python installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Import the library and print the number of supported languages to verify the Python installation. ```python import tree_sitter_language_pack as tslp print(tslp.language_count()) # 306 ``` -------------------------------- ### Install Python Package Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Install the tree-sitter-language-pack for Python using pip or uv. ```sh pip install tree-sitter-language-pack ``` ```sh uv add tree-sitter-language-pack ``` -------------------------------- ### Ruby Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `process` function in Ruby. ```ruby TreeSitterLanguagePack.process(source, configJson) ``` -------------------------------- ### Install CLI with Homebrew Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Install the ts-pack CLI using Homebrew after trusting the tap. ```sh brew install kreuzberg-dev/tap/ts-pack ``` -------------------------------- ### Java Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `process` function in Java. ```java registry.process(source, configJson) ``` -------------------------------- ### Install Node.js Package Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Install the tree-sitter-language-pack for Node.js using npm, pnpm, or yarn. ```sh npm install @kreuzberg-dev/tree-sitter-language-pack ``` ```sh pnpm add @kreuzberg-dev/tree-sitter-language-pack ``` ```sh yarn add @kreuzberg-dev/tree-sitter-language-pack ``` -------------------------------- ### Rust Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `process` function from the Rust core library. ```rust ts_pack_core::process(source, &config) ``` -------------------------------- ### Verify Java installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Instantiate the Java class and print the language count to verify the installation. ```java import dev.kreuzberg.treesitterlanguagepack.TreeSitterLanguagePack; public class Main { public static void main(String[] args) { System.out.println(TreeSitterLanguagePack.languageCount()); // 306 } } ``` -------------------------------- ### Install tree-sitter-language-pack for PHP Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Install the PHP package using Composer. Requires PHP 8.2+. Ensure `mlocati/php-extension-installer` is installed first. ```bash composer require mlocati/php-extension-installer composer require kreuzberg-dev/tree-sitter-language-pack ``` ```json { "require": { "mlocati/php-extension-installer": "^2.0", "kreuzberg-dev/tree-sitter-language-pack": "^1.0" } } ``` -------------------------------- ### Install Python Package Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/quickstart.md Install the tree-sitter-language-pack for Python projects. ```bash pip install tree-sitter-language-pack ``` -------------------------------- ### Node.js Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `process` function in Node.js. ```javascript process(source, { language: '...' }) ``` -------------------------------- ### Python Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `process` function in Python. ```python process(source, ProcessConfig(...)) ``` -------------------------------- ### Install Tree-Sitter Language Pack (Python) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/SKILL.md Install the package using pip or uv for Python projects. ```bash pip install tree-sitter-language-pack # or with uv: uv add tree-sitter-language-pack ``` -------------------------------- ### Quick Start with Tree-sitter Language Pack WASM Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-core-wasm/README.md Initialize the WASM module and get a parser for a specific language to parse code. This example demonstrates parsing Python code. ```typescript import init, { getParser } from "@kreuzberg/tree-sitter-language-pack-wasm"; await init(); const parser = getParser("python"); const tree = parser.parse("def hello(): pass"); ``` -------------------------------- ### Install Task on Linux Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/CONTRIBUTING.md Install the Task task runner on Linux using the installer script or package managers like apt or pacman. ```bash # Using the installer script sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin # Or via package managers: apt install go-task # Debian/Ubuntu pacman -S go-task # Arch ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Use `StartPosition` to get the starting `Point` (row and column) of a node. ```csharp public Point StartPosition() ``` -------------------------------- ### Install Task and Clone Repository Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/contributing.md Installs the Task runner on macOS, clones the project repository, and navigates into the project directory. ```bash # Install Task (macOS) brew install go-task # Clone the repository git clone https://github.com/kreuzberg-dev/tree-sitter-language-pack.git cd tree-sitter-language-pack ``` -------------------------------- ### Install Ruby Gem Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Install the tree-sitter-language-pack for Ruby using the gem command. ```sh gem install tree_sitter_language_pack ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Use `StartByte` to get the inclusive start byte offset of a node within its source. ```csharp public nuint StartByte() ``` -------------------------------- ### C FFI Core API Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Example of using the `ts_pack_process` function for C FFI bindings. ```c ts_pack_process(registry, source, len, configJson) ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-zig.md Return the start Point (row, column) of the node. ```zig pub fn startPosition(self: *const Node) Point ``` -------------------------------- ### Get Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-ruby.md Returns the start position of the node as a Point (row, column). ```ruby def start_position() ``` -------------------------------- ### Example Import Statement JSON Output Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/concepts/code-intelligence.md Illustrates the JSON structure for import statements, showing the source module, an array of imported names (or empty for wildcard/bare imports), and the starting line. ```json [ { "source": "os", "names": [], "start_line": 1 }, { "source": "pathlib", "names": ["Path"], "start_line": 2 }, { "source": "./utils", "names": ["readFile", "writeFile"], "start_line": 3 } ] ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-kotlin-android.md Returns the starting `Point` (row and column) of the node. ```kotlin fun startPosition(): Point ``` -------------------------------- ### Install Tree-sitter Language Pack WASM Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-core-wasm/README.md Install the package using npm. This command fetches and installs the necessary files for using tree-sitter grammars in your project. ```bash npm install @kreuzberg/tree-sitter-language-pack-wasm ``` -------------------------------- ### Initialize and Download from Configuration Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/concepts/download-model.md Use CLI or Python to initialize the language pack based on the `language-pack.toml` file and download the configured languages. ```bash ts-pack init --languages python,javascript,typescript,rust,go ts-pack download # downloads all configured languages ``` ```python from tree_sitter_language_pack import init # Reads language-pack.toml from current directory init() ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-zig.md Return the inclusive start byte offset of this node. ```zig pub fn startByte(self: *const Node) u64 ``` -------------------------------- ### Install Tree-Sitter Language Pack CLI Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/SKILL.md Install the command-line interface for the tree-sitter-language-pack, either from source or by downloading pre-built releases. ```bash # From source cargo install --path crates/ts-pack-cli # Or download pre-built from GitHub releases ``` -------------------------------- ### Export Example (Python) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/code-intelligence.md An example showing the representation of an exported symbol. ```python # def greet(): ... # {"name": "greet", "kind": "function"} ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-swift.md Returns the starting position of the node as a Point (row, column). ```swift public func startPosition() -> Point ``` -------------------------------- ### Initialize Project with Languages Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/cli-reference.md Command to initialize a new project and specify the programming languages to be used. ```bash ts-pack init --languages python,rust,typescript ts-pack download ``` -------------------------------- ### Get Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-ruby.md Returns the inclusive start byte offset of the node in the source. ```ruby def start_byte() ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-go.md Returns the starting position of the node as a Point (row, column). ```go func (o *Node) StartPosition() Point ``` -------------------------------- ### CLI Quick Start Commands Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/crates/ts-pack-cli/README.md Common commands for initializing, listing, downloading, checking status, adding, and cloning tree-sitter language parsers. ```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 Pre-commit Hooks Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/contributing.md Install the project's pre-commit hooks using the 'prek' tool. This ensures code quality checks are run before commits. ```bash prek install prek install --hook-type commit-msg ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-php.md Return the starting `Point` (row and column) of the node using `startPosition()`. ```php public function startPosition(): Point ``` -------------------------------- ### Install Task on Windows Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/CONTRIBUTING.md Install the Task task runner on Windows using Scoop or Chocolatey. ```powershell # Using Scoop scoop install task # Or using Chocolatey choco install go-task ``` -------------------------------- ### Swift Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Add the tree-sitter-language-pack-swift package for Swift projects. ```swift .package(url: "https://github.com/kreuzberg-dev/tree-sitter-language-pack-swift", from: "1.9.0") ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-elixir.md Returns the start position of the node as a Point struct (row, column). ```elixir def start_position() ``` -------------------------------- ### Install Tree-Sitter Language Pack (Node.js/TypeScript) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/SKILL.md Install the package using npm or pnpm for Node.js and TypeScript projects. ```bash npm install @kreuzberg/tree-sitter-language-pack # or with pnpm: pnpm add @kreuzberg/tree-sitter-language-pack ``` -------------------------------- ### Download on First Use Example Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/configuration.md Demonstrates how calling parse functions triggers an automatic download of uncached languages, which can add latency. ```python # First call triggers download (network I/O) tree = parse_string("python", "x = 1") # Subsequent calls use cached parser (fast) tree = parse_string("python", "y = 2") ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-swift.md Returns the inclusive start byte offset of the node within its source. ```swift public func startByte() -> UInt64 ``` -------------------------------- ### Initialize and Download Parsers Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/concepts/download-model.md Configure and download parsers in a single step. This is convenient for setting up a project with a predefined set of languages. ```python # Configure + download in one call init(["python", "javascript"]) ``` ```typescript // Configure + download in one call await init(["python", "javascript"]); ``` ```rust // Configure + download in one call init(&["python", "javascript"])?; ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-go.md Returns the inclusive start byte offset of the node within its source. ```go func (o *Node) StartByte() int ``` -------------------------------- ### Install tree-sitter-language-pack for Node.js Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Install the Node.js package using npm, pnpm, or Yarn. Requires Node.js 18+. ```bash npm install @kreuzberg/tree-sitter-language-pack ``` ```bash pnpm add @kreuzberg/tree-sitter-language-pack ``` ```bash yarn add @kreuzberg/tree-sitter-language-pack ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-kotlin-android.md Returns the inclusive start byte offset of the node within its source. ```kotlin fun startByte(): Long ``` -------------------------------- ### Zig Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Fetch the tree-sitter-language-pack for Zig using zig fetch. ```bash zig fetch --save ``` -------------------------------- ### Verify Ruby installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Require the library and print the language count to verify the Ruby installation. ```ruby require "tree_sitter_language_pack" puts TreeSitterLanguagePack.language_count # 306 ``` -------------------------------- ### Get the node's start position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-c.md The `ts_pack_start_position` function returns the start `TsPackPoint` (row, column) of the node. ```c TsPackPoint ts_pack_start_position(); ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-elixir.md Returns the inclusive start byte offset of the node within its source. ```elixir def start_byte() ``` -------------------------------- ### Install WebAssembly Package Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/README.md Install the tree-sitter-language-pack WASM package for Node.js environments using npm, pnpm, or yarn. ```sh npm install @kreuzberg-dev/tree-sitter-language-pack-wasm ``` ```sh pnpm add @kreuzberg-dev/tree-sitter-language-pack-wasm ``` ```sh yarn add @kreuzberg-dev/tree-sitter-language-pack-wasm ``` -------------------------------- ### Get Node Start Position Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-python.md Returns the starting position of the node as a `Point` object, containing row and column information. ```python def start_position(self) -> Point: ``` -------------------------------- ### Node.StartPosition Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Gets the starting `Point` (row and column) of the node. ```APIDOC ## StartPosition() ### Description Return the start `Point` (row, column). ### Signature ```csharp public Point StartPosition() ``` ``` -------------------------------- ### Install tree-sitter-language-pack for Python Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Install the Python package using pip, uv, or poetry. Requires Python 3.10+. ```bash pip install tree-sitter-language-pack ``` ```bash uv add tree-sitter-language-pack ``` ```bash poetry add tree-sitter-language-pack ``` -------------------------------- ### Node.startPosition() Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-typescript.md Gets the starting position (row and column) of the node. ```APIDOC ## startPosition(): Point ### Description Return the start `Point` (row, column). ### Returns - **Point** - The starting position of the node. ``` -------------------------------- ### Java Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Include the tree-sitter-language-pack for Java via Maven Central. ```xml Maven Central dev.kreuzberg.treesitterlanguagepack:tree-sitter-language-pack ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-php.md Return the inclusive start byte offset of the node within its source text using `startByte()`. ```php public function startByte(): int ``` -------------------------------- ### Get Node Start Byte Offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-python.md Returns the inclusive start byte offset of the node within the source text. This is a zero-copy accessor. ```python def start_byte(self) -> int: ``` -------------------------------- ### init() Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-zig.md Initializes the language pack with a given configuration, applying custom cache directories and downloading specified languages and groups. Recommended for pre-warming the cache. ```APIDOC ## init() ### Description 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. ### Signature ```zig pub fn init(config: PackConfig) Error!void ``` ### Parameters #### Path Parameters - **config** (`PackConfig`) - Yes - The configuration options for initialization. ### Returns - `void` ### Errors - Throws `Error` - If configuration cannot be applied or if downloads fail. ``` -------------------------------- ### Dart/Flutter Installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/index.md Add the tree-sitter-language-pack to your Dart or Flutter project. ```bash dart pub add tree_sitter_language_pack ``` -------------------------------- ### Init() Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Initializes the language pack with a given configuration, applying custom cache directories and downloading specified languages and groups. ```APIDOC ## Init() ### Description 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. ### Signature ```csharp public static void Init(PackConfig config) ``` ### Parameters #### Path Parameters - **config** (PackConfig) - Yes - The configuration options ### Returns `void` ### Errors - Returns an error if configuration cannot be applied or if downloads fail. - Throws `Error`. ``` -------------------------------- ### Get the node's start byte offset Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-c.md The `ts_pack_start_byte` function returns the inclusive start byte offset of the node within its source. ```c uintptr_t ts_pack_start_byte(); ``` -------------------------------- ### Get Parser for Language Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-php.md Convenience function to get a pre-configured Parser for a specific language. Handles language lookup and parser setup in one step. ```php public static function getParser(string $name): Parser ``` -------------------------------- ### Node.startByte() Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-typescript.md Gets the inclusive start byte offset of the node within its source. ```APIDOC ## startByte(): number ### Description Return the inclusive start byte offset of this node. ### Returns - **number** - The starting byte offset. ``` -------------------------------- ### Java Node startPosition() Signature Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-java.md Signature for getting the start Point (row, column). ```java public Point startPosition() ``` -------------------------------- ### Node.StartByte Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Gets the inclusive start byte offset of the node within the source text. ```APIDOC ## StartByte() ### Description Return the inclusive start byte offset of this node. ### Signature ```csharp public nuint StartByte() ``` ``` -------------------------------- ### init Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-dart.md Initializes the language pack with the given configuration, applying custom cache directories and downloading specified languages and groups. This is the recommended entry point for pre-warming the cache. ```APIDOC ## init(PackConfig config) ### Description 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. ### Signature ```dart void init(PackConfig config) ``` ### Parameters #### Path Parameters - **config** (PackConfig) - Required - The configuration options ### Returns `void` ### Errors Throws `Error` if configuration cannot be applied or if downloads fail. ``` -------------------------------- ### Initialize Language Pack Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-swift.md Initializes the language pack with the given configuration, applying custom cache directories and downloading specified languages and groups. This is the recommended entry point for pre-warming the cache. Errors if configuration cannot be applied or downloads fail. ```swift public static func init(config: PackConfig) throws ``` -------------------------------- ### Java Node startByte() Signature Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-java.md Signature for getting the inclusive start byte offset of this node. ```java public long startByte() ``` -------------------------------- ### Get Installed Languages Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-csharp.md Retrieves a list of language parsers that are already downloaded and cached on the system. ```csharp public List InstalledLanguages() ``` -------------------------------- ### Rust Quick Start: Parse and Process Code Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/SKILL.md Demonstrates parsing source code and extracting code intelligence using the Rust API. ```rust use tree_sitter_language_pack::{ parse_string, process, ProcessConfig, available_languages }; // List languages println!("{} languages available", available_languages().len()); // Parse code let tree = parse_string("python", b"def hello(): pass")?; println!("{}", tree.root_node().kind()); // "module" // Extract intelligence let config = ProcessConfig::new("python").all(); let result = process("def hello(): pass", &config)?; println!("Functions: {}", result.structure.len()); ``` -------------------------------- ### Get Parser for a Language Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-zig.md Retrieves a pre-configured Parser for a specified language. Use this for a convenient way to get a parser without manual setup. It handles language lookup and parser configuration in one step. ```zig pub fn get_parser(name: [:0]const u8) Error!Parser ``` -------------------------------- ### Download All Best Effort Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-zig.md Downloads the platform bundle and extracts all library files. It extracts all .so/.dylib/.dll files from the bundle without checking the manifest against archive contents. Languages in the manifest missing from the archive are silently ignored. ```zig pub fn downloadAllBestEffort(self: *const DownloadManager) Error!u64 ``` -------------------------------- ### Build Docker Image (Dockerfile) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/configuration.md Example Dockerfile command to build an image that includes pre-baked parsers. ```dockerfile docker build -t myapp . ``` -------------------------------- ### Node.startByte() Method Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-dart.md Gets the starting byte offset of the node within the source text. This offset is inclusive. ```dart int startByte() ``` -------------------------------- ### Get Default Language Registry Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-php.md Obtain a default instance of `LanguageRegistry` using the static `default()` method. This is useful for starting with a pre-configured registry. ```php public static function default(): LanguageRegistry ``` -------------------------------- ### Init Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-go.md Initializes the language pack with the given configuration, applying custom cache directories and downloading specified languages and groups. ```APIDOC ## Init() ### Description Initializes the language pack with the provided configuration. This function applies custom cache directories and downloads all specified languages and groups. It is the recommended entry point for pre-warming the cache before use. ### Signature ```go func Init(config PackConfig) error ``` ### Parameters #### Path Parameters - **config** (PackConfig) - Yes - The configuration options for initialization ### Returns - `error` - An error if the configuration cannot be applied or if downloads fail. ``` -------------------------------- ### Check PHP Language Availability and Count Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/snippets/php/quickstart.md Demonstrates how to check if the PHP grammar is installed and get the total count of available languages using the TreeSitterLanguagePack class. ```php ``` -------------------------------- ### Usage Example for Cache Directory Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/cli-reference.md Demonstrates how to capture the cache directory path in a script and use it for operations like checking cache size. ```bash CACHE=$(ts-pack cache-dir) du -sh "$CACHE" # Show cache size ``` -------------------------------- ### Initialize Language Pack Configuration Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/guides/cli.md Creates a language-pack.toml configuration file in the current directory. Options allow setting a custom cache directory or pre-filling languages. ```bash ts-pack init [OPTIONS] ``` ```bash ts-pack init ``` ```bash ts-pack init --languages python,javascript,typescript,rust ``` ```toml # language-pack.toml # languages = ["python", "rust"] ``` ```toml languages = ["python", "rust"] ``` -------------------------------- ### Accessing Import Statement Information Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/concepts/code-intelligence.md Loop through the 'imports' list in the result to get information about each import statement, including the source module, imported names, and starting line number. ```Python for imp in result["imports"]: print(imp["source"]) # "os" or "pathlib" print(imp["names"]) # ["path", "getcwd"] (empty = wildcard or bare import) print(imp["start_line"]) ``` -------------------------------- ### init Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-ruby.md Initializes the language pack with a given configuration, applying custom cache directories and downloading specified languages and groups. ```APIDOC ## init() ### Description 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. ### Signature ```ruby def self.init(config) ``` ### Parameters #### Path Parameters - **config** (PackConfig) - Yes - The configuration options ### Returns `nil` ### Errors Returns an error if configuration cannot be applied or if downloads fail. Raises `Error`. ``` -------------------------------- ### Install Ruby Gem Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/other-bindings.md Install the tree_sitter_language_pack Ruby gem using the gem install command or add it to your Gemfile. ```bash gem install tree_sitter_language_pack # Or in Gemfile: gem "tree_sitter_language_pack" ``` -------------------------------- ### Initialize Language Pack Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-go.md Initializes the language pack with custom configuration, including cache directories and downloading specified languages and groups. This is recommended for pre-warming the cache. Returns an error if configuration fails or downloads are unsuccessful. ```go func Init(config PackConfig) error ``` -------------------------------- ### Python Quick Start: Parse and Process Code Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/SKILL.md Demonstrates parsing source code and extracting code intelligence like functions and docstrings using the Python API. ```python from tree_sitter_language_pack import ( parse_string, process, ProcessConfig, available_languages ) # List available languages print(f"{len(available_languages())} languages supported") # Parse source code tree = parse_string("python", "def hello(): pass") print(tree.root_node_type()) # "module" print(tree.has_error_nodes()) # False print(tree.contains_node_type("function_definition")) # True # Extract code intelligence config = ProcessConfig("python", structure=True, imports=True, docstrings=True) result = process("def hello(): pass", config) print(f"Functions: {len(result['structure'])}") ``` -------------------------------- ### Initialize Language Pack Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/reference/api-ruby.md Initializes the language pack with a given configuration, applying custom cache directories and downloading specified languages and groups. This is the recommended entry point for pre-warming the cache. Errors are raised if configuration fails or downloads are unsuccessful. ```ruby LanguagePack.init(pack_config) ``` -------------------------------- ### Pre-download Parsers and Create Archive (Bash) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/configuration.md Downloads all necessary parsers and creates a compressed archive of the cache for deployment. ```bash ts-pack download --all tar czf parsers.tar.gz ~/.cache/tree-sitter-language-pack ``` -------------------------------- ### Node.js: Download and Initialize Tree-sitter Languages Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/snippets/typescript/download.md Demonstrates how to pre-download specific Tree-sitter languages and initialize the language pack with a custom cache directory. It also shows how to check the status of downloaded and manifest languages. ```typescript import { init, download, downloadedLanguages, manifestLanguages, } from "@kreuzberg/tree-sitter-language-pack"; // Pre-download specific languages const count = download(["python", "javascript", "rust"]); console.log(`Downloaded ${count} languages`); // Or initialize with config init({ languages: ["python", "go"], cacheDir: "/tmp/parsers" }); // Check what's cached console.log(downloadedLanguages()); console.log(manifestLanguages().slice(0, 5)); ``` -------------------------------- ### Initialize Language Pack (Bash) Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/skills/tree-sitter-language-pack/references/configuration.md Initializes the language pack by creating a configuration file with specified languages. ```bash ts-pack init --languages python,rust,typescript ``` -------------------------------- ### Verify PHP installation Source: https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/docs/getting-started/installation.md Use the `ts_pack_language_count` function to verify the PHP installation. ```php