Skip to content

Incorrect project root detection #941

Open

Description

@dantleech
2020-04-06 09:05:46] phpactor.DEBUG: Resolved path "%application_root%/vendor/jetbrains/phpstorm-stubs" to "/home/daniel/www/phpactor/phpactor/vendor/jetbrains/phpstorm-stubs" [] []
[2020-04-06 09:05:46] phpactor.DEBUG: Resolved path "%cache%/worse-reflection" to "/home/daniel/.cache/phpactor/worse-reflection" [] []
[2020-04-06 09:05:46] phpactor.DEBUG: Resolved path "%project_root%/vendor/autoload.php" to "/home/daniel/www/inviqa/foobar-foobar/vendor/spryker-shop/catalog-page/vendor/autoload.php" [] []
[2020-04-06 09:05:46] phpactor.WARNING: Could not find autoloader "/home/daniel/www/inviqa/foobar-foobar/vendor/spryker-shop/catalog-page/vendor/autoload.php" [] []
[2020-04-06 09:05:46] phpactor.DEBUG: Resolved path "%project_root%" to "/home/daniel/www/inviqa/foobar-foobar/vendor/spryker-shop/catalog-page" [] []
[2020-04-06 09:05:46] phpactor.DEBUG: Resolved path "%cache%/index/%project_id%" to "/home/daniel/.cache/phpactor/index/catalog-page-f0ca3b" [] []

The vendor dir was resolved when trying to goto implemtnations instead of the project root.

The defaults root patterns are:

let g:phpactorProjectRootPatterns = get(g:, 'phpactorProjectRootPatterns', ['composer.json', '.git', '.phpactor.json', '.phpactor.yml'])

All of these could be matched in a vendor dir (the .phpactor ones being much less likely)

Any operation Phpactor attempts in third-party packages will likely not work. cc @przepompownia

Resolved by locally setting:

let g:phpactorProjectRootPatterns = []

Activity

  1. przepompownia commented on Apr 6, 2020

    @przepompownia
    Contributor

    Right, detecting by patterns that are present at the top of vendor packages does not make its job.

    We have not available the third method: manual selecting the root of the project (the first method does it implicitly by setting current working directory before calling to phpactor). It's advantage is avoiding a situation like presented above. It has also drawback if it bases on one global variable per whole vim process in the case when we need to have work on more than one project.

    Proposition: have more than one project root and assign each buffer handled by phpactor to exactly one of them. It implicitly would define "project" described only by its root at this moment. Probably assumptions:

    • for the first such buffer (in newly created project) we determine its root directory by one of mentioned method,
    • we define what belonging to the project means (e.g. buffer file path is under its project root directory) and if we open any file then we decide if it belongs to any existing project or we have to create the new project.
  2. dantleech commented on Apr 6, 2020

    @dantleech
    CollaboratorAuthor
  3. camilledejoye commented on Apr 8, 2020

    @camilledejoye
    Contributor

    I have followed this subject from afar since it's a bit crazy at work currently.
    However I wonder if it's a good idea to use the composer.json file since it will be present in most PHP projects (including the vendors).
    If I'm not mistaken the .git directory is not created for the vendors, neither as it should be for monolithic projects with a gitsplit feature.
    So it might be a better idea to rely on .git, .phpactor, .projections and forget about composer files.

  4. dantleech commented on Apr 8, 2020

    @dantleech
    CollaboratorAuthor

    If I'm not mistaken the .git directory is not created for the vendors

    It is if you install dev versions.


    I think @przepompownia 's suggestion of assuming the project root to be the (resolved) directory of the first opened buffer, then switch if opening a buffer outside of that root makes sense (and seems to be the same as CoC


    What is .projections? 🤔

  5. camilledejoye commented on Apr 8, 2020

    @camilledejoye
    Contributor

    Whait is .projections

    I might have misspelled it, it came form https://github.com/tpope/vim-projectionist

    If I'm not mistaken the .git directory is not created for the vendors

    It is if you install dev versions.

    I'm surprised because I have a composer.json with a require-dev including "phpunit/phpunit": "^9.0@dev" and not .git folder in vendor/phpunit/phpunit

    You only need git when you intent to commit, when installing a dependency with composer you usually dont so it make sense to me that composer clone in a way that ignore the .git directory.

    But no matter at the end because I could also use a path repository and have a vendor which is actually a simlink to a project with the .git directory...
    I do that a lot with phpactor packages :D

    I think @przepompownia 's suggestion of assuming the project root to be the (resolved) directory of the first opened buffer, then switch if opening a buffer outside of that root makes sense (and seems to be the same as CoC

    It make sense if we are dealing with it inside vim.
    But I thought the idea was that the client will ask to the server to gave him the root directory for a file.
    But again I followed from really far so I might not have understood something, but if that's the case then the server should be not be concerned by where the client was on the last call to this method.

  6. dantleech commented on Apr 9, 2020

    @dantleech
    CollaboratorAuthor

    that the client will ask to the server to gave him the root directory for a file.

    I don't think that was the idea - (in the context of RPC) Phpactor has no state, so can't decide what the project root should be

  7. przepompownia commented on Apr 11, 2020

    @przepompownia
    Contributor

    and not .git folder in vendor/phpunit/phpunit

    @elythyr try --prefer-source or its config equivalent.

    Right, usually fetching VCS index does not make sense, but sometines it is very practical. Phpactor itself is a good example. Sometimes I want to test a changes in some subproject that are not yet available for whole phpactor project because of constraints from composer.lock or when I would like to use custom changes.

  8. dantleech commented on Apr 12, 2020

    @dantleech
    CollaboratorAuthor

    Might also be good to be able to explicitly request the CWD to be re-calculated (e.g. when working in a vendor dependency for Phpactor)

  9. przepompownia commented on Apr 13, 2020

    @przepompownia
    Contributor

    @dantleech @elythyr please look at and test the early implementation of the idea described above: #959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions