Skip to content

vim plugin not working with option set autochdir or when launching vim in a subfolder  #1085

Open

Description

@allan-simon

I'm using neovim and I have in my init.vim the line set autochdir , and it seems to not play nice with phpactor

is it possible for phpactor to try to find in the parent folders if there's a .git folder or composer file in order to choose the root of the project (like many other command line utilities do ) ?

Activity

  1. dantleech commented on Jul 7, 2020

    @dantleech
    Collaborator

    Phpactor doesn't support this directly but you can provide an anonymous function to detect the project root by g:PhpactorRootDirectoryStrategy (:help phpactor or https://phpactor.readthedocs.io/en/develop/vim-plugin/man.html).

    Maybe @przepompownia or @elythyr can recommend a way to use this in conjunction with a root-detection strategy/plugin?

  2. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author

    @dantleech thanks for the quick answer, as I'm not familiar with anonymous function in vimscript, do you have a quick example of a dirty workaround that would just return always the same root path ?

  3. dantleech commented on Jul 7, 2020

    @dantleech
    Collaborator

    Me neither in complete honesty, :help Funcref

    I assume something like g:PhpactorRootDirectoryStrategy = function () { return getcwd() } for example.

  4. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author

    ok thanks, I've seen the "expr-lambda" help but adding in my init.vim

    let g:PhpactorRootDirectoryStrategy = {-> '/home/allan/myproject' }
    

    does not seem to work

    :Phpactorstatus still return the same working directory :(

  5. dantleech commented on Jul 7, 2020

    @dantleech
    Collaborator

    You'd need to restart VIM of course ?

  6. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author

    haha, I did :) but still does not seem to works

  7. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    @dantleech restarting is not needed. The function is executed each time we call to RPC. @allan-simon do you have the version that uses let g:PhpactorRootDirectoryStrategy? :Phpactorstatus or :checkhealth should print both the version and the working directory.

  8. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    One detail: if you have set the buffer equivalent (b:PhpactorRootDirectoryStrategy) then it takes precedence over the global.

    I noticed that we have this possibility undocumented.

    Phpactor does not set this buffer variable itself.

  9. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author
    Version: 111c3e6 (4 days ago) 0.16.1-1083
    Filesystems: simple
    Working directory: /vagrant/src
    

    I've tripled-checked , I have only g:PhpactorRootDirectoryStrategy defined

    Here's my init.vim

    set mouse=a
    " workaround https://github.com/neovim/neovim/issues/6041
    set guicursor=
    "
    set tabstop=4
    set softtabstop=4
    set shiftwidth=4
    set smarttab
    
    set expandtab
    set smartindent
    
    set wildmode=longest,full
    
    set autochdir
    
    
    set showcmd
    
    colorscheme torte
    
    "the status bar is always displayed
    set laststatus=2
    if has("statusline")
        set statusline=%<%f%h%m%r%=%l,%c\ %P
    elseif has("cmdline_info")
        set ruler " display cursor position
    endif
    
    
    " Specify a directory for plugins
    " - For Neovim: ~/.local/share/nvim/plugged
    " - Avoid using standard Vim directory names like 'plugin'
    call plug#begin('~/.local/share/nvim/plugged')
    
    " for autocompletion
    
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
    " for fuzzy completion
    Plug 'Shougo/denite.nvim'
    Plug 'Shougo/echodoc.vim'
    " to display in red extra whitespaces
    Plug 'ntpeters/vim-better-whitespace'
    
    Plug 'benekastah/neomake'
    
    Plug 'evidens/vim-twig'
    Plug 'phpactor/phpactor', {'for': 'php', 'branch': 'master', 'do': 'composer install --no-dev -o'}
    Plug 'kristijanhusak/deoplete-phpactor'
    
    " Initialize plugin system
    call plug#end()
    
    
    " for language server
    
    " used by deoplete
    call deoplete#custom#option('ignore_sources', {'php': ['omni']})
    
    
    let g:PhpactorRootDirectoryStrategy = {-> '/vagrant' }
    
  10. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    One low-level test (maybe to include in checkhealth in another form):

    :echo printf('the type should be %s, is %s', type(function('type')), type(g:PhpactorRootDirectoryStrategy))
  11. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author

    I got the type should be 2, is 2

  12. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    OK, I reproduced this behaviour on Vim (as opposed to nvim). It seems that calling to RPC behaves with a correctly selected working directory, but we have a bug in status reporting. For test, please display the result of the function directly used for RPC call:

    echo phpactor#getRootDirectory()
  13. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    @dantleech is possible that the directories: this given by --working-dir and this resolved by '%project_root%' can differ?

  14. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    But why would it depend on the caller...

    I echoed (on Vim) the final command used to RPC call and it have the directory chosen by the strategy.

  15. allan-simon commented on Jul 7, 2020

    @allan-simon
    Author
    echo phpactor#getRootDirectory()
    

    ->

    /vagrant
    

    i.e it displays (correctly?) the value defined there

    let g:PhpactorRootDirectoryStrategy = {-> '/vagrant' }
    

    (I've tried changing the value to be 100% sure)

  16. dantleech commented on Jul 7, 2020

    @dantleech
    Collaborator

    is possible that the directories: this given by --working-dir and this resolved by '%project_root%' can differ?

    yes when using the language server (language client has authority), no otherwise.

  17. przepompownia commented on Jul 7, 2020

    @przepompownia
    Contributor

    phpactor#Status() executes phpactor status without --working-dir. The fallback presentation method

    phpactor#rpc("status", {'type': 'formatted'})

    works correctly but usually (no :terminal support) is not reached.

  18. dantleech commented on Jul 7, 2020

    @dantleech
    Collaborator

    ah, yeah, i think we should revert that fix

  19. camilledejoye commented on Nov 1, 2020

    @camilledejoye
    Contributor

    That was fixed since, @allan-simon can you confirm ?
    Otherwise we can close.

  20. allan-simon commented on Nov 15, 2020

    @allan-simon
    Author

    I will double check that .

  21. allan-simon commented on Nov 15, 2020

    @allan-simon
    Author
    Version: 3324205 (12 days ago) Do-not-overwrite-stub_paths-config-if-key-exists-1122
    Filesystems: simple     
    Working directory: /vagrant/src/Command
                          
    Config files (missing is not bad):
                                            
      ✘ /home/vagrant/.config/phpactor/phpactor.json
      ✘ /home/vagrant/.config/phpactor/phpactor.yml
      ✘ /vagrant/src/Command/.phpactor.json           
      ✘ /vagrant/src/Command/.phpactor.yml             
                                                    
    Diagnostics:                                         
                                                     
      ✔ XDebug is disabled. XDebug has a negative effect on performance.
      ✘ Composer not found - some functionality will not be available (e.g. class creation) and class location will fallback to scanning the filesystem if index not enabled - this can be slow. Make sure you've run `
    composer install` in your project!
      ✘ Git not detected. Some operations which would have been better scoped to your project repository will now include vendor paths.
    
       
    [Process exited 0]                
    

    (when I run PhpactorStatus , with or without putting let g:PhpactorRootDirectoryStrategy = {-> '/vagrant' } at the end of my init.vim )

    However phpactor seems to work with Coc.vim as i have autocompletion working

  22. camilledejoye commented on Nov 15, 2020

    @camilledejoye
    Contributor

    OK, I just realized that I forgot to pass the working directory when calling the status command ><
    Will try to fix that soon, but it should also only mean that the Working directory information is invalid in the result of this command.

    However phpactor seems to work with Coc.vim as i have autocompletion working
    The LSP client is responsible for provided the project root, CoC in your case, so it should indeed works without issue in this case.

  23. camilledejoye commented on Nov 15, 2020

    @camilledejoye
    Contributor

    #1127

    I tested locally by starting vim from a sub-directory, the Working directory has the right value.
    Then I realized we didn't used it when looking for possible config files at the root of the project, so I fixed that too.

    But I don't know what else to test, you said that the status was not working properly (and you were right) but I don't think it should prevent phpactor to work with RPC.

    I hope I did it right this time 😄

  24. allan-simon commented on Nov 15, 2020

    @allan-simon
    Author

    ok make sense ^^ , thanks for your hardwork

  25. added 2 commits that reference this issue on Nov 15, 2020
  26. 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