VSCode PHP Intelephense doesn't detect my libraries
Asked Answered
C

3

5

I'm switching from PhpStorm to VSCode for my PHP development and I have a problem: For my multi-root workspace, it only detects the classes from the current repository, not all the other repos and libraries from my project. For example, when trying to autocomplete a class, Go to Definition, etc.

I'm developing a TYPO3 project, using composer. Therefore, the structure of the nested projects is this one:

path-to-html/
path-to-html/public/typo3conf/ext/{extension1, extension2, etc.}

I've installed the VSCode PHP Intelephense extension and configured it according to its description. But, as I've said, I only get completion for symbols of the current repository, not of all the libraries of the TYPO3 project. How should I configure this?

I've read all the Intelephense options and I've tried setting these ones:

    "settings": {
        ...
        "intelephense.environment.documentRoot": "/path-to-html",
        "intelephense.environment.includePaths": [
            "/path-to-html/public/typo3conf/ext/extension_1",
            ...
        ]
    }

But it still doesn't work.

Collodion answered 20/3, 2022 at 21:12 Comment(2)
Does this answer your question? How can I add TYPO3 Library to Visual Studio Code?Momentary
@MartinZeitler Thanks for the answer, but not really. I've already added the TYPO3 source folder to my workspace (the html one). And I've also tried running composer install again, without success.Collodion
G
4

Disclaimer: I also have "PHP Intellisense" installed. The context menu items such as "Go to Defintion" or "Go to declaration" etc only work correctly, when I use enable both extension. Maybe it has to do with the fact that "PHP Intellisense" also uses the Language Server Protocol, but the implementation of the LSP is provided by "PHP Intelephense". Admittedly I don't understand it fully, .

In any case, these "PHP Intelephense settings" work for me.

I am using these settings right now for a local TYPO3 CMS 10 version, ddev-based.

I'll provide it here as a screenshot because these are VSCode Workspace Settings, and I cannot fgure out where VSCode stores these. (They are not stored in the $HOME/.config/Code/Usersettings.json file).

vscode settings

I think I could have used $HOME/ddev/typo3-10/public/typo3/sysext/ instead of $HOME/ddev/typo3-10/public/typo3/. Havent't tries

Key is,

  • Intelephense needed a few minutes to pick up the settings after changing them. It does not happen instantly that the red wiggly lines disappear
  • Needless to say, "Go to Definition" (opens a Doc-preview Window), "Go to Declaration" (Opens the PHP Class File), etc, are only enabled for Intelephense Premium.
Gusta answered 22/5, 2022 at 11:30 Comment(3)
Glancing at your solution led me to type $HOME/my/path and it took me a bit of digging before I realized your screenshot used $HOME to redact your actual home path. Note to anyone else the variable $HOME does not work, use the actual absolute path and this works (instantly for me)Bihar
Okay; thanks. Maybe I'll upload an edited version of my screenshot with a real absolute path to my home directory; but then I had to point out that users should enter the absolute path to their home directory (or vendor/ subdirectory)Gusta
It seems as though Intelephense is really slow in picking up changes to the environment (or vscode is slow to report them). When I run composer dump-autoload usually nothing happens until I reload vscode. I have also added vendor/ to the Intelephense includePaths and that seems to have sped up "adoption" of new classes.Connubial
M
2

No need to install, while it is supposed to be there and the html is useless.

The config needs to include the sources; eg.:

"intelephense.environment.includePaths": [
    "../../typo3_src/typo3_src-8.7.44"
]

Also see: https://github.com/bmewburn/vscode-intelephense/issues

Momentary answered 21/3, 2022 at 0:35 Comment(1)
Thanks again for the answer, but I've tried setting that option to multiple of the nested repos but it still doesn't detect those libraries. I have no idea what could be happening.Collodion
P
1

I just quit VS Code and re-open it. VS Code will open in the exact state it was in on quit. And Intelephense will have scanned the vendor folder. No need for any config changes.

Pissarro answered 20/2, 2023 at 21:37 Comment(1)
Worked on my end too. I just needed to quit all VS code windows. Open it again and they were already resolved.Physique

© 2022 - 2024 — McMap. All rights reserved.