-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for array and object shapes #249
Comments
btw, I think it would be really helpful to initially just parse and show it properly when hovering or typing the function out with the little intellisense above for the params. Support for doing $options['required'] and having intelephense know that it should be a bool is great, but I think probably also harder and not as important as just seeing the definition initially. |
Alternate syntax that Psalm static checker uses: |
This would be useful. I agree the Psalm syntax is nicer but the fig standard might have more clout. Either way this will require a proper phpdoc parser. Currently it is very simple and just uses regex to pick out the text and tags. |
Hi. @bmewburn, if you did not decide on format yet, would you mind taking a look on the format deep-assoc-completion plugin uses in phpstorm? Do you accept pull requests? I could write the phpdoc parser and add support for such format in your extension if you would like that ;-). Upd.: I somewhat ported |
@klesun, sorry for the late reply and thank you for your offer. For now I'd rather wait until some common standard emerges. |
oh, ok (though I guess it will take quite some time...) |
@bmewburn, there is no common standard for PHP; however, there is a common standard for JSDoc that works well for majority of usecases - see @typedef tag (http://usejsdoc.org/tags-typedef.html). An example of a definition using jsdoc syntax /**
/**
$person_array = array ( |
The phpdoc proposed PSR no longer shows the format initially showed by @hworld. Pslam has become quite popular now and it's format is pretty nice, so my vote goes to that 🙂. I believe even phpstan is going to add / has added support for similar format. |
Seems like psalm format is only sensible despite not being in PSR. JSDoc uses similar or the same format. https://psalm.dev/docs/annotating_code/type_syntax/array_types/#object-like-arrays |
Any updates on this? Thanks! |
I would appreciate this feature as well. |
I've begun to use PHPStan which supports the same syntax, and at the moment some declarations cause problems because Should I raise as a separate issue the faulty parsing? I would prefer Intelliphense to ignore something it doesn't understand 👍 |
This format is currently supported at least by psalm, phan and phpstan. https://psalm.dev/docs/annotating_code/type_syntax/array_types/#object-like-arrays PhpStorm supports ArrayShape: https://blog.jetbrains.com/phpstorm/2020/12/phpstorm-2020-3-release/#arrayshape and probably will support this syntax: https://youtrack.jetbrains.com/issue/WI-56038 @bmewburn Even If you're not planning to add feature this syntax should be at least ignored. <?php
namespace Foo;
/** @var array<int, array{0:string}> */
$bar = [];
$x = $bar[0]; // @var \Foo\array{0:string} $x @driskell can you provide minimal example to reproduce problem with loops? |
And looks like Thus PHPDoc version will be probably the only one supported everywhere. |
@driskell And I totally forgot about that, but PHPStan also supports own annotations like: https://phpstan.org/writing-php-code/phpdocs-basics#prefixed-tags |
Now array shapes are supported by PHPStorm: https://blog.jetbrains.com/phpstorm/2021/07/phpstorm-2021-2-release/#array_shapes_phpdoc_syntax_support /**
* @return array{foo: int, bar: string, typedObject: \Any\Type}
*/
/**
* @return array{ids: array, search_results: array}[]
*/ |
Any updates on this? Thanks! |
|
|
the deep-assoc-completion-vscode plugin is no longer working (( |
@theprometeus thanks for bringing that up, I released one more patch: The plugin is far from perfect, but I hope it still can be helpful. |
|
@theprometeus I think you can't contribute with the dev since Intelephense language server is proprietary! https://github.com/bmewburn/vscode-intelephense/#licence You really can do nothing with open source client :p |
I have a license of vscode-intelephense but this is not working even in that premium version. Any updates on this? |
Another license holder, any updates on this? |
Version 1.10 looks like it could be a good one! |
Looks like this won't get implemented :( |
@isaac-souza what makes you say that? |
@kczx3 the original issue is from 2017, from the latest comments looks like it still didn't get implemented. Please let me know if I'm wrong. It would help me tremendous if it was available. |
@bmewburn as long as it's completed, any documentation how to use this feature? |
The changelog has an example. |
+1 |
As shown here in the proposal for phpdoc fig standard: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#examples-12
Basically looks like this
Would be really cool since PHP tends to use these option arrays all over the place in libraries!
The text was updated successfully, but these errors were encountered: