Setup
- VS Code
- Windows 10
- WSL 2.0 (Ubuntu)
So let's say all my projects are PHP projects, run in Docker on WSL.
Projects are using different PHP versions, namely 7.4.x, 8.0.x, and 8.1.x, which is accomplished by lines similar to FROM php:7.4.4-fpm-alpine in their respective Dockerfiles.
How to instruct VS Code to use the correct PHP version?
Currently, I have different local PHP installations and I have to switch between them for every project. I do the switch because I use both the linter and the formatter to help me keep my code tidy and without errors, but you can imagine it's a chore I often forget to do.
Is it possible for VS Code and its extensions (Intelephense, phpfmt) to actually use the PHP binaries in the Docker image?
And if not, is it possible to have VS Code somehow read which version is being used by the image, and automatically choose the same version of local PHP binaries? (And will it affect performance?)
Examples
Writing code in PHP 7.4 and forgetting to change PHP version from 8.1 the editor allows me to write match expression, only to have the code fail the pipeline.
return match ($isPhpVersion8orGreater) {
true => 'All good',
false => 'Never made it to here...'
};
Just looking at code written in 8.1 basically forces me to change the version from 8.0, so my eyes don't bleed out from all the red squiggly lines on enums.
enum NotAClass
{
case We;
case Are;
case All;
case Mistakes;
}
Weakly related
It would also be nice if sidebar file explorer operations, and any other actions done by extension, would use the same user (whoami) as the shell attached to the Docker container of your choosing, but perhaps we're not there yet.
PS: take a moment for a couple of deep breaths and stretches, and have a great day you wonderful person