An open API service indexing awesome lists of open source software.

https://github.com/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://github.com/yaegassy/coc-intelephense

artisan coc coc-extensions coc-nvim composer intelephense laravel lsp neovim pest php phpunit vim

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# coc-intelephense

> fork from a [bmewburn/vscode-intelephense](https://github.com/bmewburn/vscode-intelephense) | [PHP Intelephense](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client) and more feature.

[intelephense](https://intelephense.com/) (PHP language server) extension for [coc.nvim](https://github.com/neoclide/coc.nvim). intelephense's various LSP features and this extension's additional features are available.

## Install

**CocInstall**:

```vim
:CocInstall @yaegassy/coc-intelephense
```

> scoped packages

**vim-plug**:

```vim
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.

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

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

```jsonc
{
// ...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](https://facebook.github.io/watchman/) in order to utilize this feature.

- See:

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.

- `:CocRestart`

## 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**:

```vim
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**:

- `intelephense.enable`: Enable coc-intelephense extension, default `true`
- `intelephense.path`: Path to intelephense module. `~` and `$HOME`, etc. can also be used. If there is no setting, the built-in module will be used. e.g. `/path/to/node_modules/intelephense`. default: `""`
- `intelephense.client.diagnosticsIgnoreErrorFeature`: Whether to enable the PHPDoc tag (`// @intelephense-ignore-line`, `/** @intelephense-ignore-next-line */`) feature and ignore errors, default: `false` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/16)
- This feature is a proprietary implementation of `coc-intelephense`. This feature will be removed when the dedicated feature is added in the upstream's `vscode-intelephense` or `intelephense` language server.
- I made it an ignore comment like `phpstan`, Please refer to this page for usage.
- `intelephense.client.autoCloseDocCommentDoSuggest`: When `/**` is entered, `*/` is automatically inserted (`/**| */`). Then, automatically display the completion menu of PHPDoc comments, default: `true` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/24#issuecomment-1088219510)
- `intelephense.client.disableScaffoldCompletion`: Disable scaffold completion (client). Typing `class_scaffold`, `interface_scaffold`, `trait_scaffold`, `enum_scaffold` or `test_scaffold` will output completion suggestions. This completion feature will only work on the first line of the file, default: `false` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/36#issue-1254138261)
- `intelephense.client.disableSnippetsCompletion`: Disable snippets completion only (client), default: `false`
- Snippet data used for snippet completion can be found in [data/snippets/extended/php.code-snippets](/data/snippets/extended/php.code-snippets).
- `intelephense.client.snippetsCompletionExclude`: Exclude specific prefix in snippet completion, e.g. `["class", "fun"]`, default: `[]`
- `intelephense.client.disableCodeLens`: Disable code lens only (client), default: `false`
- `intelephense.client.codelensProvider`: Provider for CodeLens. Possible options include `phpunit` and `pest`, default: `"phpunit"`
- `intelephense.client.disableAddIskeyword`: Disable the feature of the extension to add `iskeyword`, default: `false`
- `intelephense.server.disableCompletion`: Disable completion only (server), default: `false`
- `intelephense.server.disableDefinition`: Disable definition only (server), default: `false`
- `intelephense.composer.path`: Path to composer command. default: `composer`
- `intelephense.composer.runCommandList`: Set the subcommand of the composer you want to execute, default: `["dump-autoload", "clear-cache", "install", "update"]`
- `intelephense.composer.runCommandPlusList`: Set the subcommand of the composer you want to execute. Additional strings can be entered and executed in the subcommand. default: `["require", "require --dev", "remove", "remove --dev", "update"]`
- `intelephense.composer.enableSplitRight`: Use vertical belowright for composer terminal window, default: `false`
- `intelephense.artisan.withoutArgumentsCommandList`: List of commands to quickly execute `intelephense.artisan.runCommand` or `intelephense.sailArtisan.runCommand` without prompting for arguments or options, e.g. `["route:list", "clear-compiled"]`, default: `[]`
- `intelephense.artisan.enableSplitRight`: Use vertical belowright for artisan terminal window, default: `false`
- `intelephense.symfony.withoutArgumentsCommandList`: List of commands to quickly execute `intelephense.symfony.runCommand` without prompting for arguments or options, default: `[]`
- `intelephense.symfony.enableSplitRight`: Use vertical belowright for symfony terminal window, default: `false`
- `intelephense.phpunit.path`: Path to phpunit command. If there is no setting, the vendor/bin/phpunit will be used, default: `""`
- `intelephense.phpunit.colors`: Use colors in output (--colors), default: `false`
- `intelephense.phpunit.debug`: Display debugging information (--debug), default: `false`
- `intelephense.phpunit.useSail`: To run `sail phpunit` instead of `phpunit`, default: `false`
- `intelephense.phpunit.codeLensTitle`: CodeLens title. Can be changed to any display, default: `">> [Run PHPUnit]"`
- `intelephense.phpunit.enableSplitRight`: Use vertical belowright for phpunit terminal window, default: `false`
- `intelephense.pest.path`: Path to Pest command. If there is no setting, the vendor/bin/pest will be used, default: `""`
- `intelephense.pest.doNotCacheResult`: Do not write test results to cache file (--do-not-cache-result), default: `true`
- `intelephense.pest.useSail`: To run `sail pest` instead of `pest`, default: `false`
- `intelephense.pest.codeLensTitle`: CodeLens title. Can be changed to any display, default: `">> [Run Pest]"`
- `intelephense.pest.enableSplitRight`: Use vertical belowright for pest terminal window, default: `false`
- `intelephense.progress.enable`: Enable progress window for indexing, If false, display with echo messages, default: `true` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/2)

**Same configuration as vscode-intelephense**:

- `intelephense.compatibility.correctForBaseClassStaticUnionTypes`: Resolves 'BaseClass|static' union types to 'static' instead of 'BaseClass', default: `true`
- `intelephense.compatibility.correctForArrayAccessArrayAndTraversableArrayUnionTypes`: Resolves 'ArrayAccess' and 'Traversable' implementations that are unioned with a typed array to generic syntax. eg 'ArrayAccessOrTraversable|ElementType[]' => 'ArrayAccessOrTraversable', default: `true`
- `intelephense.compatibility.preferPsalmPhpstanPrefixedAnnotations`: Prefer `@psalm-` and `@phpstan-` prefixed `@return`, `@var`, `@param` tags when determining symbol types, default: `false`
- `intelephense.files.maxSize`: Maximum file size in bytes, default: `5000000`
- `intelephense.files.associations`: Configure glob patterns to make files available for language server features. Inherits from files.associations, default: `["*.php", "*.phtml"]`
- `intelephense.files.exclude`: Configure glob patterns to exclude certain files and folders from all language server features. Inherits from files.exclude, default: `["**/.git/**", "**/.svn/**", "**/.hg/**", "**/CVS/**", "**/.DS_Store/**", "**/node_modules/**", "**/bower_components/**", "**/vendor/**/{Tests,tests}/**", "**/.history/**", "**/vendor/**/vendor/**"]`
- `intelephense.stubs`: Configure stub files for built in symbols and common extensions. The default setting includes PHP core and all bundled extensions, default: Omitted due to the large number of settings..., See configuration in package.json
- `intelephense.completion.insertUseDeclaration`: Use declarations will be automatically inserted for namespaced classes, traits, interfaces, functions, and constants, default: `true`
- `intelephense.completion.fullyQualifyGlobalConstantsAndFunctions`: Global namespace constants and functions will be fully qualified (prefixed with a backslash), default: `false`
- `intelephense.completion.triggerParameterHints`: Method and function completions will include parentheses and trigger parameter hints, default: `true`
- `intelephense.completion.maxItems`: The maximum number of completion items returned per request, default: `100`
- `intelephense.completion.suggestObjectOperatorStaticMethods`: PHP permits the calling of static methods using the object operator eg `$obj->myStaticMethod();`. If you would prefer not to have static methods suggested in this context then set this value to `false`, default: `true`
- `intelephense.completion.parameterCase`: The preferred font case to use when suggesting parameter names. valid option `"camel", "snake"`, default: `camel`
- `intelephense.completion.propertyCase`: The preferred font case to use when suggesting property names Defaults to snake case, valid option `"camel", "snake"`, default: `snake`
- `intelephense.completion.suggestRelativeToPartialUseDeclaration`: Inserted text will be relative to any existing partial use declarations that may match the symbol. The value is the maximum number of namespace segments that may appear in the inserted text. Defaults to 0 (disabled), default: `0`
- `intelephense.completion.sortText`: Controls whether suggestions will include a `sortText` property that may influence sort order, valid option `"none", "multi-factor"`, default: `multi-factor`
- `intelephense.completion.withOverrideAttribute`: Method completions will include an `#[Override]` attribute where appropriate if targeting PHP 8.3+, default: `true`
- `intelephense.completion.withMethodBody`: Method completions will include either a `parent` call or a `throw new Exception('Not implemented')` in the method body, default: `false`
- `intelephense.format.enable`: Enables formatting, default: `true`
- `intelephense.format.braces`: Controls formatting style of braces, valid option `"per", "allman", "k&r"`, default: `per`
- `intelephense.environment.documentRoot`: The directory of the entry point to the application (directory of index.php). Can be absolute or relative to the workspace folder. Used for resolving script inclusion and path suggestions, default: `null`
- `intelephense.environment.includePaths`: include paths (as individual path items) as defined in the include_path ini setting or paths to external libraries. Can be absolute or relative to the workspace folder. Used for resolving script inclusion and/or adding external symbols to folder, default: `null`
- `intelephense.environment.phpVersion`: A semver compatible string that represents the target PHP version. Used for providing version appropriate suggestions and diagnostics. PHP 5.3.0 and greater supported, default: `"8.4.0"`
- `intelephense.environment.shortOpenTag`: When enabled `` will be parsed as a PHP open tag. Defaults to true, default: `true`
- `intelephense.diagnostics.enable`: Enables diagnostics, default: `true`
- `intelephense.diagnostics.run`: Controls when diagnostics are run, valid option `"onType", "onSave"`, default: `"onType"`
- `intelephense.diagnostics.embeddedLanguages`: Enables diagnostics in embedded languages, default: `true`
- `intelephense.diagnostics.undefinedSymbols`: DEPRECATED. Use the setting for each symbol category, default: `true`
- `intelephense.diagnostics.undefinedVariables`: Enables undefined variable diagnostics, default: `true`
- `intelephense.diagnostics.undefinedTypes`: Enables undefined class, interface and trait diagnostics, default: `true`
- `intelephense.diagnostics.undefinedFunctions`: Enables undefined function diagnostics, default: `true`
- `intelephense.diagnostics.undefinedConstants`: Enables undefined constant diagnostics, default: `true`
- `intelephense.diagnostics.undefinedClassConstants`: Enables undefined class constant diagnostics, default: `true`
- `intelephense.diagnostics.undefinedMethods`: Enables undefined method diagnostics, default: `true`
- `intelephense.diagnostics.undefinedProperties`: Enables undefined property diagnostics, default: `true`
- `intelephense.diagnostics.unusedSymbols`: Enables unused variable, private member, and import diagnostics, default: `true`
- `intelephense.diagnostics.unexpectedTokens`: Enables unexpected token diagnostics, default: `true`
- `intelephense.diagnostics.duplicateSymbols`: Enables duplicate symbol diagnostics, default: `true`
- `intelephense.diagnostics.argumentCount`: Enables argument count diagnostics, default: `true`
- `intelephense.diagnostics.typeErrors`: Enables diagnostics on type compatibility of arguments, property assignments, and return statements where types have been declared, default: `true`
- `intelephense.diagnostics.deprecated`: Enables deprecated diagnostics, default: `true`
- `intelephense.diagnostics.languageConstraints`: Enables reporting of various language constraint errors, default: `true`
- `intelephense.diagnostics.implementationErrors`: Enables reporting of problems associated with method and class implementations. For example, unimplemented methods or method signature incompatibilities, default: `true`
- `intelephense.diagnostics.relaxedTypeCheck`: This setting makes type checking less thorough by allowing contravariant (wider) types to also satisfy a type constraint. This is useful for projects that may have incomplete or innacurate typings. Set to `false` for more thorough type checks. When this setting is `true`, the `noMixedTypeCheck` setting is ignored, default: `true`
- `intelephense.diagnostics.noMixedTypeCheck`: This setting turns off type checking for the `mixed` type. This is useful for projects that may have incomplete or innacurate typings. Set to `false` to make type checking more thorough by not allowing `mixed` to satisy any type constraint. This setting has no effect when `relaxedTypeCheck` is `true`, default: `true`
- `intelephense.diagnostics.memberAccess`: Enables reporting of errors associated with type member access, default: `true`
- `intelephense.diagnostics.unreachableCode`: Enables reporting of unreachable code, default: `true`
- `intelephense.diagnostics.suspectCode`: Enables reporting of irregularities in code that may be indicative of a bug. For example, assignments in a conditional expression or duplicate array keys, default: `true`
- `intelephense.diagnostics.strictTypes`: When enabled, type checks will be performed as if a `declare(strict_types=1)` directive is present in all files, default: `false`
- `intelephense.diagnostics.suppressUndefinedMembersWhenMagicMethodDeclared`: Suppresses undefined property and method errors when `__get` or `__call` magic methods are declared, default: `true`
- `intelephense.diagnostics.severity`: Sets the severity level for each diagnostic code.
- `intelephense.diagnostics.exclude`: A map of globs to diagnostic codes to be excluded for the matching files. Use `*` as a value in the array to exclude all diagnostics. By default the vendor directory is excluded. You can override this by setting `**/vendor/**` to an empty array.
- `intelephense.runtime`: Path to a Node.js executable. Use this if you wish to use a different version of Node.js, default: `null`
- `intelephense.maxMemory`: Maximum memory (in MB) that the server should use. On some systems this may only have effect when runtime has been set. Minimum 256, default: `null`
- `intelephense.licenceKey`: DEPRECATED. Don't use this, default: `""`
- `intelephense.telemetry.enabled`: When set to `true`, anonymous usage and crash data will be sent to Azure Application Insights. Defaults to `false`, default: `false`
- `intelephense.rename.exclude`: Glob patterns to exclude files and folders from having symbols renamed. Rename operation will fail if references and/or definitions are found in excluded files/folders, default: `["**/vendor/**"]`
- `intelephense.rename.namespaceMode`: Controls the scope of a namespace rename operation, valid option `"single", "all"`, default: `"single"`
- `intelephense.references.exclude`: Glob patterns matching files and folders that should be excluded from references search, default: `["**/vendor/**"]`
- `intelephense.phpdoc.returnVoid`: Adds `@return void` to auto generated phpdoc for definitions that do not return a value, default: `true`
- `intelephense.phpdoc.textFormat`: Auto generated phpdoc is returned in {snippet, plain text}, valid option `"snippet", "text"`, default: `"snippet"`
- `intelephense.phpdoc.classTemplate`: An object that describes the format of generated class/interface/trait phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE, default: See configuration in package.json
- `intelephense.phpdoc.propertyTemplate`: An object that describes the format of generated property phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE, default: See configuration in package.json
- `intelephense.phpdoc.functionTemplate`: An object that describes the format of generated function/method phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE, default: See configuration in package.json
- `intelephense.phpdoc.useFullyQualifiedNames`: Fully qualified names will be used for types when true. When false short type names will be used and imported where appropriate. Overrides intelephense.completion.insertUseDeclaration, default: `true`
- `intelephense.codeLens.references.enable`: Enable a code lens that shows a reference count and command to peek locations, default: `false`.
- `intelephense.codeLens.implementations.enable`: Enable a code lens that shows an abstract and interface implementations count and command to peek locations, default: `false`
- `intelephense.codeLens.usages.enable`: Enable a code lens that shows a trait usages count and command to peek locations, default: `false`
- `intelephense.codeLens.overrides.enable`: Enable a code lens that shows method override count and command to peek locations, default: `false`
- `intelephense.codeLens.parent.enable`: Enable a code lens that indicates if a method has a parent implementation and command to peek location, default: `false`
- `intelephense.shortOpenEchoAutoClose`: Will auto-close short open echo tags (`=`). VSCode only, default: `true`
- `intelephense.inlayHint.returnTypes`: Will show an inlay hint for call declaration return type if not already declared, default: `true`
- `intelephense.inlayHint.parameterTypes`: Will show inlay hints for anonymous function declaration parameter types if not already declared, default: `true`
- `intelephense.inlayHint.parameterNames`: Will show inlay hints for call argument parameter names if named arguments are not already in use, default: `true`
- `intelephense.trace.server`: Traces the communication between VSCode and the intelephense language server, valid option `"off", "messages", "verbose"`, default: `"off"`

## Commands

**Command List**:

> :CocCommand [CommandName]
>
> **e.g.** :CocCommand intelephense.phpunit.projectTest

- `intelephense.index.workspace`: Index workspace
- `intelephense.cancel.indexing`: Cancel indexing
- `intelephense.composer.runCommand`: Run selected composer command
- [DEMO](https://github.com/yaegassy/coc-intelephense/pull/23#issuecomment-1085413528)
- `intelephense.composer.runCommandPlus`: Enter and run additional strings to the selected composer commands
- [DEMO](https://github.com/yaegassy/coc-intelephense/pull/23#issuecomment-1085413960)
- `intelephense.composer.runScriptsCommand`: Run selected composer script
- Select and run the script defined in the "scripts section" of `composer.json`. The `pre-...` and `post-...` event scripts are excluded from the list.
- [DEMO](https://github.com/yaegassy/coc-intelephense/pull/23#issuecomment-1085414532)
- `intelephense.artisan.runCommand`: Run Artisan command | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/25)
- `intelephense.sailArtisan.runCommand`: Run Sail Artisan command
- `intelephense.symfony.runCommand`: Run Symfony command
- `intelephense.phpunit.projectTest`: Run PHPUnit for current project
- `intelephense.phpunit.fileTest`: Run PHPUnit for current file
- `intelephense.phpunit.singleTest`: Run PHPUnit for single (nearest) test
- `intelephense.pest.projectTest`: Run Pest for current project
- `intelephense.pest.fileTest`: Run Pest for current file
- `intelephense.pest.singleTest`: Run Pest for single (nearest) test
- `intelephense.fixClassName`: Fix class name based on file name | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/34#issue-1253763775)
- `intelephense.fixNamespace`: Fix namespace based on the composer configuration | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/35#issue-1253784395)
- `intelephense.completeConstructor`: Complete the assignments and add properties for an incomplete constructor | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/38#issue-1259696099)

**Example of Vim command and key mapping**:

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

```vim
" Quickly view a list of all coc.nvim commands
nnoremap :CocCommand

" 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 te :call CocAction('runCommand', 'intelephense.phpunit.singleTest')
```

## CodeLens

**Feature**:

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

- [PHPUnit DEMO](https://github.com/yaegassy/coc-intelephense/pull/20)
- [Pest DEMO](https://github.com/yaegassy/coc-intelephense/pull/26#issuecomment-1099097009)

**coc-settings.json**:

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

Change the setting to `true` to enable it.

```jsonc
{
"codeLens.enable": true
}
```

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

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

**Example key mapping (CodeLens related)**:

```vim
nmap gl (coc-codelens-action)
```

## Code Actions

**Example key mapping (Code Action related)**:

```vim
nmap ga (coc-codeaction-line)
xmap ga (coc-codeaction-selected)
nmap a (coc-codeaction-cursor)
nmap gA (coc-codeaction)
```

**Code Actions (Client side)**:

- `Open 'php.net' for 'xxxx'` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/6)
- `Add @intelephense-ignore-line` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/16)
- `Add @intelephense-ignore-next-line` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/16)
- `Insert PHP Getter` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/33#issuecomment-1140683583)
- `Insert PHP Setter` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/33#issuecomment-1140684502)
- `Insert PHP Getter & Setter` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/33#issuecomment-1140685034)
- `Change Visibility` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/37#issue-1259334586)
- `Remove all unused imports for "use" statetment` | [DEMO](https://github.com/yaegassy/coc-intelephense/pull/43#issue-1285689962)

**Code Actions (Server side)**:

- `use NAMESPACE\...\CLASS`
- `Implement all abstract methods for '...'`
- `Add PHPDoc for '...'`
- and more...
- Other code actions provided by the intelephehse language server

## Thanks

- [bmewburn/vscode-intelephense](https://github.com/bmewburn/vscode-intelephense)
- [glayzzle/php-parser](https://github.com/glayzzle/php-parser)

## License

MIT

----

> This extension is built with [create-coc-extension](https://github.com/fannheyward/create-coc-extension)