Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined type 'Imagick' in VSCode's intelephense

I had an issue where I installed Imagick via Pecl and Intelephense didn't know what to do with that extension and failed to show any code completion even though the extension was properly installed in the php.ini file and was working fine.
Some screenshots to bring clarity:

  1. Code where Imagick is used
  2. Bash output showing that the imagick extension is installed in the php.ini:
ddruganov@MBP-Demid:~$ php -i | grep imagick
imagick
imagick module => enabled
imagick module version => 3.4.4
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0
  1. Bash output showing where the extension is located:
ddruganov@MBP-Demid:~$ mdfind imagick.so
/usr/local/lib/php/pecl/20190902/imagick.so
like image 857
ddruganov Avatar asked Jun 08 '20 09:06

ddruganov


1 Answers

Turns out intelephense just wasn't configured to know what this extension is.
The solution is very simple:

  1. Go to Intelephense extension settings in VSCode
  2. Go to a setting called 'Intelephense: Stubs'
  3. Add a new item named 'imagick'
  4. Save and close settings (though I believe they are saved
    automatically)
  5. Done

After all this is done, Intelephense shows all info about Imagick and auto-complete works just fine: proof

Hope this helps someone!

like image 174
ddruganov Avatar answered Oct 19 '22 12:10

ddruganov