Skip to main content

php_lsp/completion/
keyword.rs

1use tower_lsp::lsp_types::{CompletionItem, CompletionItemKind};
2
3const PHP_KEYWORDS: &[&str] = &[
4    "abstract",
5    "and",
6    "array",
7    "as",
8    "break",
9    "callable",
10    "case",
11    "catch",
12    "class",
13    "clone",
14    "const",
15    "continue",
16    "declare",
17    "default",
18    "die",
19    "do",
20    "echo",
21    "else",
22    "elseif",
23    "empty",
24    "enddeclare",
25    "endfor",
26    "endforeach",
27    "endif",
28    "endswitch",
29    "endwhile",
30    "enum",
31    "eval",
32    "exit",
33    "extends",
34    "final",
35    "finally",
36    "fn",
37    "for",
38    "foreach",
39    "function",
40    "global",
41    "goto",
42    "if",
43    "implements",
44    "include",
45    "include_once",
46    "instanceof",
47    "insteadof",
48    "interface",
49    "isset",
50    "list",
51    "match",
52    "namespace",
53    "new",
54    "null",
55    "or",
56    "print",
57    "private",
58    "protected",
59    "public",
60    "readonly",
61    "require",
62    "require_once",
63    "return",
64    "self",
65    "static",
66    "switch",
67    "throw",
68    "trait",
69    "true",
70    "false",
71    "try",
72    "use",
73    "var",
74    "while",
75    "xor",
76    "yield",
77];
78
79pub fn keyword_completions() -> Vec<CompletionItem> {
80    PHP_KEYWORDS
81        .iter()
82        .map(|kw| CompletionItem {
83            label: kw.to_string(),
84            kind: Some(CompletionItemKind::KEYWORD),
85            ..Default::default()
86        })
87        .collect()
88}
89
90const PHP_MAGIC_CONSTANTS: &[(&str, &str)] = &[
91    ("__FILE__", "Absolute path of the current file"),
92    ("__DIR__", "Directory of the current file"),
93    ("__LINE__", "Current line number"),
94    ("__CLASS__", "Current class name"),
95    ("__FUNCTION__", "Current function name"),
96    ("__METHOD__", "Current method name (Class::method)"),
97    ("__NAMESPACE__", "Current namespace"),
98    ("__TRAIT__", "Current trait name"),
99];
100
101pub fn magic_constant_completions() -> Vec<CompletionItem> {
102    PHP_MAGIC_CONSTANTS
103        .iter()
104        .map(|(name, doc)| CompletionItem {
105            label: name.to_string(),
106            kind: Some(CompletionItemKind::CONSTANT),
107            detail: Some(doc.to_string()),
108            ..Default::default()
109        })
110        .collect()
111}