Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Namespace Resolver for PHPNew to Visual Studio Code? Get it now.
Namespace Resolver for PHP

Namespace Resolver for PHP

Nate Reprogle

|
3 installs
| (0) | Free
Import and expand php namespaces
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

PHP Namespace Resolver

PHP Namespace Resolver

Based on PHP Namespace Resolver by MehediDracula. The original has a few bugs (namely, issues with global namespaces) that have not been resolved since version 2.0, and the project has not seen any commits or updates in 6 months.

Version Installs Rating

Import, expand, sort, and manage PHP namespaces with full PHP 8+ support. Detects unimported and unused classes, offers quick fixes, and keeps your imports clean.

Changes in this fork

  • Fixed classes without a namespace always showing other non-namespaced classes as not imported.
  • Added additional classes introduced in PHP 8.4 and 8.5 to builtInClasses.ts
    • The comment in this file states that the classes listed are non-namespaced classes, yet it lists classes that are namespaced, such as Render\\Engine, so I just included the new ones regardless of namespacing or not.
  • Updated dependencies
    • Dependency update was required to fix unit tests failing on macOS, as @vscode/test-electron could not launch.

Features

  • Import Class — resolve and add use statements for any class
  • Import All Classes — detect and import every unresolved class in one go
  • Expand Class — replace a short class name with its fully qualified name inline
  • Sort Imports — sort use statements by length, alphabetically, or with natural ordering
  • Remove Unused Imports — strip all unused use statements with one command
  • Generate Namespace — generate a PSR-4/PSR-0 namespace from the file path and composer.json
  • Diagnostics — unimported classes appear as warnings and unused imports as hints in the Problems panel
  • Quick Fixes — lightbulb actions to import, expand, or remove directly from diagnostics
  • Namespace Caching — persistent index with file watcher for fast resolution
  • Multi-Root Workspace — file searching scoped to the correct workspace folder

PHP 8+ Support

Union types, intersection types, return types, typed properties, constructor promotion, nullable types, attributes, catch block types, and enum declarations are all detected and resolved.

Demo

Commands

Search these commands by the title on command palette.

Command Title
phpNamespaceResolver.import Import Class
phpNamespaceResolver.importAll Import All Classes
phpNamespaceResolver.expand Expand Class
phpNamespaceResolver.sort Sort Imports
phpNamespaceResolver.removeUnused Remove Unused Imports
phpNamespaceResolver.generateNamespace Generate Namespace
phpNamespaceResolver.rebuildIndex Rebuild Namespace Index

Keybindings

You can override these defaults in your keybindings.json.

Command Windows / Linux Mac
Import Class Ctrl+Alt+I ⌃⌥I
Import All Classes Ctrl+Alt+A ⌃⌥A
Expand Class Ctrl+Alt+E ⌃⌥E
Sort Imports Ctrl+Alt+S ⌃⌥S
Remove Unused Imports Ctrl+Alt+R ⌃⌥R
Generate Namespace Ctrl+Alt+G ⌃⌥G

Settings

You can override these defaults in your VS Code settings.

{
    "phpNamespaceResolver.exclude": "**/node_modules/**",  // Glob pattern to exclude when searching files
    "phpNamespaceResolver.autoSort": true,                 // Auto sort after importing a class
    "phpNamespaceResolver.sortOnSave": false,              // Sort imports when a file is saved
    "phpNamespaceResolver.sortMode": "natural",            // Sort mode: "natural", "length", or "alphabetical"
    "phpNamespaceResolver.leadingSeparator": true,         // Prepend leading backslash when expanding
    "phpNamespaceResolver.removeOnSave": false,            // Remove unused imports on save
    "phpNamespaceResolver.autoImportOnSave": false,        // Auto import all detected classes on save
    "phpNamespaceResolver.ignoreList": [],                 // Class names to exclude from diagnostics (e.g. ["Yii"])
    "phpNamespaceResolver.highlightNotImported": true,     // Show warnings for unimported classes
    "phpNamespaceResolver.highlightNotUsed": true          // Show hints for unused imports
}

Author

  • Nate Reprogle (Forked from: PHP Namespace Resolver)

License

MIT License.

Copyright (c) 2026 Nate Reprogle

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft