Skip to main content

detecting-languages

Use when the user wants to know which programming language a file or snippet is. Covers implicit detection in `ts-pack parse`/`process`, confirming support with `ts-pack list`/`info`, and the SDK detection functions for path, extension, and raw content.

소스 정보

저장소
xberg-io/tree-sitter-language-pack
최근 소스 활동
2026년 9월 14일 08:59
감지된 SKILL.md 언어
영어
스타
471
포크
69

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
detecting-languages
description
Use when the user wants to know which programming language a file or snippet is. Covers implicit detection in `ts-pack parse`/`process`, confirming support with `ts-pack list`/`info`, and the SDK detection functions for path, extension, and raw content.
<!-- AI-RULEZ :: GENERATED FILE — DO NOT EDIT Content-Hash: blake3:70b679986812101189d1165f8f97d0a057d94d950920f1fff75724636e88291e Source-Hash: blake3:70559811033def67b9afc84aff0b0dd18329e8b04263cffeca7336545e95ab3c Schema-Version: v1 --> # Detecting languages tree-sitter-language-pack maps a file to one of 371 supported languages. Detection works from a file path, a bare extension, or — via the SDK — the file content itself. ## On the CLI: detection is implicit There is no standalone `ts-pack detect` command. `parse` and `process` auto-detect the language from the file extension and act on it: ```bash ts-pack parse src/app.ts # detects "typescript", parses ts-pack process app.py # detects "python", extracts ``` When detection fails (no extension, ambiguous, or stdin), pass `--language`: ```bash cat snippet | ts-pack parse - --language go ``` To check whether a language name is supported and cached without parsing anything, use `list` and `info`: ```bash ts-pack list --filter type # languages whose name contains "type" ts-pack list --manifest # every language in the remote manifest ts-pack info typescript # is it known? is it downloaded? cache path? ``` ## In the SDK: explicit detection The core exposes three detection functions, including content-based detection that the CLI does not surface: | Function | Detects from | | -------- | ------------ | | `detect_language_from_path(path)` | Full path (uses the extension). | | `detect_language_from_extension(ext)` | A bare extension like `"rs"`. | | `detect_language_from_content(content)` | Raw source text — no path needed. | Each returns the language name or null/None when no grammar matches. ### Python ```python from tree_sitter_language_pack import ( detect_language_from_path, detect_language_from_extension, detect_language_from_content, ) detect_language_from_path("src/app.py") # "python" detect_language_from_extension("rs") # "rust" detect_language_from_content(open("x").read()) # from the shebang line, if present ``` ### Node.js / TypeScript ```typescript import { detectLanguageFromPath, detectLanguageFromContent } from "@xberg-io/tree-sitter-language-pack"; const lang = detectLanguageFromPath("src/app.ts") ?? detectLanguageFromContent(source); ``` ## Choosing CLI vs SDK - Path or extension is enough, one-shot → just run `ts-pack parse`/`process` and let it auto-detect. - Only raw content (a pasted snippet, a stream, a file with no extension) → use the SDK's `detect_language_from_content`, then pass the result as `--language` to the CLI if needed. ## When to reach for the other skills Once the language is known, hand off to `parsing-source` (syntax tree) or `extracting-code-structure` (metadata). To see or prefetch the parser for a detected language, see `managing-parsers`.
GitHub에서 보기