marlonfan / coc-phpls

🐭 php language server for coc.nvim
MIT License
212 stars 16 forks source link

Add Use Statement in Normal Mode #68

Closed cxgslegend closed 4 years ago

cxgslegend commented 4 years ago

Sorry if this is obvious, but is there a way to add the use statement for a class in normal mode? Currently, I have to go to the class go into insert mode, delete a few characters, then start adding them back in to trigger the completion window. Then from there, I can pick correct class, and it will add the Use statement at the top.

It would be nice if I could just hover over the class, and use a key mapping to add the use statement. I thought, maybe I could use <Plug>(coc-fix-current), but guess that doesn't do what I thought it did.

Thanks

yaegassy commented 4 years ago

This feature is available on the recently updated intelephense 1.5.1.


Intelephense changelog


It is available in coc-phpls using the CodeAction feature. <Plug>(coc-codeaction)

You will need to purchase an intelephense license and have it set to intelephense.licenceKey.

Demo

use_codeaction

cxgslegend commented 4 years ago

Thank you @yaegassy. Do you know how I get the latest intelephense version? I am pretty sure coc-phpls installed it for me.

Or should I just wait for the project authors to update the project?

cxgslegend commented 4 years ago

I figured out that if I went into the ~/.config/coc/extensions directory and updated npm, I would get the updated version of intelephense. However, I still don't see anything when I try to run the <Plug>(coc-codeaction). I get an error that says I need a function name.

Screen Shot 2020-07-13 at 12 05 53 PM
yaegassy commented 4 years ago

@cxgslegend

I think there may be a misconfiguration of the <Plug>(coc-codeaction) mapping.

Here's an example configuration.

nmap <silent> ga <Plug>(coc-codeaction)

Alternatively, you can directly execute the actual function to be executed by <Plug>(coc-codeaction).

:call CocActionAsync('codeAction','')

I have prepared a DEMO so that you can understand the keyboard input as well, so please refer to it.

I tried DEMO with vim8, but there is a slight difference in the display on nvim, so I'll post a screenshot of nvim as well.

DEMO(vim8)

coc-phpls-vim8-codaction_960

Screenshot(nvim)

coc-phpls-nvim-codaction
yaegassy commented 4 years ago

@cxgslegend How to use the latest intelephense in coc-phpls.

I created this Pull Request. https://github.com/marlonfan/coc-phpls/pull/67

Once this is merged, you will certainly have the latest version of the current intelephense available.

Alternatively, you may be able to use the latest version of intelephense by uninstalling and reinstalling coc-phpls once.

:CocUninstall coc-phpls
:CocInstall coc-phpls
cxgslegend commented 4 years ago

Thank you @yaegassy. I am using vim-which-key for my mappings. So I guess I misconfigured it or something. When I deleted it and tried again, it worked (maybe there was something wrong with the dictionary structure).

This is how it looks now:

let g:which_key_map.l = {
\'name' : '+lsp' ,
\   '.' : [':CocConfig'                          , 'config'],
\   'a' : ['<Plug>(coc-codeaction)'              , 'code action'],
\   'd' : ['<Plug>(coc-definition)'              , 'definition'],
\   'f' : ['<Plug>(coc-format-selected)'         , 'format selected'],
\   'i' : ['<Plug>(coc-implementation)'          , 'implementation'],
\   'm' : [':CocList diagnostics'                , 'diagnostics messages'],
\   'n' : ['<Plug>(coc-diagnostic-next-error)'   , 'next error'],
\   'p' : ['<Plug>(coc-diagnostic-prev-error)'   , 'prev error'],
\   'e' : ['<Plug>(coc-rename)'                  , 'edit name (rename)'],
\   'r' : ['<Plug>(coc-references)'              , 'references'],
\   's' : [':CocList -I symbols'                 , 'search symbols'],
\   't' : ['<Plug>(coc-type-definition)'         , 'type definition'],
\}

Regardless, its working now. Thank you so much. Sorry if this was too trivial. I really appreciated it.

Screen Shot 2020-07-13 at 8 04 09 PM
yaegassy commented 4 years ago

@cxgslegend I'm glad it worked. Happy viming!