### Get Grammar Info - forest.Info() Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Retrieves grammar information for a specified language. Returns nil if the language is not found. The Grammar struct implements Stringer for easy printing and provides direct field access. ```go package main import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { gr := forest.Info("ada") if gr == nil { fmt.Println("not found") return } // Stringer output: ada, src: "@", sha: "" fmt.Println(gr) // Access fields directly. fmt.Println("Language:", gr.Language) fmt.Println("URL: ", gr.URL) fmt.Println("Revision:", gr.Revision) // Info for a language with an alternate name. reqGr := forest.Info("requirements") if reqGr != nil { fmt.Println("AltName:", reqGr.AltName) // "Pip requirements" } } ``` -------------------------------- ### Check Supported Tree-sitter Languages with forest.SupportedLanguages Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Use forest.SupportedLanguages() to get a sorted slice of all supported language names, and forest.SupportedLanguage(lang) to check if a specific language is supported. These functions are derived from embedded grammars.json. ```go package main import ( "fmt" "slices" forest "github.com/alexaandru/go-sitter-forest" ) func main() { all := forest.SupportedLanguages() fmt.Printf("Total supported languages: %d\n", len(all)) // Total supported languages: 510 // Check specific languages. for _, lang := range []string{"go", "python", "rust", "typescript", "cobol", "bogus"} { fmt.Printf(" %-20s supported=%v\n", lang, forest.SupportedLanguage(lang)) } // go supported=true // python supported=true // rust supported=true // typescript supported=true // cobol supported=true // bogus supported=false // Check whether a specific language is in the list. fmt.Println("has zig:", slices.Contains(all, "zig")) // true fmt.Println("has java:", slices.Contains(all, "java")) // true } ``` -------------------------------- ### Get Grammar Information Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Retrieves grammar information for a specified language. The returned Grammar struct includes language name, URL, revision, and alternate name. It also implements the Stringer interface for easy printing. ```APIDOC ## Get Grammar Information - `forest.Info(lang string)` ### Description Retrieves grammar information for a specified language. The returned `*grammar.Grammar` struct includes fields like `Language`, `URL`, `Revision`, and `AltName`. The `Grammar` type implements `Stringer` for convenient human-readable output. ### Method `forest.Info(lang string)` ### Parameters #### Path Parameters - **lang** (string) - Required - The language identifier for which to retrieve grammar information. ### Response #### Success Response - **`*grammar.Grammar`** - A pointer to a Grammar struct containing language details, or nil if the language is not found. ### Example ```go import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { gr := forest.Info("ada") if gr == nil { fmt.Println("not found") return } fmt.Println(gr) fmt.Println("Language:", gr.Language) fmt.Println("URL:", gr.URL) fmt.Println("Revision:", gr.Revision) reqGr := forest.Info("requirements") if reqGr != nil { fmt.Println("AltName:", reqGr.AltName) } } ``` ``` -------------------------------- ### Build Parser Plugins - Plugins.make Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Generates Go plugin (.so) files for on-demand parser loading. The binary must be built with -trimpath. Plugins are loaded at runtime using the standard 'plugin' package. ```makefile # Copy Plugins.make into your project, then: # Build a single parser plugin: make -f Plugins.make plugin-python # => python.so ``` -------------------------------- ### Build All Parser Plugins Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Command to build all parser plugins, resulting in a large number of .so files. ```makefile make -f Plugins.make plugin-all ``` -------------------------------- ### Fetch Rust Queries with Individual Parser Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Shows how to fetch different types of queries (highlights, injections) for the Rust parser using GetQuery. Handles optional query source preferences and non-existent query kinds. ```go package main import ( "fmt" "github.com/alexaandru/go-sitter-forest/rust" ) func main() { // Fetch the nvim_treesitter highlights query for Rust (default: NvimFirst). hiQuery := rust.GetQuery("highlights") fmt.Printf("highlights.scm (%d bytes)\n", len(hiQuery)) // Fetch only the native (upstream sitter repo) highlights query. nativeHi := rust.GetQuery("highlights", rust.NativeOnly) fmt.Printf("native highlights.scm (%d bytes)\n", len(nativeHi)) // Fetch injections query (no .scm extension required, but accepted too). injQuery := rust.GetQuery("injections.scm") fmt.Printf("injections.scm (%d bytes)\n", len(injQuery)) // Non-existent query kind returns nil/empty slice — safe to check with len(). missing := rust.GetQuery("bogus") fmt.Println("missing:", len(missing) == 0) // true } ``` -------------------------------- ### Bulk Parser Usage with Forest Package in Go Source: https://github.com/alexaandru/go-sitter-forest/blob/main/README.md Shows how to use all or most parsers dynamically via the `forest` package. This approach results in a significantly larger binary size. `forest.GetLanguage()` returns a `*sitter.Language` directly usable with `parser.SetLanguage()`. ```Go package main import ( "context" "fmt" forest "github.com/alexaandru/go-sitter-forest" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { content := []byte("print('It works!')\n") parser := sitter.NewParser() parser.SetLanguage(forest.GetLanguage("risor")) tree, err := parser.Parse(context.TODO(), nil, content) if err != nil { panic(err) } // Do something interesting with the parsed tree... fmt.Println(tree.RootNode()) } ``` -------------------------------- ### Parse Python Code with Individual Parser Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Demonstrates parsing Python code using the individual python parser. Ensure sitter.NewLanguage() wraps the unsafe.Pointer from GetLanguage(). ```go package main import ( "context" "fmt" "github.com/alexaandru/go-sitter-forest/python" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { src := []byte(` def greet(name: str) -> str: return f"Hello, {name}!" `) // sitter.NewLanguage() wraps the unsafe.Pointer returned by the individual package. node, err := sitter.Parse(context.TODO(), src, sitter.NewLanguage(python.GetLanguage())) if err != nil { panic(err) } fmt.Println(node) // Output: (module (function_definition name: (identifier) parameters: ...)) } ``` -------------------------------- ### Standalone Parser Usage in Go Source: https://github.com/alexaandru/go-sitter-forest/blob/main/README.md Demonstrates how to use a single Tree-sitter parser in a Go application. Requires wrapping the language pointer with `sitter.NewLanguage()` when passing to `sitter.Parse()`. ```Go package main import ( "context" "fmt" "github.com/alexaandru/go-sitter-forest/risor" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { content := []byte("print('It works!')\n") node, err := sitter.Parse(context.TODO(), content, sitter.NewLanguage(risor.GetLanguage())) if err != nil { panic(err) } // Do something interesting with the parsed tree... fmt.Println(node) } ``` -------------------------------- ### GetLanguage() - Individual Parser Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Each language sub-module exports a GetLanguage() function. This function returns an unsafe.Pointer that must be wrapped with sitter.NewLanguage() before use. This is the most lightweight import option, as only the specific parser's C code is compiled into your binary. ```APIDOC ## GetLanguage() ### Description Retrieves the language parser for a specific language module. ### Usage ```go import ( "context" "fmt" "github.com/alexaandru/go-sitter-forest/python" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { ssrc := []byte(` def greet(name: str) -> str: return f"Hello, {name}!" `) // sitter.NewLanguage() wraps the unsafe.Pointer returned by the individual package. node, err := sitter.Parse(context.TODO(), src, sitter.NewLanguage(python.GetLanguage())) if err != nil { panic(err) } fmt.Println(node) // Output: (module (function_definition name: (identifier) parameters: ...)) } ``` ### Parameters None ### Returns - `unsafe.Pointer`: A pointer to the language parser. This should be wrapped with `sitter.NewLanguage()`. ``` -------------------------------- ### GetQuery(kind, ...opts) - Individual Parser Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Every language sub-module exposes GetQuery(kind string, opts ...byte). This function returns the embedded .scm query file for that parser. The 'kind' argument specifies the type of query (e.g., 'highlights', 'injections'), and optional 'opts' can be used to select the query source preference. ```APIDOC ## GetQuery(kind, ...opts) ### Description Fetches an embedded query file (e.g., for syntax highlighting, indentation) for a specific language parser. ### Usage ```go import ( "fmt" "github.com/alexaandru/go-sitter-forest/rust" ) func main() { // Fetch the nvim_treesitter highlights query for Rust (default: NvimFirst). hiQuery := rust.GetQuery("highlights") fmt.Printf("highlights.scm (%d bytes)\n", len(hiQuery)) // Fetch only the native (upstream sitter repo) highlights query. nativeHi := rust.GetQuery("highlights", rust.NativeOnly) fmt.Printf("native highlights.scm (%d bytes)\n", len(nativeHi)) // Fetch injections query (no .scm extension required, but accepted too). injQuery := rust.GetQuery("injections.scm") fmt.Printf("injections.scm (%d bytes)\n", len(injQuery)) // Non-existent query kind returns nil/empty slice — safe to check with len(). missing := rust.GetQuery("bogus") fmt.Println("missing:", len(missing) == 0) // true } ``` ### Parameters - **kind** (string) - Required - The type of query to fetch (e.g., "highlights", "injections", "indents", "folds", "locals", "textobjects"). The ".scm" suffix is optional. - **opts** ([]byte) - Optional - Query source preference. Options include `NvimFirst`, `NativeFirst`, `NvimOnly`, `NativeOnly`. Defaults to `NvimFirst`. ### Returns - `[]byte`: A byte slice containing the content of the requested query file. Returns an empty slice if the query kind is not found. ``` -------------------------------- ### Info() - Individual Parser Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Each language sub-module provides an Info() string function. This function returns the raw JSON entry from grammars.json, which includes metadata about the parser's upstream source URL, git SHA revision, and other details. ```APIDOC ## Info() ### Description Retrieves metadata about the language parser, including its upstream source URL and revision. ### Usage ```go import ( "encoding/json" "fmt" "github.com/alexaandru/go-sitter-forest/typescript" ) func main() { raw := typescript.Info() var meta map[string]any if err := json.Unmarshal([]byte(raw), &meta); err != nil { panic(err) } fmt.Println("language:", meta["language"]) fmt.Println("src:", meta["src"]) fmt.Println("revision:", meta["revision"]) // language: typescript // src: https://github.com/tree-sitter/tree-sitter-typescript // revision: } ``` ### Parameters None ### Returns - `string`: A JSON string containing metadata about the parser, including 'language', 'src', and 'revision'. ``` -------------------------------- ### Fetch Tree-sitter Queries with forest.GetQuery Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Use forest.GetQuery to fetch queries, supporting recursive resolution of '; inherits:' directives across parser boundaries. This function allows specifying query preferences like NvimFirst or NativeOnly. ```go package main import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { // TSX folds folds inherits typescript -> ecma -> jsx; forest resolves the full chain. tsxFolds := forest.GetQuery("tsx", "folds") fmt.Printf("tsx folds (with inheritance): %d bytes\n", len(tsxFolds)) // Prefer native (upstream repo) query over nvim_treesitter. goNative := forest.GetQuery("go", "highlights", forest.NativeOnly) fmt.Printf("go highlights (native only): %d bytes\n", len(goNative)) // Use NvimFirst (default): tries nvim_treesitter first, falls back to native. goNvim := forest.GetQuery("go", "highlights", forest.NvimFirst) fmt.Printf("go highlights (nvim first): %d bytes\n", len(goNvim)) // Unknown query kind returns empty — safe. empty := forest.GetQuery("python", "nonexistent") fmt.Println("empty:", len(empty) == 0) // true // Query preference constants: // forest.NvimFirst — prefer nvim_treesitter, fall back to native // forest.NativeFirst — prefer native, fall back to nvim_treesitter // forest.NvimOnly — only nvim_treesitter // forest.NativeOnly — only native sitter repo } ``` -------------------------------- ### Retrieve TypeScript Parser Metadata Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Demonstrates retrieving metadata for the TypeScript parser using the Info() function and unmarshalling the JSON output to access language, source, and revision details. ```go package main import ( "encoding/json" "fmt" "github.com/alexaandru/go-sitter-forest/typescript" ) func main() { raw := typescript.Info() var meta map[string]any if err := json.Unmarshal([]byte(raw), &meta); err != nil { panic(err) } fmt.Println("language:", meta["language"]) fmt.Println("src:", meta["src"]) fmt.Println("revision:", meta["revision"]) // language: typescript // src: https://github.com/tree-sitter/tree-sitter-typescript // revision: } ``` -------------------------------- ### Parse Go Source and Traverse Tree Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Parses Go source code using the standalone go sub-package and traverses the syntax tree to extract function names. Individual packages return unsafe.Pointer; wrap with sitter.NewLanguage(). ```go package main import ( "context" "fmt" Go "github.com/alexaandru/go-sitter-forest/go" sitter "github.com/alexaandru/go-tree-sitter-bare" ) // walkFunctions recursively walks a syntax tree node and prints function names. func walkFunctions(node *sitter.Node, src []byte) { if node == nil { return } if node.Type() == "function_declaration" { nameNode := node.ChildByFieldName("name") if nameNode != nil { fmt.Printf(" func %s (line %d)\n", nameNode.Content(src), nameNode.StartPoint().Row+1, ) } } for i := range node.ChildCount() { walkFunctions(node.Child(int(i)), src) } } func main() { src := []byte(`package main import "fmt" func Hello(name string) string { return fmt.Sprintf("Hello, %s!", name) } func main() { fmt.Println(Hello("World")) } `) // Note: individual package returns unsafe.Pointer; wrap with sitter.NewLanguage(). lang := sitter.NewLanguage(Go.GetLanguage()) tree, err := sitter.Parse(context.TODO(), src, lang) if err != nil { panic(err) } root := tree.RootNode() fmt.Printf("root type: %s, children: %d, errors: %v\n", root.Type(), root.ChildCount(), root.HasError()) fmt.Println("Functions found:") walkFunctions(root, src) // root type: source_file, children: 3, errors: false // Functions found: // func Hello (line 5) // func main (line 9) } ``` -------------------------------- ### Detect Language from File Path - forest.DetectLanguage() Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Detects the tree-sitter language name from a file path using multiple strategies: shebang/modeline, glob patterns, basename match, and extension match. Returns 'unknown' if no match is found. ```go package main import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { cases := []string{ "/home/user/project/main.go", // extension .go "/etc/nginx/nginx.conf", // basename nginx.conf "Makefile", // basename "script.py", // extension .py ".bashrc", // basename "styles.scss", // extension .scss "terraform/main.tf", // extension .tf -> hcl/terraform "/path/to/Dockerfile", // basename "unknown.xyz", // no match } for _, fpath := range cases { lang := forest.DetectLanguage(fpath) fmt.Printf("%-40s -> %s\n", fpath, lang) } // /home/user/project/main.go -> go // /etc/nginx/nginx.conf -> nginx // Makefile -> make // script.py -> python // .bashrc -> bash // styles.scss -> scss // terraform/main.tf -> terraform // /path/to/Dockerfile -> dockerfile // unknown.xyz -> unknown } ``` -------------------------------- ### Load Tree-sitter Languages with forest.GetLanguage Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Use forest.GetLanguage to retrieve a *sitter.Language directly by its tree-sitter name. Results are cached thread-safely. This is useful for parsing code snippets in various languages. ```go package main import ( "context" "fmt" forest "github.com/alexaandru/go-sitter-forest" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { langs := []struct { name string src string }{ {"go", `package main; func main() {}`}, {"typescript", `const x: number = 42;`}, {"rust", `fn main() { println!("hi"); }`}, {"python", `print("hello")`}, } parser := sitter.NewParser() for _, l := range langs { lang := forest.GetLanguage(l.name) if lang == nil { fmt.Printf("%s: not found\n", l.name) continue } parser.SetLanguage(lang) tree, err := parser.ParseString(context.TODO(), nil, []byte(l.src)) if err != nil { fmt.Printf("%s: parse error: %v\n", l.name, err) continue } root := tree.RootNode() fmt.Printf("%s: root=%s hasError=%v\n", l.name, root.Type(), root.HasError()) // go: root=source_file hasError=false // typescript: root=program hasError=false // rust: root=source_file hasError=false // python: root=module hasError=false } } ``` -------------------------------- ### Register Custom Language Mappings - forest.RegisterLanguage() Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Adds or overrides language mappings at runtime. Patterns can be globs, extensions, or basenames. Only supported languages are accepted. Returns an error for invalid inputs. ```go package main import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { // Override: .v files -> verilog instead of the default v (V language). if err := forest.RegisterLanguage(".v", "verilog"); err != nil { panic(err) } fmt.Println(forest.DetectLanguage("circuit.v")) // verilog // Register a custom glob pattern. if err := forest.RegisterLanguage("infra/*/main.tf", "hcl"); err != nil { panic(err) } fmt.Println(forest.DetectLanguage("/repo/infra/prod/main.tf")) // hcl // Register a custom basename. if err := forest.RegisterLanguage("Justfile", "just"); err != nil { panic(err) } fmt.Println(forest.DetectLanguage("Justfile")) // just // Error cases. fmt.Println(forest.RegisterLanguage("", "go")) // error: pattern is missing fmt.Println(forest.RegisterLanguage(".foo", "")) // error: language is missing fmt.Println(forest.RegisterLanguage(".foo", "bogus")) // error: language is invalid } ``` -------------------------------- ### GetQuery Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Fetches query definitions, resolving inheritance directives recursively across parser boundaries. Supports various query preference options. ```APIDOC ## GetQuery lang string, kind string, opts ...byte ### Description Fetches queries at the forest level, resolving `; inherits:` directives recursively across parser boundaries. Individual package `GetQuery` cannot do this cross-language resolution. Supports query preference constants like `NativeOnly` and `NvimFirst`. ### Parameters #### Path Parameters - **lang** (string) - Required - The language for which to fetch the query (e.g., "tsx", "go"). - **kind** (string) - Required - The type of query to fetch (e.g., "folds", "highlights"). #### Options - **opts** ([]byte) - Optional - Query preference constants (e.g., `forest.NativeOnly`, `forest.NvimFirst`). ### Response #### Success Response (200) - **queryBytes** ([]byte) - The query definition as a byte slice. Returns empty slice if the query kind is unknown or not found. ### Query Preference Constants - `forest.NvimFirst`: Prefer nvim_treesitter, fall back to native. - `forest.NativeFirst`: Prefer native, fall back to nvim_treesitter. - `forest.NvimOnly`: Only use nvim_treesitter. - `forest.NativeOnly`: Only use the native sitter repo. ``` -------------------------------- ### Load Compiled Parser Plugin Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Loads a compiled parser plugin (e.g., python.so) and retrieves the GetLanguage symbol. Ensure your app is also built with -trimpath. ```go package main import ( "fmt" "plugin" "unsafe" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { // Load the compiled plugin. // NOTE: your app must also be built with -trimpath. p, err := plugin.Open("python.so") if err != nil { panic(err) } sym, err := p.Lookup("GetLanguage") if err != nil { panic(err) } // GetLanguage from a plugin returns unsafe.Pointer. getLang := sym.(func() unsafe.Pointer) lang := sitter.NewLanguage(getLang()) fmt.Printf("loaded plugin language: %v\n", lang != nil) // true } ``` -------------------------------- ### SupportedLanguages and SupportedLanguage Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Provides functions to retrieve a list of all supported languages or check if a specific language is supported. ```APIDOC ## SupportedLanguages() ### Description Returns a sorted slice of all supported language name strings derived from the embedded `grammars.json`. ### Response #### Success Response (200) - **languages** ([]string) - A sorted slice of all supported language names. ## SupportedLanguage(lang string) ### Description Checks if a given language name is present in the list of supported languages. ### Parameters #### Path Parameters - **lang** (string) - Required - The language name to check (e.g., "go", "python"). ### Response #### Success Response (200) - **isSupported** (bool) - `true` if the language is supported, `false` otherwise. ``` -------------------------------- ### Register Custom Language Mapping Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Allows adding or overriding pattern-to-language mappings at runtime. The pattern type is inferred (glob, extension, or basename). Only languages already supported by `SupportedLanguages()` are accepted. ```APIDOC ## Register Custom Language Mapping - `forest.RegisterLanguage(pat string, lang string)` ### Description Adds or overrides a pattern-to-language mapping dynamically. The type of the pattern is inferred based on its content (glob, extension, or basename). Only languages that are already recognized by `SupportedLanguages()` can be registered. ### Method `forest.RegisterLanguage(pat string, lang string)` ### Parameters #### Path Parameters - **pat** (string) - Required - The pattern to associate with a language. Can be a glob pattern, a file extension (starting with '.'), or a basename. - **lang** (string) - Required - The language identifier to map the pattern to. Must be a supported language. ### Response #### Success Response - **error** - Returns nil if the registration is successful. #### Error Response - **error** - Returns an error if the pattern is missing, the language is missing, or the language is invalid/unsupported. ### Example ```go import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { // Override .v files to be recognized as 'verilog'. err := forest.RegisterLanguage(".v", "verilog") if err != nil { panic(err) } fmt.Println(forest.DetectLanguage("circuit.v")) // Output: verilog // Register a custom glob pattern. err = forest.RegisterLanguage("infra/*/main.tf", "hcl") if err != nil { panic(err) } fmt.Println(forest.DetectLanguage("/repo/infra/prod/main.tf")) // Output: hcl // Register a custom basename. err = forest.RegisterLanguage("Justfile", "just") if err != nil { panic(err) } fmt.Println(forest.DetectLanguage("Justfile")) // Output: just // Example of error cases: fmt.Println(forest.RegisterLanguage("", "go")) // Error: pattern is missing fmt.Println(forest.RegisterLanguage(".foo", "")) // Error: language is missing fmt.Println(forest.RegisterLanguage(".foo", "bogus")) // Error: language is invalid } ``` ``` -------------------------------- ### Detect Language from File Path Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Detects the tree-sitter language name from a given file path using multiple strategies including shebang/modeline, glob patterns, basename matching, and file extension matching. ```APIDOC ## Detect Language from File Path - `forest.DetectLanguage(fpath string)` ### Description Resolves a tree-sitter language name from a file path. It employs four strategies in order: shebang/Vim modeline, glob pattern matching, exact basename match, and file extension match. Returns "unknown" if no match is found. ### Method `forest.DetectLanguage(fpath string)` ### Parameters #### Path Parameters - **fpath** (string) - Required - The file path or filename to detect the language from. ### Response #### Success Response - **string** - The detected language name (e.g., "go", "python"), or "unknown" if no language could be identified. ### Example ```go import ( "fmt" forest "github.com/alexaandru/go-sitter-forest" ) func main() { cases := []string{ "/home/user/project/main.go", "/etc/nginx/nginx.conf", "Makefile", "script.py", ".bashrc", "styles.scss", "terraform/main.tf", "/path/to/Dockerfile", "unknown.xyz", } for _, fpath := range cases { lang := forest.DetectLanguage(fpath) fmt.Printf("% -40s -> %s\n", fpath, lang) } } ``` ``` -------------------------------- ### GetLanguage Source: https://context7.com/alexaandru/go-sitter-forest/llms.txt Retrieves a cached `*sitter.Language` for a given tree-sitter language name. Results are cached thread-safely. ```APIDOC ## GetLanguage lang string ### Description Accepts the tree-sitter language name (lowercase, matching folder names) and returns a `*sitter.Language` directly. Results are cached thread-safely. ### Parameters #### Path Parameters - **lang** (string) - Required - The tree-sitter language name (e.g., "go", "typescript"). ### Response #### Success Response (200) - **language** (*sitter.Language) - A pointer to the language definition. #### Not Found Response - **language** (nil) - If the language is not found. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.