@@ -138,6 +138,29 @@ public function before(NamespaceNode $ctx, iterable $nodes): iterable
138
138
return [];
139
139
}
140
140
141
+ /**
142
+ * Additionally, an autocomplete with a pointer will be generated if the
143
+ * specified type is a structure-like or a typedef for a structure-like.
144
+ *
145
+ * @param non-empty-string $name
146
+ *
147
+ * @psalm-suppress RedundantConditionGivenDocblockType
148
+ */
149
+ private function isStructureLike (NamespaceNode $ ctx , string $ name ): bool
150
+ {
151
+ if (!isset ($ ctx ->types [$ name ])) {
152
+ return false ;
153
+ }
154
+
155
+ $ type = $ ctx ->types [$ name ];
156
+
157
+ if ($ type instanceof RecordTypeNode) {
158
+ return true ;
159
+ }
160
+
161
+ return $ type instanceof TypeDefinitionNode && $ type ->type instanceof RecordTypeNode;
162
+ }
163
+
141
164
public function after (NamespaceNode $ ctx , iterable $ nodes ): iterable
142
165
{
143
166
//
@@ -155,9 +178,12 @@ public function after(NamespaceNode $ctx, iterable $nodes): iterable
155
178
);
156
179
157
180
foreach ($ this ->names as $ name ) {
158
- $ registerArgumentsSet ->args [] = new Arg (new String_ (
159
- value: $ name ,
160
- ));
181
+ $ registerArgumentsSet ->args [] = new Arg (new String_ ($ name ));
182
+
183
+ if ($ this ->isStructureLike ($ ctx , $ name )) {
184
+ $ registerArgumentsSet ->args [] = new Arg (new String_ ($ name . '* ' ));
185
+ $ registerArgumentsSet ->args [] = new Arg (new String_ ($ name . '** ' ));
186
+ }
161
187
}
162
188
163
189
yield new Expression ($ registerArgumentsSet );
@@ -183,6 +209,23 @@ class: new Name\FullyQualified($this->naming->getEntrypoint()),
183
209
]
184
210
));
185
211
212
+ yield new Expression (new FuncCall (
213
+ name: new Name ('expectedArguments ' ),
214
+ args: [
215
+ new Arg (new StaticCall (
216
+ class: new Name \FullyQualified ($ this ->naming ->getEntrypoint ()),
217
+ name: 'cast ' ,
218
+ )),
219
+ new Arg (new LNumber (0 )),
220
+ new Arg (new FuncCall (
221
+ name: new Name ('argumentsSet ' ),
222
+ args: [new Arg (new String_ (
223
+ value: $ this ->argumentSetPrefix . $ this ->globalArgumentSetSuffix
224
+ ))]
225
+ ))
226
+ ]
227
+ ));
228
+
186
229
yield new Expression (new FuncCall (
187
230
name: new Name ('expectedArguments ' ),
188
231
args: [
@@ -206,7 +249,7 @@ class: new Name\FullyQualified($this->naming->getEntrypoint()),
206
249
207
250
$ internalName = \rtrim ($ this ->naming ->getName ('@ ' , new StructTypeNode ('@ ' )), '@ ' ) . '@ ' ;
208
251
209
- $ arrayItems = [new ArrayItem (
252
+ $ map = [new ArrayItem (
210
253
value: new String_ ('\\' . $ internalName ),
211
254
key: new String_ ('' ),
212
255
attributes: ['comments ' => [new Comment ('// structures autocompletion ' )]]
@@ -218,13 +261,38 @@ class: new Name\FullyQualified($this->naming->getEntrypoint()),
218
261
continue ;
219
262
}
220
263
221
- $ arrayItems [] = new ArrayItem (
222
- value: new String_ ('\\' . $ this ->naming ->getName (
223
- name: $ node ->name ,
224
- type: $ node ->type ,
225
- )),
264
+ $ mappedType = $ this ->naming ->getName (
265
+ name: $ node ->name ,
266
+ type: $ node ->type ,
267
+ );
268
+
269
+ $ map [] = new ArrayItem (
270
+ value: new String_ ("\\$ mappedType " ),
226
271
key: new String_ ($ node ->name ),
227
272
);
273
+
274
+ if ($ this ->isStructureLike ($ ctx , $ node ->name )) {
275
+ $ map [] = new ArrayItem (
276
+ value: new String_ ("\\{$ mappedType }[] " ),
277
+ key: new String_ ( $ node ->name . '* ' ),
278
+ );
279
+ $ map [] = new ArrayItem (
280
+ value: new String_ ("\\{$ mappedType }" ),
281
+ key: new String_ ( $ node ->name . '* ' ),
282
+ );
283
+ $ map [] = new ArrayItem (
284
+ value: new String_ ("\\{$ mappedType }[][] " ),
285
+ key: new String_ ( $ node ->name . '** ' ),
286
+ );
287
+ $ map [] = new ArrayItem (
288
+ value: new String_ ("\\{$ mappedType }[] " ),
289
+ key: new String_ ( $ node ->name . '** ' ),
290
+ );
291
+ $ map [] = new ArrayItem (
292
+ value: new String_ ("\\{$ mappedType }" ),
293
+ key: new String_ ( $ node ->name . '** ' ),
294
+ );
295
+ }
228
296
}
229
297
}
230
298
@@ -237,9 +305,10 @@ class: new Name\FullyQualified($this->naming->getEntrypoint()),
237
305
)),
238
306
new Arg (new FuncCall (
239
307
name: new Name ('map ' ),
240
- args: [
241
- new Arg (new Array_ ($ arrayItems , ['kind ' => Array_::KIND_SHORT ]))
242
- ]
308
+ args: [new Arg (new Array_ (
309
+ items: $ map ,
310
+ attributes: ['kind ' => Array_::KIND_SHORT ],
311
+ ))]
243
312
))
244
313
]
245
314
));
0 commit comments