bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.58k stars 93 forks source link

Code actions and renaming not working in Neovim #1888

Open maxime-aknin opened 3 years ago

maxime-aknin commented 3 years ago

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.

elken commented 3 years ago

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

elken commented 3 years ago

@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

bmewburn commented 3 years ago

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

elken commented 3 years ago

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

elken commented 3 years ago

Weirdly, this morning I have code actions now.

maxime-aknin commented 3 years ago

Premium features still not working in neovim

elken commented 3 years ago

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

haringsrob commented 3 years ago

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

elken commented 3 years ago

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 :)

bmewburn commented 3 years ago

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

marwan38 commented 2 years ago

@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.....

syrm commented 2 years ago

Same thing than @marwan38

marwan38 commented 2 years ago

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

elken commented 2 years ago

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

syrm commented 2 years ago

fixed for me too thank you

alexandersix commented 2 years ago

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.

thomas-humi commented 2 years ago

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:

axkirillov commented 2 years ago

@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.

yaegassy commented 2 years ago

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.

feekApp commented 2 years ago

@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.

Fadarrizz commented 1 year ago

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).

feekApp commented 1 year ago

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!

leocavalcante commented 1 year ago

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.

lpanebr commented 7 months ago

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! 🤦

knubbbe commented 4 months ago

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.