It will help you to improve your skills or how to understand how to start this journey!
A lot of people got troubles on configuring Intelephense with NeoVim but also for WordPress.
I will show you how to achieve everything you need. Also this is the most read article of my website so for any feedback let me know (the article get updates during the time).
Installation
First of all you need to download Intelephense from NPM.
Now you need to install NeoVim 0.5 or superior with the plugin neovim/nvim-lspconfig
. Without this plugin you are not able to use the feature, as it is embedded, but some APIs are exposed from this plugin.
To install a NeoVim plugin there are various ways so I won’t talk about that but my config files will be available at the end of the post.
Next step is to download some php stubs. As WordPress is not PSR-4 and not all the plugins/themes are compatible with this technology the language server cannot detect a lot of stuff. So stubs were invented to create php files that include the documentation and just the function or method mention but they are empty in this way this tools can parse them like as they were part of the namespace as example.
composer global require php-stubs/wordpress-globals php-stubs/wordpress-stubs php-stubs/woocommerce-stubs php-stubs/acf-pro-stubs wpsyntex/polylang-stubs php-stubs/genesis-stubs php-stubs/wp-cli-stubs
This command will install globally in your machine some stubs that you can remove based on your needs. The funny part is that of wp-cli-stubs and genesis-stubs I am the author ๐

Configure
Now you need Lua as you need to code a bit to specify the settings for NeoVim. A good guide about it it’s there.
This is an extract of my settings (it’s an incomplete example code):
local nvim_lsp = require'lspconfig' nvim_lsp.intelephense.setup({ settings = { intelephense = { stubs = { "bcmath", "bz2", "calendar", "Core", "curl", ... "zip", "zlib", "wordpress", "woocommerce", "acf-pro", "wordpress-globals", "wp-cli", "genesis", "polylang" }, environment = { includePaths = '/home/your-user/.composer/vendor/php-stubs/' -- this line forces the composer path for the stubs in case inteliphense don't find it... }, files = { maxSize = 5000000; }; }; } });
This code is truncated (or it will be too much long) but you can find here the complete one also with the integration with other plugins.
You have integrated a LSP in your neovim for PHP with WordPress integration.
Neovim supports also PHPActor/PHPStan as LSP, so this is on you.
nvim_lsp.phpactor.setup{} nvim_lsp.cssls.setup{} nvim_lsp.html.setup{} nvim_lsp.bashls.setup{}
As example in this way I am initializing without parameters sole LSP but if you look in my repository’s code you can see also other stuff.
Now basically the LSP setup as some events or callback and the most used by some plugin to get executed is the on_attach
.
I am using the ray-x/lsp_signature.nvim
plugin to that event to add a tiny modal with information of the method where the cursor is. In my config you can find also other settings for other plugins like aerial
or trouble
.
Also there is some code in the same file to integrate better with another that is hrsh7th/nvim-compe
. This plugin adds the support to snippets for autocomplete but also to other sources.
My plan in fact is to refactor a Deoplete plugin (another autocomplete plugin that I am not using anymore) that I wrote to add support for the action/filters. I opened a ticket to get help as I am not so skilled in Lua.
I have also the SirVer/ultisnips
(supported by compe) with the plugin of the sniphpets/sniphpets
to get everything I need.
EDIT: I am using COQ now and I did a plugin for this that integrate WordPress autocompletion for hooks. This plugin autocomplete for you add_action('he hook name here'
and is very handy. Also COQ has snippet support so you can do them on your own.
Anyway it is just matter of trying until works and create the best settings with the plugins that fit your needs.
Extra
This is my Kate LSP settings.json
{ "servers": { "php": { "command": "intelephense --stdio" }, "bash": { "command": "bash-language-server start" }, "css": { "command": "vscode-css-language-server --stdio" }, "css": { "command": "vscode-css-language-server --stdio" }, "html": { "command": "vscode-css-language-server --stdio" } } }
My dotfiles also include a way to run Nvim in a way with less plugins that i called WordPress mode that I use when I have to contribute to WP and I require less stuff that can create troubles.
Thanks to the PHP-Stubs project for the stubs and Intelephense also if it is not open source sadly.
Neovim of course ๐