1

I'm using coc-phpls to edit a plugin project inside a bigger project.

i.e. the dir structure is like

/var/www/example/
/var/www/example/libraries/
/var/www/example/plugins/myplugin  ← my working dir.

Because I started in myplugin/ then intelephense only looks for symbols in files within that dir; but I need it to hunt for the top of the project, i.e. /var/www/example.

I'm using local_vimrc which lets me include a .vim file from an ancestor dir. But the intelephense settings are in a json file in ~/.config/nvim/coc-settings.json

How can I set this dynamically?

I'm using neovim 0.5.0.

1
  • 1
    Have you tried using :h :cd/:h :lcd? I don't know if coc respects that but that could be a way to do it. Otherwise you might have more success asking directly in coc's issue tracker
    – statox
    Aug 13, 2021 at 12:31

1 Answer 1

1

Create a .vim/coc-settings.json file in the root of your project, i.e. /var/www/example/.vim/coc-settings.json

In here you can add settings to override the global ones. Enter this:

{
  "coc.preferences.rootPatterns": [
    ".thisIsDocRoot"
  ]
}

This tells CoC to look for a .thisIsDocRoot file to determine a "workspace" dir.

Next touch /var/www/example/.thisIsDocRoot to create a file in the doc root.

Now when you edit a file in /var/www/example/plugins/myplugin CoC will:

  • scan up the tree looking for .vim/coc-settings.json which it will find at the root of your project. It merges that config.
  • that causes it to then look for .thisIsDocRoot, which again it finds in the root of the project.
  • Intelephense now uses this to find symbols.

Note: you might also want to tell it to look in files other than .php ones, e.g. Drupal uses .module and .inc files too. To cover this, my /var/www/example/.vim/coc-settings.json file is:

{
  "coc.preferences.rootPatterns": [
    ".thisIsDocRoot"
  ],
  "intelephense.files.associations": [
    "*.php",
    "*.module",
    "*.inc"
  ],
  "cSpell.userWords": [
    "DRUPAL"
  ]
}

Red herring: Intelephense defines a config item called intelephense.environment.documentRoot. I tried putting a value in this in various coc-settings files to no avail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.