Intelephense Documentation

repository·master·Indexed 23 days ago

https://github.com/bmewburn/vscode-intelephense

A high-performance PHP language server for Visual Studio Code providing code intelligence, refactoring, and static analysis. Features include code completion, signature help, navigation, and PSR-12 compatible formatting. Offers a freemium model with advanced capabilities such as symbol renaming, type hierarchy, and code lens available via a premium licence.

Tokens
2K
Snippets
7
Records
15
Agent score
84%

What's inside Intelephense

  1. Intelephense Feature Overview

    master

    Intelephense is a high-performance PHP language server for VS Code. It provides a wide range of intelligence features, categorized below:

    Free Features

    • Code Completion (IntelliSense): Fast camel/underscore case completion for documents, workspaces, and built-in symbols with automatic use declarations.
    • Signature Help: Detailed parameter help for constructors, methods, and functions.
    • Navigation: Rapid workspace-wide go to definition, find all references, and workspace symbol search.
    • Symbol Search: Full document symbol search (powers breadcrumbs and outline UI).
    • Diagnostics: Error-tolerant parsing and static analysis for open files.
    • Formatting: Lossless PSR-12 compatible formatting for PHP and combined HTML/PHP/JS/CSS files.
    • Code Intelligence: Embedded HTML/JS/CSS intelligence, detailed hover with PHP documentation links, and smart keyword highlighting.
    • Type System: Advanced PHPDoc support including templates and callable signatures.
    • Integrations: Reads PHPStorm metadata and enhances Xdebug with an inline values provider.

    Premium Features

    • Symbol Management: Easy rename (including files/folders), find all implementations, and go to declaration for interface/abstract methods.
    • Navigation & Hierarchy: Go to type definition, type hierarchy (subtypes/supertypes), and document links for include/require files.
    • Code Assistance: Auto PHPDoc creation, smart select (syntax tree driven), and code actions (import symbols, implement abstract methods).
    • UI Enhancements: Code folding, code lens (references, implementations, trait usages), and inlay hints (parameter names, return types).
  2. Licensing and Premium Access

    master

    Intelephense follows a freemium model:

    • Free Tier: All features not explicitly marked as PREMIUM are free.
    • Premium Tier: Access to advanced features (like symbol renaming, type hierarchy, and code lens) requires a licence.
    • Licence Details: A single licence key grants a single user access to all current and future premium features on multiple devices forever.
    • Activation: Licence keys must be activated automatically via HTTPS. You can enter your key in VS Code using the command Enter licence key from the command palette.
  3. Quick Start: Install and Setup Intelephense

    master

    To use Intelephense effectively in Visual Studio Code, follow these setup steps:

    1. Disable built-in PHP features: To prevent conflicts, you must disable the default VS Code PHP language features.
      • Open the Extensions view.
      • Search for @builtin php.
      • Disable PHP Language Features.
      • Note: Keep PHP Language Basics enabled to maintain syntax highlighting. It is also recommended to disable any other 3rd party PHP extensions that provide similar intelligence.
    2. Configure non-standard file extensions: If you use custom PHP extensions (e.g., .module), map them to the php language in your files.associations setting.
    3. Activate Premium features (Optional): If you have purchased a licence, activate it via the command palette (Ctrl + Shift + P) by searching for Enter licence key.
    "files.associations": {
      "*.module": "php"
    }
  4. Activate an Intelephense Licence Key

    master

    To activate a purchased licence, use the intelephense.enter.key command.

    • The key must be a 15 character alphanumeric string.
    • Activation involves a POST request to intelephense.com/activate using a machine ID derived from your home directory.
    • Once successfully activated, the licence information is stored in the extension's global storage.
  5. Configure Intelephense Runtime and Memory

    master

    You can tune the performance and environment of the Intelephense language server through VS Code settings under the intelephense namespace:

    • intelephense.runtime: Specifies the path to a specific PHP runtime to be used by the language server.
    • intelephense.maxMemory: Sets the maximum memory (in MB) for the language server. If set to 256 or higher, it applies the --max-old-space-size flag to the Node.js process.
  6. Enable Short Open Tag Auto-Close

    master

    The intelephense.shortOpenEchoAutoClose setting controls an automatic feature for PHP files. When enabled, if you type an equals sign (=) immediately following a short echo tag (<?=), the extension will automatically insert the closing tag (?>) and place your cursor inside the tags.

    Example behavior: Typing <?= results in <?= ?> with the cursor positioned between the tags.

  7. Identify and manage embedded content URIs

    master
    Intelephense uses a virtual URI scheme to represent embedded content (such as HTML, JS, or CSS) found within PHP files. These URIs use the embedded-content scheme. You can use the following utility functions to identify if a URI is an embedded content URI, retrieve the original host document's URI, or determine the language ID of the embedded content.
  8. Create Intelephense middleware with createMiddleware()

    master

    The createMiddleware() function returns an IntelephenseMiddleware object used to intercept and augment the language server's request/response pipeline. This middleware specifically handles the synchronization of VS Code workspace settings with Intelephense configuration.

    Key behaviors include:

    • Configuration Merging: When workspace.configuration is called, the middleware merges Intelephense settings with VS Code's files.associations and files.exclude settings. It also synchronizes php.validate.run with Intelephense diagnostics.
    • CodeLens Transformation: It intercepts resolveCodeLens requests to transform raw command arguments (like URI strings) into proper VS Code Uri, Position, and Location objects, ensuring compatibility with the VS Code editor.

    This middleware implements the Middleware and Disposable interfaces from vscode-languageclient.

  9. Available Intelephense Commands

    master

    Intelephense provides several commands that can be executed via the VS Code Command Palette to manage indexing and licensing:

    • intelephense.index.workspace: Manually triggers a workspace re-index. This stops the current language client and restarts it with the cache cleared.
    • intelephense.cancel.indexing: Sends a request to the language server to cancel the current indexing process.
    • intelephense.enter.key: Opens an input box to enter or update your Intelephense licence key.
    intelephense.index.workspace
    intelephense.cancel.indexing
    intelephense.enter.key