bmewburn/vscode-intelephense

Mediawiki stubs

Opened this issue · 3 comments

I have made an attempt at generating Mediawiki stubs using nikic/php-parser: https://github.com/JohnRDOrazio/mediawiki-stubs

However I'm not very familiar with these tools and I'm not sure if the result is useable with intelephense. The resulting stubs file is over 9MB (perhaps there are ways to optimize and reduce the size?).

I have tried placing the stubs file in the root folder of my VSCode project, I have also tried adding the stubs file to a mediawiki stubs folder in the extension's node_modules, and adding mediawiki to the package.json list of intelephense stubs, then enabling mediawiki in the extension settings for stubs. However I'm still getting red underlines on all Mediawiki classes and methods, so I'm not sure what I'm not doing correctly.

In any case, if anyone more experienced is willing to generate Mediawiki stubs and include them in the intelephense extension, this would be greatly appreciated.

Do you have intelephense.files.maxSize set to a value greater than 9000000 ? If not, they would not be indexed because of the file size.

I have now fixed the stubs generation, there were some errors due to some comments containing strings such as $1 and $2 and \\1, and when I called preg_replace on the pretty printed node with capture groups it was seeing those strings as capture group substitutions. So I had to make sure any similar character sequences were correctly escaped before doing any preg_replace operations.

I also grouped classes by namespace, and split the globals from the rest of the stubs just like in the wordpress stubs.

The resulting mediawiki-stubs.php is now down to 6.4MB, I would say much better than the previous 9MB. I copied the updated stub files to a mediawiki folder in the extension's node_modules/intelephense/lib/stub/, and now all is finally working. I no longer get the red underlines, instead I get the popup with the signatures and doc blocks.

Perhaps these stubs could be included in vscode-intelephense?

I have also released the generation script as a composer package : https://packagist.org/packages/johnrdorazio/mediawikistubs .