Composer

Installation

Composer All-in-One is a part of PHP Tools extension. Although it can be installed separatelly from the Composer extension page.

Composer.json Editor & IntelliSense

The composer.json editor is extended with smart actions, code lenses, tooltips, and IntelliSense to autocomplete packages and versions from packagist.org.

Completion of Package Names

Code completion searches packages and lists their names with detailed information including downloads, favorites, abandoned information, and description. There are also quick links to the package home page, package source code, and packagist page.

composer completion

Completion of Package Versions

Available minor versions are fetched from packagist listed in code completion after the required package name:

complete package version

Tool-Tips

Installed package details are displayed in the tooltips.

composer package tootip

Code Actions

Quickly update or remove package right from the editor, using the code actions:

composer code actions

Installed Version Inlay

Actual installed version is displayed connveniently next to the package required version:

installed package versions

Run-Script CodeLens

The "scripts" section of composer.json gets a small code-lens allowing to quickly run the corresponding script, right from the editor:

composer run-script codelens

Diagnostics & Abandoned Packages

The extension watches for installed packages and checks if any of them isn't abandoned. Abandoned packages are listed in VS Code's problems view, strikethrough, and the tooltip shows the corresponding abandoned message:

composer diagnostic for abandoned packages

Commands

Integrated commands work with the composer.json in the workspace root directory. If necessary, commands ask which workspace folder you're referring to. It allows quickly require, remove, or search for packages from packagist.org, and more.

The following commands are usually executed as a VSCode task, using php executable as configured in the Settings, and composer.phar downloaded automatically when necessary (so it is not necessary to install it by yourself).

composer: install

Runs the install command.

composer: update

Runs the update command.

composer: require

The composer: require command shows quick-pick with online search, and installs the selected package. The search displayed all the important information including packages description, downloads, and favorites.

composer require

composer: require-dev

Requires a dev package; this works the same as composer: require but the packageis installed as a development dependency.

composer: remove

Removes installed package or more packages from the project. The command shows quick pick with multi-selection allowing to choose the packages to be removed:

composer remove

composer: create-project ...

Open an empty folder in VS Code, and create a new project from a composer package. The command shows quick-pick that searches online for available packages and invokes the create-project command for you:

composer create-project

composer: search ...

Search packages on packagist.org. Quickly browse through packages, read descriptions, open details on packagist.org or require the package right from the quick pick menu.

composer search

composer: run-script ...

Quickly run your composer script from command palette:

composer run-script

composer: check-platform-reqs

composer: update the internal composer.phar

The extension automatically downloads the latest composer installation, and uses it for all the tasks and commands. Run composer: update the internal composer to manually re-download the latest snapshot.

composer: about

Shows the about information.

composer: archive ...

Runs the archive command, and asks for arguments.

composer: clear-cache

Clear the internal composer cache.

composer: fund

Shows your required packages funding options.

composer: licenses

Shows summary of your required packages licenses.

composer: outdated

Shows list of outdated packages.

composer: reinstall

Runs the reinstall command.

Tasks

VS Code task that executes a composer command is a useful way of configuring and running composer. The composer.phar itself is automatically installed, and php executable is determined from Settings.

Example:

"tasks": [
    {
        "label": "check",
        "type": "composer",
        "command": "check-platform-reqs",
        "args": []
    }
]

Schema Validation

The extension provides schema validation for composer.json files, maintained by @composer.

  • correctness validation.
  • tooltips and code completion for composer.json JSON elements.

Configuration

If there's an existing installation of composer.phar under the following paths, it's used as it is:

  • /usr/bin/composer (Linux/OsX)
  • /usr/local/bin/composer (Linux/OsX)
  • ${COMPOSER_HOME}/composer.phar
  • .composer/composer.phar under user's home (Linux, OsX)
  • ${APP_DATA}/Composer/composer.phar (Windows)

Otherwise, the extension automatically downloads composer.phar latest snapshot, uses it, and keeps it updated. The location respects the Composer default installation path which can be changed by setting the COMPOSER_HOME environment variable.

Additional Settings

Setting Description
php.executablePath The value is used to determine php executable path for running composer commands. If not set, "php" is used by default.

In case, there is PHP Tools extension installed, composer commands are executed using php set with PHP Version Picker.
composer.workingPath The relative path for the composer.json

Related links