yaegassy / coc-intelephense

intelephense (PHP language server) extension for coc.nvim. intelephense’s various LSP features and this extension's additional features are available.
https://www.npmjs.com/package/@yaegassy/coc-intelephense
MIT License
98 stars 4 forks source link
artisan coc coc-extensions coc-nvim composer intelephense laravel lsp neovim pest php phpunit vim

coc-intelephense

fork from a bmewburn/vscode-intelephense | PHP Intelephense and more feature.

intelephense (PHP language server) extension for coc.nvim. intelephense's various LSP features and this extension's additional features are available.

Install

CocInstall:

:CocInstall @yaegassy/coc-intelephense

scoped packages

vim-plug:

Plug 'yaegassy/coc-intelephense', {'do': 'yarn install --frozen-lockfile'}

Enabling the PREMIUM feature

Prepare a licence.txt file containing the licence key and place it in a designated location.

$ node -e "console.log(os.homedir() + '/intelephense/licence.txt')"
/Users/username/intelephense/licence.txt

[DEPRECATED]: Or set intelephense.licenceKey in "coc-settings.json"

{
  // ...snip
  "intelephense.licenceKey": "LICENCEKEYSAMPLE",
  // ...snip
}

For more information, please check this link.

[RECOMMENDED] Additional installation of "watchman"

In the intelephense used by coc-intelephense, it utilizes the workspace/didChangeWatchedFiles notification to watch files within the project.

In coc.nvim, it is recommended to install watchman in order to utilize this feature.

If you have difficulty installing watchman, you can use coc-intelephense without watchman, but you may not be able to immediately use intelephense's IntelliSense with the newly added files.

In this case, please execute the command to restart the language server.

workspaceFolders

Depending on the project like mono repo or how Vim/Neovim is started, workspaceFolders may not be recognized correctly.

To make coc.nvim recognize workspaceFolders correctly, you can set b:coc_root_patterns in .vimrc/init.vim

Example:

  au FileType php let b:coc_root_patterns = ['.git', '.env', 'composer.json', 'artisan']

For more information, check this coc.nvim's wiki.

Configuration options

For additional feature of coc-intelephese:

Same configuration as vscode-intelephense:

Commands

Command List:

:CocCommand [CommandName]

e.g. :CocCommand intelephense.phpunit.projectTest

Example of Vim command and key mapping:

Vim commands can be defined and executed or key mappings can be set and used.

" Quickly view a list of all coc.nvim commands
nnoremap <silent> <C-p> :<C-u>CocCommand<CR>

" Run PHPUnit for current project
command! -nargs=0 PHPUnit :call CocAction('runCommand', 'intelephense.phpunit.projectTest')

" Run PHPUnit for current file
command! -nargs=0 PHPUnitCurrent :call CocAction('runCommand', 'intelephense.phpunit.fileTest', ['%'])

" Run PHPUnit for single (nearest) test
nnoremap <leader>te :call CocAction('runCommand', 'intelephense.phpunit.singleTest')<CR>

CodeLens

Feature:

Test file for "PHPUnit" or "Pest", allowing execution of a single test method. CodeLens appears at the top of the test method.

coc-settings.json:

By default, codeLens.enable is set to false, which disables it.

Change the setting to true to enable it.

{
  "codeLens.enable": true
}

If you want to use "Pest", change the intelephense.client.codelensProvider setting to pest (default: phpunit).

{
  "intelephense.client.codelensProvider": "pest"
}

Example key mapping (CodeLens related):

nmap <silent> gl <Plug>(coc-codelens-action)

Code Actions

Example key mapping (Code Action related):

nmap <silent> ga <Plug>(coc-codeaction-line)
xmap <silent> ga <Plug>(coc-codeaction-selected)
nmap <silent> <leader>a <Plug>(coc-codeaction-cursor)
nmap <silent> gA <Plug>(coc-codeaction)

Code Actions (Client side):

Code Actions (Server side):

Inlay Hints (Client Base)

Thanks

License

MIT


This extension is built with create-coc-extension