vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

My PSR-4 loader is not processed when folders are added to VS Code piecemeal

Open fulldecent opened this issue 3 years ago • 1 comments

Describe the bug Intelephense does not recognize my PSR-4 loader so I get "undefined type" errors for all my classes

When opening VS Code by adding /var/www/vhosts/ to the workspace everything works.

This bug describes when adding individual /var/www/vhosts/* folders to the workspace.

I am using Microsoft Remote - SSH to load files on server and run Intelephense inside there.

To Reproduce

My VS Code is a workspace that includes folders for

  • /var/www/vhosts/backend.example.com/
  • /var/www/vhosts/library/

Main file that is loaded:

/var/www/vhosts/backend.example.com/students/student.php

<?php
namespace PMTDashboards;
require '../config-production.php';
...
$calculator = new StudentExpirationsCalculator();

/var/www/vhosts/backend.example.com/config-production.php

<?php
namespace PMTDashboards;
error_reporting(-1);
...
require __DIR__ . '/../library/autoload.php';
require __DIR__ . '/../vendor/autoload.php'; // Composer
require __DIR__ . '/partials/autoload.php';
...

/var/www/vhosts/library/autoload.php

<?php
// http://www.php-fig.org/psr/psr-4/examples/
spl_autoload_register(function ($class) {
	$prefix = 'PMTDashboards\\';
	$base_dir = __DIR__ . '/';
	$len = strlen($prefix);
	if (strncmp($prefix, $class, $len) !== 0) {
		return;
	}
	$relative_class = substr($class, $len);
	$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
	if (file_exists($file)) {
		require $file;
	}
});

/var/www/vhosts/library/StudentExpirationsCalculator.php

<?php
namespace PMTDashboards;
class StudentExpirationsCalculator
{
}

Expected behavior

When browsing /var/www/vhosts/backend.example.com/students/student.php in VS Code, the symbols in StudentExpirationsCalculator are recognized.

Or if it is not recognized because the __DIR__ . '/../library/autoload.php' include is unable to get access, then some type of "Intelephense is having a problem" error should be shown in that popup.

Screenshots

Screen Shot 2021-08-16 at 10 51 27

Platform and version

macOS 11.5 // SSH into Linux CENTOS 7 // Intelephense 1.7.1 (activated)

NOTES

It seems like maybe Intelephense is processing /var/www/vhosts/backend.example.com/config-production.php and tries to load the __DIR__ . '/../library/autoload.php'. That file is outside of the workspace folder /var/www/vhosts/backend.example.com so maybe it assumes it does not have access to that file. But actually it does have access to that file because /var/www/vhosts/library IS another folder the workspace has access to.

fulldecent avatar Aug 16 '21 14:08 fulldecent

any luck?

mimda avatar Jun 04 '22 18:06 mimda

Intelephense doesnt execute any autoloaders and only indexes symbols found in the workspace folder. External symbols can be linked to with the intelephense.environment.includePaths setting. eg "intelephense.environment.includePaths": ["/path/to/other/code/**"]

bmewburn avatar Jan 14 '23 05:01 bmewburn