Skip to content

Commit dea5b7f

Browse files
committed
Exclude magic methods
1 parent 3f76f06 commit dea5b7f

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

src/completion/builder.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,36 @@ use tower_lsp::lsp_types::*;
77
use crate::Backend;
88
use crate::types::*;
99

10+
/// PHP magic methods that should not appear in completion results.
11+
/// These are invoked implicitly by the language runtime rather than
12+
/// called directly by user code.
13+
const MAGIC_METHODS: &[&str] = &[
14+
"__construct",
15+
"__destruct",
16+
"__clone",
17+
"__get",
18+
"__set",
19+
"__isset",
20+
"__unset",
21+
"__call",
22+
"__callStatic",
23+
"__invoke",
24+
"__toString",
25+
"__sleep",
26+
"__wakeup",
27+
"__serialize",
28+
"__unserialize",
29+
"__set_state",
30+
"__debugInfo",
31+
];
32+
1033
impl Backend {
34+
/// Check whether a method name is a PHP magic method that should be
35+
/// excluded from completion results.
36+
fn is_magic_method(name: &str) -> bool {
37+
MAGIC_METHODS.iter().any(|&m| m.eq_ignore_ascii_case(name))
38+
}
39+
1140
/// Build the label showing the full method signature.
1241
///
1342
/// Example: `regularCode(string $text, $frogs = false): string`
@@ -56,8 +85,12 @@ impl Backend {
5685
) -> Vec<CompletionItem> {
5786
let mut items: Vec<CompletionItem> = Vec::new();
5887

59-
// Methods — filtered by static / instance
88+
// Methods — filtered by static / instance, excluding magic methods
6089
for method in &target_class.methods {
90+
if Self::is_magic_method(&method.name) {
91+
continue;
92+
}
93+
6194
let include = match access_kind {
6295
AccessKind::Arrow => !method.is_static,
6396
AccessKind::DoubleColon => method.is_static,

src/composer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn resolve_class_path(
135135
// Empty prefix matches everything (root namespace fallback)
136136
Some(name)
137137
} else {
138-
name.strip_prefix(&mapping.prefix).map(|rest| rest)
138+
name.strip_prefix(&mapping.prefix)
139139
};
140140

141141
if let Some(relative_class) = relative {

src/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/// Data types used throughout the PHPantomLSP server.
2-
///
3-
/// This module contains all the "model" structs and enums that represent
4-
/// extracted PHP information (classes, methods, properties, constants)
5-
/// as well as completion-related types (AccessKind, CompletionTarget).
1+
//! Data types used throughout the PHPantomLSP server.
2+
//!
3+
//! This module contains all the "model" structs and enums that represent
4+
//! extracted PHP information (classes, methods, properties, constants)
5+
//! as well as completion-related types (AccessKind, CompletionTarget).
66
77
/// Stores extracted parameter information from a parsed PHP method.
88
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)