Search code examples
visual-studio-codesymfony-3.4vscode-remoteintelephense

VS Code + PHP Intelephense + Remote-SSH + Symfony 3 : undefined method error


I'm discovering VS Code, I am a complete newbie with this code editor, before I used Atom but I want to use VS Code which looks very cool!

I have a Symfony 3 project on a Linux server and I want to directly modify its files because it's a dev environment. I don't want to have a local copy.

So, I installed VS Code on my PC and I downloaded Remote-SSH and PHP Intelephense extensions. After several problem, I managed to make it work but I have a lot of issues inside my Controllers because PHP Intelephense doesn't recognize a lot of methods whereas it should do.

I turned off the built-in PHP Language Features of VS Code.

For example, here are some undefined methods :

It doesn't recognize $repository->createQueryBuilder() or $em->createQuery() or custom functions inside Repository class of entities. It doesn't recognize some functions defined inside the Controller itself whereas they are correctly defined. It doesn't recognize the Symfony basic repository methods like $repo->findOneByProperty(), etc.

So my files are full of errors while everything is normal! ^^

Can someone help me ? If Remote-SSH isn't the best extension, maybe you can advise me another one ? Same thing for Intelephense ?


Solution

  • The only solution I found is to have the project in local and use SFTP extension (by liximomo) to upload files on the server after saving them. PHP Intelephense is working well with that configuration. Symfony for VScode extension (by TheNouillet) can be useful too.

    settings.json

    "emmet.includeLanguages": {
        "twig": "html"
    },
    "symfony-vscode.phpExecutablePath": "C:\\wamp64\\bin\\php\\php5.6.16\\php.exe",
    "files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/*/**": true,
        "**/vendor/**": true
    },
    "editor.quickSuggestions": {
        "other": true,
        "comments": true,
        "strings": true
    },
    "php.suggest.basic": false,
    "intelephense.files.exclude": [
        "**/.git/**",
        "**/.svn/**",
        "**/.hg/**",
        "**/CVS/**",
        "**/.DS_Store/**",
        "**/node_modules/**",
        "**/bower_components/**",
        "**/vendor/**/{Test,test,Tests,tests}/**/*Test.php"
    ],
    "intelephense.diagnostics.undefinedMethods": false