Skip to content

Index files outside project directory #1113

Closed

Description

@norival

Hi!

I was wondering if it is possible to index files outside project directory in order to have completion and code navigation. I'm working on projects that depend on other php files that are in a different location (these projects are not using composer).

Everyone here is using phpstorm and it is possible to add these files as 'External librairies' to have autocompletion of classes and methods and code navigation.

Thanks! :)

Activity

  1. camilledejoye commented on Nov 1, 2020

    @camilledejoye
    Contributor

    Hi,

    It's currently not possible.
    I guess we could add this feature, like we did in order to index the stubs, but I'm not sure it's a good idea right now.
    The issue is that I'm almost certain we still have features that do not rely on the index.

    So if we add this possibility we will have inconsistent behavior because the features relying on the index will be aware of the external code while other features won't.

    @dantleech You have a better vision of project as a all, do you think it would behave properly ?
    Maybe we can add the feature but specify that it is only supported when used as a LSP server ?
    Even though some RPC features start using the indexer so we will still have the same issue.

    I realize that the indexer configuration as not been updated, only the configuration reference
    Also, it's not possible to override or change the value of indexer.stub_paths because of:

    $config[IndexerExtension::PARAM_STUB_PATHS] = [

    I guess that if we don't want it to be configurable by the user we should not expose it in the configuration, since it's made as a list I think you intended it to be configurable.

    So to resume:

    • Is it possible to add external sources to the indexer without having a strange behavior ?
    • If so, maybe we should rename the stub_paths to something like external_sources
    • Should the user be able to add its own stub paths ? (to fix the current behavior)
  2. dantleech commented on Nov 1, 2020

    @dantleech
    Collaborator

    Yes, adding it to stub paths would accomplish what is required I think. Maybe it should be renamed, and maybe the phpstorn stubs can be added programatically rather than via config

  3. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    Hi! Thank you for your answers and all the details :) It would be great to have this feature. Is there any way I can help?

  4. dantleech commented on Nov 3, 2020

    @dantleech
    Collaborator

    For now you could try setting:

    {
        "indexer.stub_paths": [
            "/absolute/path/to/phpactor/vendor/jetbrains/phpstorm-stubs",
            "/path/to/your/external/files"
        ]
    }
    
  5. camilledejoye commented on Nov 3, 2020

    @camilledejoye
    Contributor

    We need to fix the initialization of the config first, if I understand how the config loader works, we first load the config from the config files, then we override the stubs then we load the extension configs.

  6. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    For now you could try setting:

    {
        "indexer.stub_paths": [
            "/absolute/path/to/phpactor/vendor/jetbrains/phpstorm-stubs",
            "/path/to/your/external/files"
        ]
    }
    

    It does not change

  7. dantleech commented on Nov 3, 2020

    @dantleech
    Collaborator

    You'll need to do a --reset, e.g. :CocCommand phpactor.reindex or $ phpactor index:build --reset

  8. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    Ok, I tried to reset the index, but it is still the same. I tried to query with phpactor index:query and it does not find the references either.

  9. dantleech commented on Nov 3, 2020

    @dantleech
    Collaborator

    are you on develop? in master stub_paths does not work. Try phpactor index:search (index:query requires FQNs - it not very well named)

  10. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    Ah, I was on master, sorry. I switched to develop but it is still not working. It does not find the references in vim, nor with phpactor index:search. The index:build --reset command says there are 306 files in the index whereas there are around 5000 php files in the external libraries.

  11. dantleech commented on Nov 3, 2020

    @dantleech
    Collaborator

    if you run index:build --reset --verbose you should at least see the phpstorm-stub files being indexed, the path may need to be absolute, what does phpactor config:dump --config-only | jq '.["indexer.stub_paths"]' say? (may need to brew|apt install jq or just parse the output manually. .)

  12. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    Yes, the phpstorm-stub files are shown with the --verbose option. Here is the output of phpactor config:dump --config-only | jq '.["indexer.stub_paths"]':

    [                                                                   
      "/home/xlaviron/.local/share/nvim/plugged/phpactor/vendor/jetbrains/phpstorm-stubs"
    ] 
    

    I tried changing the value in the config file, and the output is always the same.

  13. dantleech commented on Nov 3, 2020

    @dantleech
    Collaborator

    ah ok, then I misunderstood how it currently works:

    $config[IndexerExtension::PARAM_STUB_PATHS] = [
    self::resolveApplicationRoot() . '/vendor/jetbrains/phpstorm-stubs'
    ];

    we could append the stubs here if the key exists rather than overwriting -- that might be an intermediate solution.

  14. norival commented on Nov 3, 2020

    @norival
    ContributorAuthor

    Ok! I tried setting the paths directly here :

    $config[IndexerExtension::PARAM_STUB_PATHS] = [
    self::resolveApplicationRoot() . '/vendor/jetbrains/phpstorm-stubs'
    ];

    and the files are indexed! Completion and go to definition work fine :) I had to increase php's memory limit though.

  15. added a commit that references this issue on Feb 6, 2021
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