Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tree-sitter-java = "0.23"
tree-sitter-c = "0.23"
tree-sitter-cpp = "0.23"
tree-sitter-ruby = "0.23"
tree-sitter-php = "0.23"

# Serialization
serde = { version = "1", features = ["derive"] }
Expand Down
56 changes: 55 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl SymbolIndex {
"impl_item" => "impl",
"enum_item" | "enum_declaration" => "enum",
"interface_declaration" => "interface",
"trait_item" => "trait",
"trait_item" | "trait_declaration" => "trait",
"type_alias_declaration" | "type_item" | "type_declaration" => "type",
"arrow_function" => "arrow_fn",
"export_statement" => "export",
Expand Down Expand Up @@ -290,6 +290,19 @@ impl SymbolIndex {
("module", NameExtractor::Field("name")),
],
},
// PHP
LangConfig {
language: tree_sitter_php::LANGUAGE_PHP.into(),
extensions: &["php"],
symbol_queries: vec![
("function_definition", NameExtractor::Field("name")),
("method_declaration", NameExtractor::Field("name")),
("class_declaration", NameExtractor::Field("name")),
("interface_declaration", NameExtractor::Field("name")),
("trait_declaration", NameExtractor::Field("name")),
("enum_declaration", NameExtractor::Field("name")),
],
},
]
}
}
Expand Down Expand Up @@ -818,4 +831,45 @@ end
find_sym(&symbols, "bark");
find_sym(&symbols, "Helpers");
}

// ── 20. PHP ─────────────────────────────────────────────────────────

#[test]
fn test_parse_php() {
let dir = TempDir::new().unwrap();
write_file(&dir, "app.php", r#"<?php
class UserController {
public function index() {
return "list";
}

public function store(Request $request) {
return "created";
}
}

interface Authenticatable {
public function getAuthIdentifier();
}

trait HasRoles {
public function hasRole(string $role): bool {
return true;
}
}

function helper_function() {
return 42;
}
"#);
let idx = SymbolIndex::new(dir.path().to_str().unwrap()).unwrap();
let symbols = idx.scan_all().unwrap();

find_sym(&symbols, "UserController");
find_sym(&symbols, "index");
find_sym(&symbols, "store");
find_sym(&symbols, "Authenticatable");
find_sym(&symbols, "HasRoles");
find_sym(&symbols, "helper_function");
}
}
Loading