vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Code actions and renaming not working in Neovim

Open maxime-aknin opened this issue 3 years ago • 26 comments

Describe the bug Code actions ("textDocument/codeAction") and renaming ("textDocument/rename") seems not to be working with neovim builtin lsp.

To Reproduce Install neovim 0.5.0, configure with intelephense and try to trigger a code action like implementing methods or try to trigger a rename action. I've tried triggering code actions with plugins like Telescope or lsp saga, also tried to manually triggering a buf_request "textDocument/codeAction" request directly from lua, none of these seems to work.

lsp configuration:

require'lspconfig'.intelephense.setup{
        init_options =  {
            licenceKey = "LICENSE_KEY"
        }
}

Expected behavior Code actions and renaming should be available in neovim.

Screenshots Screen Shot 2021-07-21 at 12 54 09 PM Screen Shot 2021-07-21 at 12 55 50 PM Screen Shot 2021-07-21 at 1 03 37 PM

Platform and version OS: macOs Catalina Intelephense version: 1.7.1.

maxime-aknin avatar Jul 21 '21 11:07 maxime-aknin

I can confirm the same behaviour in emacs, are you able to do anything else premium or just code actions?

elken avatar Jul 24 '21 14:07 elken

@bmewburn is this logic not part of the core intelephense? And is it needed? I don't think the emacs-lsp package calls it, some way to verify premium status would be useful.

https://github.com/bmewburn/vscode-intelephense/blob/master/src/extension.ts#L274

elken avatar Jul 24 '21 16:07 elken

The activation routine is also in the server. I'll look into this.

bmewburn avatar Jul 25 '21 09:07 bmewburn

I have refactoring working in emacs, just lacking code actions oddly.

elken avatar Jul 25 '21 10:07 elken

Weirdly, this morning I have code actions now.

elken avatar Jul 26 '21 09:07 elken

Premium features still not working in neovim

maxime-aknin avatar Jul 26 '21 09:07 maxime-aknin

I'll try and setup nvim for intelephense and see if there's something missing later

elken avatar Jul 26 '21 09:07 elken

I have this working for a long time (see screenshot): Screenshot 2021-07-31 at 21 43 27

Might be a setting or config. I use native lsp + some additional extensions, config is here: https://github.com/haringsrob/neovim-config

haringsrob avatar Jul 31 '21 19:07 haringsrob

Aye I can verify the same behaviour in emacs (phpdoc shows up in the actions list)

image

I think this is indeed a local setup issue and should probably be closed, thanks anyway :)

elken avatar Aug 01 '21 06:08 elken

Thanks @haringsrob . @maxime-aknin are you still having trouble with this?

bmewburn avatar Aug 01 '21 07:08 bmewburn

@bmewburn I've been facing this issue for a while and can't figure out what's happening.

I've tried using both LunarVim and NvChad neovim configs/framework and they don't work in either. They both use Lspinstall to set up the server, but, that only changes the cmd path in the config - the rest stay as is. I have activated my license using vscode to make sure, and it's okay there.

EDIT: I can confirm that LspInstall is not the issue. EDIT2: tried clearing out the intelephense cache in tmp, tried to downgrade to 1.6.1.. still no go. The errors I get in neovim are:

When renaming:

Error executing lua /usr/share/nvim/runtime/lua/vim/lsp/handlers.lau:461: bad argument #2 to 'format' (number expected, got nil).

When executing code_action:

Error executing lua /usr/share/nvim/runtime/lua/vim/lsp.lua:1320: table index is nil.

I did run LSP in debug mode and I log says that textDocument/codeAction is not supported by the attathed server (being intelephense). I have my license in ~/intelephense/license.txt. I tried pasting in the license directly within init_options as well, and using it as an env.

Code actions and rename work for me just fine with the other LSPs that i'm running.

EDIT:

I got the fix:

Emailed Ben. License vs Licence.. US vs UK spelling.....

marwan38 avatar Aug 27 '21 13:08 marwan38

Same thing than @marwan38

syrm avatar Sep 04 '21 20:09 syrm

@syrm Check out the edit at the bottom of that comment. It was a sillllly mistake that cost me many hours.

marwan38 avatar Sep 06 '21 02:09 marwan38

Oh yeah good spot, @maxime-aknin licenceKey = "LICENSE_KEY" should be licenseKey = "LICENSE_KEY". Seems like user error rather than a genuine issue.

elken avatar Sep 06 '21 06:09 elken

fixed for me too thank you

syrm avatar Sep 06 '21 11:09 syrm

Hi there! Happy to open a new issue if you'd rather close this one out (just let me know), but I'm bumping into the same issue here where things like codeAction and rename aren't being supported by the Intelephense server. I read through the comments so far and double-checked that I wasn't falling victim to any of the things that have been discussed so far, but even after changing my spelling of licenseKey, I'm still not able to run code actions or rename classes, variables, etc.

I've tried using both Telescope and LspSaga to run these commands, and they fail using both methods. My premium license key is definitely making into my configuration (which I've pasted down below), because I can do things like "Go To Declaration".

Here's the information that I have:

Neovim Editor LSP Errors (Telescope):

LSP: server does not support code_action

Neovim LSP Log Errors (LspSaga):

[WARN][2021-10-14 20:15:24] .../lua/vim/lsp.lua:87	"method textDocument/codeAction is not supported by any of the servers registered for the current buffer"
[WARN][2021-10-14 20:15:46] .../lua/vim/lsp.lua:87	"method textDocument/rename is not supported by any of the servers registered for the current buffer"

Intelephense Version: 1.7.1

Neovim Version: v0.5.1

Configuration – LSP Capabilities

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.resolveSupport = {
  properties = {
    'documentation',
    'detail',
    'additionalTextEdits',
   }
}

Configuration – Intelephense Config

lspconfig.intelephense.setup{
  capabilities = capabilities, -- from the local capabilities variable in the above snippet
  init_options = {
    licenseKey = os.getenv('INTELEPHENSE_LICENSE_KEY'), -- this is tested and working as intended
  },
  settings = {
    intelephense = {
      telemetry = {
        enabled = false,
      },
      completion = {
        fullyQualifyGlobalConstantsAndFunctions = false
      },
      phpdoc = {
        returnVoid = false,
      }
    },
  }
}

Admittedly, I only have a passing knowledge of Lua (most of this configuration came from more knowledgable Lua folks in this Issue) and even less knowledge of writing language parsers, but I'm happy to help where I can–Intelephense has been indispensable for me when I use VSCode.

Let me know if you need any more information from me–if you can point out what you want, I can definitely get it for you.

alexandersix avatar Oct 15 '21 00:10 alexandersix

Same issue. I've spent hours debugging. No luck!

Ok, found my issue. I'm using https://github.com/ray-x/navigator.lua and I use it to disable formatting for the intelephense language server. Later in the file, I try to setup the language server again with the init options.

So, basically, I was unknowingly calling setup twice.

:heart:

thomas-humi avatar Nov 02 '21 13:11 thomas-humi

@alexandersix Hi. I solved this issue for myself by updating the config key as follows: init_options = { licenceKey = "my key" } notice the spelling of the word licence it is very confusing, cause from reading this thread I see that for other people it was the other way around, as in updating from licence to license fixed their issue. I have no idea why.

axkirillov avatar Jun 08 '22 11:06 axkirillov

Hi, check this. https://intelephense.com/faq.html

Currently, setting the license key in initializationOptions is deprecated. https://github.com/bmewburn/vscode-intelephense/blob/master/package.json#L626

It is better to place licence.txt files.

yaegassy avatar Jun 08 '22 12:06 yaegassy

@haringsrob could you please share your config again? Your mentioned link does not work any more...

And does anybody know how you can rename a function name workspace (project) wide? :lua vim.lsp.buf.rename() does not do that.

feekApp avatar Aug 05 '22 18:08 feekApp

And does anybody know how you can rename a function name workspace (project) wide? :lua vim.lsp.buf.rename() does not do that.

It actually does, but all buffers need to be written (:wa).

Fadarrizz avatar Jan 11 '23 14:01 Fadarrizz

Thnx @Fadarrizz for sharing! I did not realise that all the files containing the renamed functions are placed in a new buffer. I was supposing that the renaming was done directly in the files (outside Vim). :wa indeed does the trick!

feekApp avatar Jan 12 '23 06:01 feekApp

Hi, @elken. How was you able to make it work in Emacs? I've a license key at ~/intelephense/licence.txt already. I'm also trying (setq lsp-intelephense-licence-key "LICENSE-KEY"), but no lucky. Ps.: the same key works in VSCode.

EDIT (w/ solution) It was my Netskope client blocking the intelephense.com/activate url, after disabling it, the Intelphense premium features could be enabled.

leocavalcante avatar Apr 20 '23 18:04 leocavalcante

just in case... Make sure you check the spelling on your licence key file!

It MUST be licence.txt

Mine was named license.txt with a freaking S! 🤦

lpanebr avatar Jan 06 '24 21:01 lpanebr

Any news on code actions not working? I can get PHPActor code actions to work, but don't want to run both Intelephense and PHPActor. Then I get duplicate linting messages (PHPStan) and completions. Would rather have code actions from Intelephense only.

When I run vim.lsp.buf.code_action() without PHPActor enabled I get message: No code actions available With PHPActor enabled I get actual code actions.

I can provide my lspconfig if needed, but it's pretty basic.

knubbbe avatar Mar 27 '24 10:03 knubbbe