DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
82 stars 10 forks source link

PHP0413 Error (Unknown Class) for symlinked packages #684

Closed julesgilson closed 5 hours ago

julesgilson commented 1 month ago

Intellisense is always showing "unknown class" PHP0413 for composer packages installed from local repo. Unsure if this is because composer creates a symlink in ./vendor/publisher/ to the package or for another reason.

Note: This is on Windows - symlinks on *nix systems may not have the same issue - if it is a link issue.

Re-importing the class fixes the issue until VSC is restarted - where the problem returns. Quite tedious as the package is used in many other classes...

This scenario is common when developing composer packages - i.e before they can be installed from Packagist


Package installed with Composer from a repo defined in composer.json:

"repositories": [
        {
            "type": "path",
            "url": "../relativepathto/package"
        }
    ],

As this is a path type repo, by default composer creates a symlink in ./vendor/publisher/ to the package's source

Is therefore included in ./vendor/composer/installed.json:

{
            "name": "publisher/package",
            "version": "dev-master",
            "version_normalized": "dev-master",
            "dist": {
                "type": "path",
                "url": "../relativepathto/package",
                "reference": "a7acca5e62f96425339de18a781fee5a83e7b84a"
            },
           ... ...
            "type": "library",
            "extra": {
                "laravel": {
                    "providers": [
                        "publisher\\package\\provider"
                    ]
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-4": {
                    "publisher\\package\\": "src/"
                }
            },
            ... ...
            "transport-options": {
                "relative": true
            },
            "install-path": "../publisher/package"
        },
jakubmisek commented 1 month ago

Thank you for reporting the issue.

We specifically handle symlinked packages on Windows - let me check what we're doing wrong here.

julesgilson commented 1 week ago

I am sure I saw an email with a further response from you.... not showing here! In it you mentioned you found the source of the issue and that it would be fixed. Any update when?

jakubmisek commented 1 week ago

I am sure I saw an email with a further response from you....

sorry, it was a mistake. I thought I found the culprit :)

julesgilson commented 1 week ago

so, um... any ideas for a work around? It is driving me crazy having to reimport every class every time I open a file 😕

jakubmisek commented 1 week ago

is the symlink target outside of the workspace folder?

julesgilson commented 1 week ago

is the symlink target outside of the workspace folder?

yep. Its a Laravel package in dev - installed in a few test projects with composer - so creates a symlink to source in the vendor folder of each project.

I could move the package source to a project's vendor folder - but that only solves the problem for one project.

I guess my question is... is this just something that can't be fixed? If so I will have to get creative. (maybe syncing copies of the source to each projects vendor folder.) I would prefer the correct solution if that is possible.

Thanks.

jakubmisek commented 1 week ago

Thanks! We have, by purpose, ignored symlinks targeting outside the project folder.

The fix will be available in the upcoming update (pre-release).

jakubmisek commented 5 hours ago

The latest release (1.53) fixes the indexing of packages symlinked outside the vendor folder.

Please let us know if it works now.

Maybe it will be necessary to run VSCode Command from Command Palette: "clear /vendor/ cache".

Thanks!