3

Intelephense show error like "unknown type" and "unknown function", but I have no clue how to fix them.

My project (a TYPO3 composer installation) has a "public" folder, which is, why I configured intelephense's intelephense.environment.documentRoot option accordingly by setting it to ./public.

The first screenshot shows the page tree of the project with a section opened, where the error occurs.

Project tree

When I open "function.php", intelephense informs me about a "Undefined type 'Aimeos\Map'":

"Undefined type" error

Map is defined right next to the function.php file in Map and ooks like this:

The Map Class

There are other places in the code, where intelephense informs me about a "Undefined function 'map'":

Other code snippets with error message

I had a look at intelephense's "function" template, but I do not know, what to put there. Neither, if I also have to define a class template and/or anything else.

This is my VSCode configuration for intelephense:

VSCode config

As can be seen, I tried to exclude "vendor/aimeos" files using the negator "!", but I assume this is not a known configuration value within intelephense.

What do I have to do to make intelephense work correctly? Thank you!

Gama11
  • 31,714
  • 9
  • 78
  • 100
Robert Wildling
  • 1,014
  • 12
  • 29
  • 3
    I know virtually nothing about VSCode/Intelephense but [that answer](https://stackoverflow.com/a/59152511/965834) to a similar question seems to imply the (recently added) feature is quite buggy. – Jeto Oct 17 '20 at 11:51
  • Thank you! There is a lot of valuable information there! "Vendor" must not be disabled - that is one thing. But then a lot of useless file indexing happens, which I would like to suppress due to performance. Still need to figure out, how my stubs must look like and where to place them... – Robert Wildling Oct 17 '20 at 12:04
  • 1
    I propose setting the documentRoot one level up and exclude all dirs you don't need like node_modules but still keep the vendor directory. Otherwise also a lot of stuff like ViewHelpers won't show you correct information – Georg Ringer Oct 19 '20 at 15:17

1 Answers1

3

I was getting these warning even after adding appropriate use declarations. For me, I had to open the files where these types are declared from the vendor folder and then save the offending file. This somehow seems to trigger the intelephense type resolution mechanism and the warnings go away. Once intelephense recognizes them then you can safely close those files off of vendor folder. I tried closing the vs code and reopening it and still no warnings. Your mileage may vary.

Sonny N
  • 170
  • 8
  • 1
    Interestingly, I've used exactly this approach using a completely different editor, namely, Nova from Panic, which is a macOS-only application. It also supports LSP and there is an extension for Intelephense, which works rather well. But it exhibits the same 'problem': you need to open & save dependent files in order to get Intelephense to recognise the symbols defined there. Once I did that — as you suggested! — everything worked flawlessly :-) Thanks! – Gwyneth Llewelyn Apr 22 '22 at 16:12
  • 1
    BTW, I believe that @robert-wilding ought to mark your answer as the one that solves the issue :-) – Gwyneth Llewelyn Apr 22 '22 at 16:13