Skip to content

feat(parsers): add PowerShell language support - #350

Merged
e91d82c73 merged 1 commit into
chunkhound:mainfrom
GoodOlClint:feat/powershell-language-support
Jun 29, 2026
Merged

e91d82c73 merged 1 commit into
chunkhound:mainfrom
GoodOlClint:feat/powershell-language-support

Conversation

@GoodOlClint

Copy link
Copy Markdown
Contributor

What

Adds first-class PowerShell support to ChunkHound. .ps1 / .psm1 files now
route through a dedicated tree-sitter mapping that emits
function/class/method/property/enum-aware chunks instead of falling through to
the generic UNKNOWN text parser.

Why

On main, PowerShell files are unsupported: detect_language returns
Language.UNKNOWN and a .ps1 file yields only a couple of untyped fallback
chunks. PowerShell users (and AI assistants searching their codebases) get no
function/class/method structure to search against. This change gives them the
same typed, semantically-aware chunking every other supported language already
enjoys.

How

  • The PowerShell grammar already ships with tree-sitter-language-pack, so no
    new pip dependency is needed. It is wired via the existing
    _LanguagePackWrapper path (_get_lang("powershell")), exactly like
    matlab / swift / objc.

  • New PowerShellMapping (chunkhound/parsers/mappings/powershell.py) maps the
    real grammar node types:

    node type ChunkType
    function_statement FUNCTION (covers function and filter)
    class_statement CLASS
    class_method_definition METHOD
    class_property_definition PROPERTY
    enum_statement ENUM
  • Landmine handled: the router in universal_parser checks
    elif kind == "class" or "class" in node_type. Both
    class_method_definition and class_property_definition contain the
    substring "class", so exposing the raw node_type would mis-route methods
    and properties to ChunkType.CLASS. The mapping therefore routes on the
    kind metadata only and never sets node_type.

Touchpoints

  • chunkhound/core/types/common.py — Language.POWERSHELL; .ps1/.psm1
    in the detection extension map; added to is_programming_language and
    supports_classes.
  • chunkhound/parsers/parser_factory.py — language-pack wrapper, mapping
    import, LANGUAGE_CONFIGS entry, EXTENSION_TO_LANGUAGE entries.
  • chunkhound/parsers/mappings/powershell.py — new mapping.
  • chunkhound/parsers/mappings/__init__.py — export.
  • Tests — new tests/test_powershell_mapping.py; PowerShell samples added to
    test_parsers.py, test_language_extensions.py,
    test_e2e_chunk_size_constraints.py, test_qa_deterministic.py.

Evidence (before → after)

1. Routing flips (wiring proof)

$ chunkhound … detect_language(Path('x.ps1'))
main:        Language.UNKNOWN
this branch: Language.POWERSHELL

2. Typed chunks (behavior proof)

main only emits a couple of untyped fallback chunks for a .ps1. On this
branch, parsing through the real parser
(create_parser(Language.POWERSHELL).parse_content(...)) yields:

function   Get-Foo
class      Widget
property   Size
method     Spin

The new contract test (tests/test_powershell_mapping.py) asserts
ChunkType.FUNCTION == "Get-Foo", ChunkType.CLASS == "Widget",
ChunkType.METHOD == "Spin", ChunkType.PROPERTY == "Size" — typed symbols the
UNKNOWN fallback cannot produce, so the test fails on main and passes here.

3. CLI end-to-end (real pipeline)

$ chunkhound index <dir> --db <db> --no-embeddings
Processed: 1 files
Total chunks: 4

$ chunkhound search --regex "Get-Foo" <dir> --db <db>
[1] sample.ps1  Lines 1-5
    function Get-Foo { … }

Quality gate

  • pytest tests/test_powershell_mapping.py tests/test_language_extensions.py tests/test_parsers.py — 145 passed
  • pytest tests/test_smoke.py -n auto — 18 passed (mandatory gate)
  • ruff check on changed files — clean (the only remaining ruff hits are
    pre-existing import-ordering issues already present on main)
  • mypy chunkhound/parsers/mappings/powershell.py — clean

Note on the new-language coverage tests

Language enum members are guarded by coverage tests
(test_qa_deterministic, test_e2e_chunk_size_constraints,
test_parsers) that require a sample for every language; PowerShell samples
were added to each. Pre-existing, unrelated full-suite failures on this machine
(node/tests/site/* build tests, git tag docs-version contract tests, and a
makefile chunk-size assertion) reproduce identically on clean main and are
not touched by this change.

Notes / scope

  • .psd1 (data manifests) is intentionally not routed to the PS grammar —
    .ps1 and .psm1 are the script extensions that benefit from code-aware
    chunking.
  • Small adjacent same-kind members (e.g. two tiny methods in one class) merge
    under the generic cAST greedy-merge, identical to every other language — this
    is existing chunking behavior, not PowerShell-specific.

Route .ps1/.psm1 files through a dedicated tree-sitter mapping so
PowerShell users get function/class/method/property/enum-aware chunks
instead of the generic UNKNOWN text fallback (which only emits ~2
untyped chunks per file).

The grammar already ships with tree-sitter-language-pack, so this wires
it via the existing _LanguagePackWrapper path (no new dependency),
mirroring matlab/swift. The mapping routes ChunkType purely on the
"kind" metadata and never exposes the raw node_type: PowerShell's
class_method_definition / class_property_definition node types both
contain the substring "class", which the router's `"class" in node_type`
check would otherwise mis-route to ChunkType.CLASS.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@e91d82c73

Copy link
Copy Markdown
Collaborator

Clean, minimal PowerShell support that follows the established patterns.

Support for DATA sections and .psd1 files can be added later.

@e91d82c73
e91d82c73 added this pull request to the merge queue Jun 29, 2026
Merged via the queue into chunkhound:main with commit bc146da Jun 29, 2026
17 checks passed
@GoodOlClint
GoodOlClint deleted the feat/powershell-language-support branch July 3, 2026 17:31
ofriw added a commit that referenced this pull request Jul 6, 2026
…CP read-only, and fixes

Merge main into matryoshka-fix-6-26.

main changes incorporated:
- DuckDB compaction with atomic swap (#339)
- PowerShell (#350) and Metal (#351) language parsers
- MCP --read-only flag (#329)
- Research per-step timing (#355)
- Various fixes: websearch late-completion guard, quickresearch
  orphan cleanup, token literal counting, claude-cli auto-updater
- openai_compatible in factory's supported_providers()

Conflict resolution: chunkhound/services/realtime_indexing_service.py
was deleted on main (dead code, no production callers). The branch's
ModuleType __class__ hack + its test were removed to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants