How do I get code actions to do something useful?

I was using coc-intelephense plugin with an unlicensed copy of intelephense but was able to get some simple code actions working. See GitHub - yaegassy/coc-intelephense: coc.nvim extension for intelephense (PHP language server)

I recently switched to coq over coc. Kept getting errors that intelephense did not support code actions: “method textDocument/codeAction is not supported by any of the servers registered for the current buffer”. So I then discovered that they are available with licensed copy. So I got the licensed copy. Now I get a message that “No code actions are available.”

According to intelphense doc, they are supposed to show up when I see a little light bulb which I do see.

I have following line in lspconfig:

vim.api.nvim_buf_set_keymap(bufnr, ‘n’, ‘<space>ca’, ‘<cmd>lua vim.lsp.buf.code_action()<CR>’, opts)

So I’m deeply confused. How was I able to get code actions working with coc with unlicensed copy of intelphense but get no code action suggestions with licensed copy? Do I have to add code actions manually? If so, I see no clear documentation for doing that.

I also tried the code here: Code Actions - neovim/nvim-lspconfig Wiki

That didn’t help.

I was able to see code action for adding documentation. So they definitely work. I just don’t see the same code actions I had with coc. For example, I could quickly add in some code to ignore a diagnostic warning. I don’t have that with coq.

OK, so went back and read documentation at feat: add ignore error feature for PHPDoc tag comment by yaegassy · Pull Request #16 · yaegassy/coc-intelephense · GitHub for code actions implemented by coc.

Those actions are not implemented by intelephense at all but by the plugin.

So next question is, can I get this feature back with coq?

Something I do not understand: You can use Intelephense as LSP server, right? Then why the detour with coc-intelephense? With the Neovim LSP interface it should be possible to connect intelephense directly. You could also ask the support if there is already experience with the connection to Neovim.

I had Neovim LSP set up with intelephense without coc-intelephense. It does work. But coc-intelephense has some extra goodies like actions. I think it also allows you to add in the json configuration variables that begin with ‘intelephense.’. But I’m not sure on that.

I had read on their homepage that you only get the full functionality if you buy a license for €15. This means that the limited functionality comes from coc-intelephense.

This is a mild source of confusion amongst users.

Coc-intelephense is adding entirely client-side code to perform a “code action”, the code action is both injected and executed client side. Basically the only point of this code action is to add a unified interface in the picker with the other code actions coming from the server.

It would be extremely trivial to write something equivalent with buf_get_text and buf_set_text. We do allow registering custom commands for code actions, that is, bits of lua code that are executed when a server returns a code action, but we do not have a system for adding arbitrary lua functions as additional entries in the code action window.

I personally have been opposed to allowing arbitrary neovim generated entries in the code action handler, it would not be difficult to artificially write your own buf request/handler (basically copy the code action out of buf.lua, add an entry for both responses that adds the line with buf_get_text, buf_set_text, but I would question why this needs to even be in the code action menu at that point, and not mapped to a dedicated key which is mapped in on_attach from lspconfig.