fix: add PHP grammar support to smart-file-read parser (fixes #1617)

PHP was listed as a supported language in CHANGELOG and .php files were
scanned by search.ts, but parser.ts was missing:
- .php extension in LANG_MAP (causing detectLanguage to return 'unknown')
- 'php' entry in GRAMMAR_PACKAGES (no grammar path to resolve)
- PHP query patterns for symbol extraction
- PHP case in getQueryKey()

This meant smart_search/smart_outline/smart_unfold scanned PHP files
but extracted 0 symbols because the grammar could not be resolved.

Changes:
- Add '.php' -> 'php' to LANG_MAP
- Add 'php' -> 'tree-sitter-php/php' to GRAMMAR_PACKAGES
- Add PHP tree-sitter query patterns (functions, methods, classes, interfaces, traits, use statements)
- Add 'php' case to getQueryKey()
- Add tree-sitter-php ^0.24.2 to devDependencies
This commit is contained in:
Octopus
2026-04-06 10:02:18 +08:00
parent 811c94da36
commit 7def736f0a
2 changed files with 14 additions and 1 deletions
+1
View File
@@ -138,6 +138,7 @@
"tree-sitter-go": "^0.25.0",
"tree-sitter-java": "^0.23.5",
"tree-sitter-javascript": "^0.25.0",
"tree-sitter-php": "^0.24.2",
"tree-sitter-python": "^0.25.0",
"tree-sitter-ruby": "^0.23.1",
"tree-sitter-rust": "^0.24.0",
+13 -1
View File
@@ -3,7 +3,7 @@
*
* No native bindings. No WASM. Just the CLI binary + query patterns.
*
* Supported: JS, TS, Python, Go, Rust, Ruby, Java, C, C++
* Supported: JS, TS, Python, Go, Rust, Ruby, Java, C, C++, PHP
*
* by Copter Labs
*/
@@ -66,6 +66,7 @@ const LANG_MAP: Record<string, string> = {
".cxx": "cpp",
".hpp": "cpp",
".hh": "cpp",
".php": "php",
};
export function detectLanguage(filePath: string): string {
@@ -86,6 +87,7 @@ const GRAMMAR_PACKAGES: Record<string, string> = {
java: "tree-sitter-java",
c: "tree-sitter-c",
cpp: "tree-sitter-cpp",
php: "tree-sitter-php/php",
};
function resolveGrammarPath(language: string): string | null {
@@ -159,6 +161,15 @@ const QUERIES: Record<string, string> = {
(class_definition name: (identifier) @name) @cls
(import_statement) @imp
(import_declaration) @imp
`,
php: `
(function_definition name: (name) @name) @func
(method_declaration name: (name) @name) @method
(class_declaration name: (name) @name) @cls
(interface_declaration name: (name) @name) @iface
(trait_declaration name: (name) @name) @trait_def
(namespace_use_declaration) @imp
`,
};
@@ -173,6 +184,7 @@ function getQueryKey(language: string): string {
case "rust": return "rust";
case "ruby": return "ruby";
case "java": return "java";
case "php": return "php";
default: return "generic";
}
}