diff --git a/src/extraction/grammars.ts b/src/extraction/grammars.ts index c167d28b3..9e879c297 100644 --- a/src/extraction/grammars.ts +++ b/src/extraction/grammars.ts @@ -37,6 +37,7 @@ const WASM_GRAMMAR_FILES: Record = { scala: 'tree-sitter-scala.wasm', lua: 'tree-sitter-lua.wasm', luau: 'tree-sitter-luau.wasm', + hlsl: 'tree-sitter-hlsl.wasm', }; /** @@ -92,6 +93,11 @@ export const EXTENSION_MAP: Record = { '.sc': 'scala', '.lua': 'lua', '.luau': 'luau', + // Shader files (HLSL grammar with USF/USH/GLSL aliases) + '.hlsl': 'hlsl', + '.usf': 'hlsl', + '.ush': 'hlsl', + '.glsl': 'hlsl', }; /** @@ -169,7 +175,7 @@ export async function loadGrammarsForLanguages(languages: Language[]): Promise { + const importText = source.substring(node.startIndex, node.endIndex).trim(); + // HLSL includes: #include "Common.ush", #include "/Engine/Private/Common.ush" + const systemLib = node.namedChildren.find( + (c: SyntaxNode) => c.type === 'system_lib_string' + ); + if (systemLib) { + return { + moduleName: getNodeText(systemLib, source).replace(/^<|>$/g, ''), + signature: importText, + }; + } + const stringLiteral = node.namedChildren.find( + (c: SyntaxNode) => c.type === 'string_literal' + ); + if (stringLiteral) { + const stringContent = stringLiteral.namedChildren.find( + (c: SyntaxNode) => c.type === 'string_content' + ); + if (stringContent) { + return { + moduleName: getNodeText(stringContent, source), + signature: importText, + }; + } + } + return null; + }, +}; diff --git a/src/extraction/languages/index.ts b/src/extraction/languages/index.ts index a289f0289..6d713bbc7 100644 --- a/src/extraction/languages/index.ts +++ b/src/extraction/languages/index.ts @@ -25,6 +25,7 @@ import { pascalExtractor } from './pascal'; import { scalaExtractor } from './scala'; import { luaExtractor } from './lua'; import { luauExtractor } from './luau'; +import { hlslExtractor } from './hlsl'; export const EXTRACTORS: Partial> = { typescript: typescriptExtractor, @@ -47,4 +48,5 @@ export const EXTRACTORS: Partial> = { scala: scalaExtractor, lua: luaExtractor, luau: luauExtractor, + hlsl: hlslExtractor, }; diff --git a/src/extraction/wasm/tree-sitter-hlsl.wasm b/src/extraction/wasm/tree-sitter-hlsl.wasm new file mode 100644 index 000000000..7dcda3b49 Binary files /dev/null and b/src/extraction/wasm/tree-sitter-hlsl.wasm differ diff --git a/src/types.ts b/src/types.ts index 0168665d2..c76b96079 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,6 +87,7 @@ export const LANGUAGES = [ 'scala', 'lua', 'luau', + 'hlsl', 'yaml', 'twig', 'unknown',