Skip to content

Commit 7a6a788

Browse files
committed
Better PHP query
1 parent 4d77644 commit 7a6a788

File tree

2 files changed

+48
-121
lines changed

2 files changed

+48
-121
lines changed

crates/codebook/src/queries/php.scm

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22
(comment) @comment
33

44
; Strings
5-
(string) @string
6-
(encapsed_string) @string
5+
(string_content) @string
76

87
; Names (covers function names, class names, etc.)
9-
(name) @identifier
10-
8+
; (name) @identifier
9+
(class_declaration
10+
name: (name) @identifier)
11+
(const_declaration
12+
(const_element (name) @identifier))
13+
(namespace_definition
14+
(namespace_name (name) @identifier))
15+
(property_element
16+
(variable_name (name) @identifier))
17+
(method_declaration
18+
name: (name) @identifier)
19+
(assignment_expression
20+
left: (variable_name (name) @identifier))
21+
(function_definition
22+
name: (name) @identifier)
23+
(simple_parameter
24+
(variable_name (name) @identifier))
25+
(catch_clause
26+
(variable_name (name) @identifier))
1127
; Variable names - simplified with no nested structure
1228
; (variable_name) @identifier

crates/codebook/tests/test_php.rs

Lines changed: 28 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,11 @@ $userDetails = $userr->getUserDeetails();
7171
),
7272
WordLocation::new(
7373
"Servicce".to_string(),
74-
vec![
75-
TextRange {
76-
start_char: 10,
77-
end_char: 18,
78-
line: 7,
79-
},
80-
TextRange {
81-
start_char: 17,
82-
end_char: 25,
83-
line: 48,
84-
},
85-
],
74+
vec![TextRange {
75+
start_char: 10,
76+
end_char: 18,
77+
line: 7,
78+
}],
8679
),
8780
WordLocation::new(
8881
"ACTIVVE".to_string(),
@@ -105,21 +98,6 @@ $userDetails = $userr->getUserDeetails();
10598
end_char: 40,
10699
line: 16,
107100
},
108-
TextRange {
109-
start_char: 19,
110-
end_char: 22,
111-
line: 17,
112-
},
113-
TextRange {
114-
start_char: 30,
115-
end_char: 33,
116-
line: 17,
117-
},
118-
TextRange {
119-
start_char: 65,
120-
end_char: 68,
121-
line: 23,
122-
},
123101
],
124102
),
125103
WordLocation::new(
@@ -135,32 +113,15 @@ $userDetails = $userr->getUserDeetails();
135113
end_char: 52,
136114
line: 16,
137115
},
138-
TextRange {
139-
start_char: 15,
140-
end_char: 24,
141-
line: 18,
142-
},
143-
TextRange {
144-
start_char: 28,
145-
end_char: 37,
146-
line: 18,
147-
},
148116
],
149117
),
150118
WordLocation::new(
151119
"Deetails".to_string(),
152-
vec![
153-
TextRange {
154-
start_char: 27,
155-
end_char: 35,
156-
line: 22,
157-
},
158-
TextRange {
159-
start_char: 30,
160-
end_char: 38,
161-
line: 49,
162-
},
163-
],
120+
vec![TextRange {
121+
start_char: 27,
122+
end_char: 35,
123+
line: 22,
124+
}],
164125
),
165126
WordLocation::new(
166127
"querry".to_string(),
@@ -188,63 +149,27 @@ $userDetails = $userr->getUserDeetails();
188149
),
189150
WordLocation::new(
190151
"amountt".to_string(),
191-
vec![
192-
TextRange {
193-
start_char: 26,
194-
end_char: 33,
195-
line: 34,
196-
},
197-
TextRange {
198-
start_char: 48,
199-
end_char: 55,
200-
line: 39,
201-
},
202-
],
152+
vec![TextRange {
153+
start_char: 26,
154+
end_char: 33,
155+
line: 34,
156+
}],
203157
),
204158
WordLocation::new(
205159
"symboll".to_string(),
206-
vec![
207-
TextRange {
208-
start_char: 5,
209-
end_char: 12,
210-
line: 35,
211-
},
212-
TextRange {
213-
start_char: 23,
214-
end_char: 30,
215-
line: 39,
216-
},
217-
],
160+
vec![TextRange {
161+
start_char: 5,
162+
end_char: 12,
163+
line: 35,
164+
}],
218165
),
219166
WordLocation::new(
220167
"formattted".to_string(),
221-
vec![
222-
TextRange {
223-
start_char: 9,
224-
end_char: 19,
225-
line: 39,
226-
},
227-
TextRange {
228-
start_char: 12,
229-
end_char: 22,
230-
line: 44,
231-
},
232-
],
233-
),
234-
WordLocation::new(
235-
"Excepton".to_string(),
236-
vec![
237-
TextRange {
238-
start_char: 23,
239-
end_char: 31,
240-
line: 26,
241-
},
242-
TextRange {
243-
start_char: 13,
244-
end_char: 21,
245-
line: 40,
246-
},
247-
],
168+
vec![TextRange {
169+
start_char: 9,
170+
end_char: 19,
171+
line: 39,
172+
}],
248173
),
249174
WordLocation::new(
250175
"errr".to_string(),
@@ -256,30 +181,16 @@ $userDetails = $userr->getUserDeetails();
256181
),
257182
WordLocation::new(
258183
"userr".to_string(),
259-
vec![
260-
TextRange {
261-
start_char: 1,
262-
end_char: 6,
263-
line: 48,
264-
},
265-
TextRange {
266-
start_char: 16,
267-
end_char: 21,
268-
line: 49,
269-
},
270-
],
271-
),
272-
WordLocation::new(
273-
"dbb".to_string(),
274184
vec![TextRange {
275-
start_char: 32,
276-
end_char: 35,
185+
start_char: 1,
186+
end_char: 6,
277187
line: 48,
278188
}],
279189
),
280190
];
281191

282192
let not_expected = [
193+
"Excepton",
283194
"php",
284195
"namespace",
285196
"class",

0 commit comments

Comments
 (0)