Setting up the free version of Intelephense in NeoVim's native LSP is a straightforward affair. However, importing the license key and using it can be a real headache as there is literally no documentation on how to do this. HOping trhis Gist comes in useful for somebody.
First, create a file called license.txt
in $HOME/intelephense/license.txt
and paste in your license key. Save that file.
Next we will want make sure we have intelephense installed on our host
sudo npm i intelephense -g
Now we can setup intelephense in our Nvim config. How you structure your files is up to you. I have a file called lua/lsp.lua
which is required in my init.lua
but do what works for you.
We now need to create a function that reads our license key.
local get_intelephense_license = function ()
local f = assert(io.open(os.getenv("HOME") .. "/intelephense/license.txt", "rb"))
local content = f:read("*a")
f:close()
return string.gsub(content, "%s+", "")
end
Once we have this we can call setup on intelephense like so.
nvim_lsp.intelephense.setup {
capabilities = capabilities,
on_attach = on_attach,
init_options = {
licenceKey = get_intelephense_license()
}
}
You can do whatever setup you like inside the on_attach
function. Here is mine as reference.
local on_attach = function()
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {buffer = 0})
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {buffer = 0})
vim.keymap.set('n', 'gr', vim.lsp.buf.references, {buffer = 0})
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {buffer = 0})
vim.keymap.set('n', '<leader>dj', vim.diagnostic.goto_next, {buffer = 0})
vim.keymap.set('n', '<leader>dk', vim.diagnostic.goto_prev, {buffer = 0})
vim.keymap.set('n', '<leader>df', '<cmd>Telescope diagnostics<cr>', {buffer = 0})
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, {buffer = 0})
vim.keymap.set('n', '<C-h>', vim.lsp.buf.signature_help, {buffer = 0})
end