Feature request: set php version per folder
First of all: huge thank you for you project!
It would be great if I could configure different php versions per folders in my project. I work on legacy project which for historical reasons have several php version for some parts of it, and I would greatly appreciate if I will not have need to constantly go to phpactor config and change which php version I would like to work with today
P.S. Sorry for bad English
Hey, there is the option to add a phpactor config in the current (project) folder. This should override the settings from the global phpactor. Have you tried that already?
No, I am not. But I will try it, thank you
When I dump phpactor config via cli in different folders it dumps correct versions of php, but it does not work in neovim phpactor as language server. I am using this lua function to check phpactor config:
function LspPhpactorDumpConfig()
local results, _ = vim.lsp.buf_request_sync(0, "phpactor/debug/config", {["return"]=true})
for _, res in pairs(results or {}) do
showWindow("Phpactor LSP Configuration", "json", res["result"])
end
end
Every time I use it in neovim in says that "php.version" is null
Correction: neovim says that current "php.version" is what is inside of phpactor configuration file which is in current project root directory.
But folders with different php versions required are not separate projects, that is the problem
I assume the separate folders are different projects? I would personally use a different workflow:
- start neovim in the root of the project/folder you are working in
- and then we can put the
.phpactor.jsonin the root of each
You could probably also write a LUA script to change the root dir and restart Phpactor, but I don't know about that.
I assume the separate folders are different projects?
I am sorry for bad description of my situation. Let me explain more clear. I have a project with roughly this structure:
project/
| app/
| | ... some files
| \_____
|
| html/
| | index.php
| | ... some other files
| \_____
|
| some_folder/
| | index.php
| | ... this is where different version of php used
| \_____|
| .phpactor.json
| file1.php
| composer.json
\_____________
Whole project uses one version of php, except for some_folder, which is using different version of php with its own index.php, but this is same project and it uses some code from main "project" (ones that can work in this situation)
Yeah, I know that this is really bad, but legacy codebase is legacy codebase and I can't do anything about it. But I still need to work on it.
I tried to put additional .phpactor.json in some_folder, but that did not worked
Okay, dumb question but what benefits do you expect from having a different php version in the subfolder? Many of the features of phpactor don't respect it. For example the "constructor promoted properties" from php 8 will still be available when the language level is set to 7.4. It's going to produce code that can't be run though.
Well, that looks like a bug that should be fixed
@Strongleong I feel your pain about the legacy setup, been there. Have you tried Dan's suggestion? You shared the structure of your project which shows that the root is using a particular version of PHP, and a sub folder with a different one.
You could open some_folder inside as a seperate project, I assume it has it's own composer.json etc..
And then when you open the root of your project, you could just ignore the subfolders as they have different PHP versions.
Your setup isn't ideal for sure, I think ideally it would be best to seperate the different PHP versions into different repositories and treat them as seperate projects.
I don't think it would benefit anyone using phpactor to having this complicated setup supported, given this is extremely rare and would possibly add enourmous overhead. Wouldn't clasify this as a bug therefor.
Hi, @Dmitrev! Thank you for your response.
Your assumption about composer.json inside of some_folder is incorrect. In my project there is only one composer.json, only one git repo, only one workspace root and there is nothing in some_folder that can hint that this folder is workspace/project root. And nobody in my company gonna separated this mess into diferent repositories, nobody gonna refactor this because there is just too much of code that requires too much work.
(We had another legacy project with similar complexity. It's team refactored it for a year and didn't finish)
I understand that adding proper support for php 5.x, neither support for multiple php versions in one project is probably not gonna happen. That's sad, but I am fine with that.
Ok, I'll close this then. As @mamazu said there would be limited benefits to setting the php version per folder anyway, maybe an exception bring some code generation (typed properties f.e.). Can PHPStorm do this per folder?
Not without opening it in a new project. So we're on par with that.