Skip to content

feat: Add HLSL / Shader language support#370

Open
colinchen1984 wants to merge 1 commit into
colbymchenry:mainfrom
colinchen1984:feat/hlsl-shader-support
Open

feat: Add HLSL / Shader language support#370
colinchen1984 wants to merge 1 commit into
colbymchenry:mainfrom
colinchen1984:feat/hlsl-shader-support

Conversation

@colinchen1984
Copy link
Copy Markdown

Summary

Adds HLSL (High-Level Shader Language) support to CodeGraph, enabling indexing of shader files used in game engines and GPU programming.

Changes

New files

  • src/extraction/languages/hlsl.ts — Language extractor (based on C++ extractor template)
  • src/extraction/wasm/tree-sitter-hlsl.wasm — Pre-built WASM grammar from tree-sitter-grammars/tree-sitter-hlsl

Modified files

  • src/types.ts — Added hlsl to LANGUAGES array
  • src/extraction/grammars.ts — WASM grammar registration, extension mappings, display name, custom WASM path
  • src/extraction/languages/index.ts — Import and register hlslExtractor

Supported file extensions

Extension Description
.hlsl Standard HLSL
.usf Unreal Shader File (UE HLSL variant)
.ush Unreal Shader Header (UE HLSL variant)
.glsl OpenGL Shading Language (parsed by HLSL grammar as C-like shader)

Why bundled WASM

tree-sitter-hlsl is not included in the tree-sitter-wasms package. The WASM is pre-built using tree-sitter build --wasm and follows the same bundling pattern as pascal, scala, lua, and luau.

Tested

  • Parsing .usf files from Unreal Engine 5 (VirtualShadowMapProjection, ShadowDepthPixelShader, etc.)
  • Function extraction: MainPS, VirtualShadowMapGetPageFlag, etc.
  • Include tracking: #include "Common.ush"
  • Verified on Windows with Node.js 24

Related: #283 (language documentation)

- Add tree-sitter-hlsl WASM grammar (builds from tree-sitter-grammars/tree-sitter-hlsl)
- Add languages/hlsl.ts extractor (based on C++ extractor)
- Register .hlsl, .usf, .ush, .glsl extensions in EXTENSION_MAP
- Maps all shader extensions to HLSL grammar (USF/USH are Unreal Engine HLSL variants)

Enables CodeGraph to index shader files in Unreal Engine, Unity, and
other HLSL/GLSL-based projects. Parses function definitions, structs,
enums, includes, and function calls.

Fixes colbymchenry#283 (partially — documents new language support)
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.

1 participant