phpactor icon indicating copy to clipboard operation
phpactor copied to clipboard

Feature request: set php version per folder

Open Strongleong opened this issue 1 year ago • 8 comments

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

Strongleong avatar Jan 30 '24 23:01 Strongleong

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?

mamazu avatar Jan 30 '24 23:01 mamazu

No, I am not. But I will try it, thank you

Strongleong avatar Jan 30 '24 23:01 Strongleong

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

Strongleong avatar Jan 31 '24 00:01 Strongleong

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

Strongleong avatar Jan 31 '24 00:01 Strongleong

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.json in 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.

dantleech avatar Jan 31 '24 18:01 dantleech

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

Strongleong avatar Jan 31 '24 22:01 Strongleong

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.

mamazu avatar Jan 31 '24 23:01 mamazu

Well, that looks like a bug that should be fixed

Strongleong avatar Feb 01 '24 01:02 Strongleong

@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.

Dmitrev avatar Feb 29 '24 11:02 Dmitrev

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.

Strongleong avatar Feb 29 '24 22:02 Strongleong

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?

dantleech avatar Feb 29 '24 22:02 dantleech

Not without opening it in a new project. So we're on par with that.

mamazu avatar Feb 29 '24 22:02 mamazu