bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.64k stars 94 forks source link

Allow folders to be included outside of workspace #253

Closed hirasso closed 4 years ago

hirasso commented 6 years ago

Hi there, great work on this plugin!!!

I'm really close to switching from SublimeText to VSCode, the only thing I'm still missing is the ability to tell intelephense to let me go to definitions of libraries outside of my workspace. (e.g. WordPress Core files - My VSCode Workspace is only the theme). Something like files.exclude would be great, just files.include of course ;)

hirasso commented 6 years ago

This is how SublimeCodeIntel is doing it (I can set these settings in the packages user settings):

{
  /*
     Defines a configuration for each language.
  */
  "codeintel_language_settings": {
      "Python3": {
          "python3": "/usr/local/bin/python3.3",
          "codeintel_scan_extra_dir": [
              "/Applications/Sublime Text.app/Contents/MacOS",
              "~/Library/Application Support/Sublime Text 3/Packages/SublimeCodeIntel/arch",
              "~/Library/Application Support/Sublime Text 3/Packages/SublimeCodeIntel/libs"
          ],
          "codeintel_scan_files_in_project": true,
          "codeintel_selected_catalogs": []
      },
      "JavaScript": {
          "codeintel_scan_extra_dir": [],
          "codeintel_scan_exclude_dir":["/build/", "/min/", "/assets/"],
          "codeintel_scan_files_in_project": true,
          "codeintel_max_recursive_dir_depth": 2,
          "codeintel_selected_catalogs": ["jQuery"]
      },
      "PHP": {
          "php": "/Applications/MAMP/bin/php/php5.5.3/bin/php",
          "codeintel_scan_extra_dir": [
            "/Applications/MAMP/bin/php/php7.2.1/bin/php",
            "/Users/username/php-libraries",
          ],
          "codeintel_scan_files_in_project": true,
          "codeintel_max_recursive_dir_depth": 15,
          "codeintel_scan_exclude_dir":["/Applications/MAMP/bin/php/php5.5.3/"]
      }
  }
}

The setting codeintel_scan_extra_dir under PHP lets me tell it where to look for my global php libraries.

bmewburn commented 6 years ago

You can add folders to the workspace with File -> Add folder to workspace to index additional files as needed.

hirasso commented 6 years ago

@bmewburn Thanks for the hint – I would really like, if I wouldn't need to set up a VSCode workspace for every project, though. That's why a global setting would be such a great solution.

Ciantic commented 4 years ago

This would be especially useful in a lot of spaghetti code I have. E.g. with WordPress it's common to have some plugins, and creating workspace individually for all themes is a bit cumbersome. I would like to globally include a few directories so that I get autocomplete and error checking working when ever I open any PHP directory.

Btw, if stubs can be replaced with real thing it also helps. Because I actually like checking e.g. WordPress source code, so I could just include WordPress source code as an inclusion instead of stubs so I can go-to definition on any project.

KapitanOczywisty commented 4 years ago

Currently It's possible to hack this using intelephense.stubs settings (#907), by adding path to additional folder "/path/to/folder/" or "C:/path/to/folder/". (forward slashes only) This will show error in settings, but works. Stubs are scanned for .php files - only these will be included, and AFIK you cannot exclude or filter anything there. And finally any changes in these files are applied only on change of this setting.

Ciantic commented 4 years ago

@KapitanOczywisty apparently it allows any php files (I thought it was for just stubs). Thanks for the tip!

This is still better than nothing, but does not allow to jump definitions.

KapitanOczywisty commented 4 years ago

This is still better than nothing, but does not allow to jump definitions.

For example JS allows jumping to definitions from "DefinitelyTyped", IMO intelephense may also do that. Test code: let jQuery = require('jquery'); in javascript file and Go To Type Definition

nateplusplus commented 4 years ago

@KapitanOczywisty I've used this setting when working on a WordPress plugin, as you've suggested, to include PHP functions from directories two-levels outside my current workspace. However, for some reason now intelephense does not recognize some core PHP functions such as printf, extract, count, str_replace, array_push and several more.

Seems like some functions are fine but a handful are missing. Any idea what may be causing this or how to work around it?

Thank you again for your advice!

KapitanOczywisty commented 4 years ago

Try F1 -> Intelephense: Index workspace.

nateplusplus commented 4 years ago

Thanks @KapitanOczywisty. Sadly this did not seem to have any effect.

bmewburn commented 4 years ago

You can now use the intelephense.environment.includePaths setting to add files from outside the workspace.

Ciantic commented 4 years ago

Great, I tested that. However I still can't jump to definitions when I use intelephense.environment.includePaths. Especially with WordPress I often want to read what's in the function. Or if I use difficult libraries, I'd like to jump to definition of those too.

hirasso commented 4 years ago

Should setting relative paths in the .code-workspace still work with the newest Update v1.5.2? I just updated and it seems to be broken now. This is what used to work until now:

{
    "folders": [
        {
            "path": "."
        },
        {
            "path": "../../../core"
        },
        {
          "path": "../../plugins/advanced-custom-fields-pro"
        },
        {
          "path": "../../plugins/wordpress-seo"
        }
    ],
    "settings": {}
}

It's a WordPress theme inside a custom folder structure:

├── content
│  ├── plugins
│  ├── themes
│  │  ├── my-theme (where my .code-workspace is)
├── core
│  ├── index.php
│  ├── license.txt
│  ├── readme.html
│  ├── wp-activate.php
│  ├── wp-admin
│  ├── wp-blog-header.php
│  ├── wp-comments-post.php
│  ├── wp-config-sample.php
│  ├── wp-cron.php
│  ├── wp-includes
│  ├── wp-links-opml.php
│  ├── wp-load.php
│  ├── wp-login.php
│  ├── wp-mail.php
│  ├── wp-settings.php
│  ├── wp-signup.php
│  ├── wp-trackback.php
│  └── xmlrpc.php
├── index.php

WordPress and Plugin function calls are not being found anymore:

image get_term_by(), get_term() and is_wp_error() should be discoverable, since they can be found inside the core folder.

Sherbieny commented 4 years ago

I wanted to add this in case someone is facing the same issue with Magento 2 platform. I always add the magento core files with "Add folder to workspace" along with my current working module in the same workspace. I have the premium version of intelephense.

I could not get the core folder to get indexed at all, no matter how I run reindex, remove folder, add it again ...

After reading this issue discussion, I tried adding using intelephense.environment.includePaths and added the absolute path of the "magento" core folder .. and now it seems it work, intelephense has been indexing for the past 10 minutes :D

magento core tree is something like this - I copied just a small bit - its huge

┣ module-quote ┃ ┣ Api ┃ ┃ ┣ Data ┃ ┃ ┃ ┣ AddressAdditionalDataInterface.php ┃ ┃ ┃ ┣ AddressInterface.php ┃ ┃ ┃ ┣ CartInterface.php ┃ ┃ ┃ ┣ CartItemInterface.php ┃ ┃ ┃ ┣ CartSearchResultsInterface.php ┃ ┃ ┃ ┣ CurrencyInterface.php ┃ ┃ ┃ ┣ EstimateAddressInterface.php ┃ ┃ ┃ ┣ PaymentInterface.php ┃ ┃ ┃ ┣ PaymentMethodInterface.php ┃ ┃ ┃ ┣ ProductOptionInterface.php ┃ ┃ ┃ ┣ ShippingAssignmentInterface.php ┃ ┃ ┃ ┣ ShippingInterface.php ┃ ┃ ┃ ┣ ShippingMethodInterface.php ┃ ┃ ┃ ┣ TotalSegmentInterface.php ┃ ┃ ┃ ┣ TotalsAdditionalDataInterface.php ┃ ┃ ┃ ┣ TotalsInterface.php ┃ ┃ ┃ ┗ TotalsItemInterface.php ┃ ┃ ┣ BillingAddressManagementInterface.php ┃ ┃ ┣ CartItemRepositoryInterface.php ┃ ┃ ┣ CartManagementInterface.php ┃ ┃ ┣ CartRepositoryInterface.php ┃ ┃ ┣ CartTotalManagementInterface.php ┃ ┃ ┣ CartTotalRepositoryInterface.php ┃ ┃ ┣ ChangeQuoteControlInterface.php ┃ ┃ ┣ CouponManagementInterface.php ┃ ┃ ┣ GuestBillingAddressManagementInterface.php ┃ ┃ ┣ GuestCartItemRepositoryInterface.php ┃ ┃ ┣ GuestCartManagementInterface.php ┃ ┃ ┣ GuestCartRepositoryInterface.php ┃ ┃ ┣ GuestCartTotalManagementInterface.php ┃ ┃ ┣ GuestCartTotalRepositoryInterface.php ┃ ┃ ┣ GuestCouponManagementInterface.php ┃ ┃ ┣ GuestPaymentMethodManagementInterface.php ┃ ┃ ┣ GuestShipmentEstimationInterface.php ┃ ┃ ┣ GuestShippingMethodManagementInterface.php ┃ ┃ ┣ PaymentMethodManagementInterface.php ┃ ┃ ┣ ShipmentEstimationInterface.php ┃ ┃ ┗ ShippingMethodManagementInterface.php ┃ ┣ Model ┃ ┃ ┣ Cart ┃ ┃ ┃ ┣ Totals ┃ ┃ ┃ ┃ ┣ Item.php ┃ ┃ ┃ ┃ ┗ ItemConverter.php ┃ ┃ ┃ ┣ CartTotalManagement.php ┃ ┃ ┃ ┣ CartTotalRepository.php ┃ ┃ ┃ ┣ Currency.php ┃ ┃ ┃ ┣ ShippingMethod.php ┃ ┃ ┃ ┣ ShippingMethodConverter.php ┃ ┃ ┃ ┣ TotalSegment.php ┃ ┃ ┃ ┣ Totals.php ┃ ┃ ┃ ┣ TotalsAdditionalData.php ┃ ┃ ┃ ┣ TotalsAdditionalDataProcessor.php ┃ ┃ ┃ ┗ TotalsConverter.php ┃ ┃ ┣ GuestCart ┃ ┃ ┃ ┣ GuestBillingAddressManagement.php ┃ ┃ ┃ ┣ GuestCartItemRepository.php ┃ ┃ ┃ ┣ GuestCartManagement.php ┃ ┃ ┃ ┣ GuestCartRepository.php ┃ ┃ ┃ ┣ GuestCartTotalManagement.php ┃ ┃ ┃ ┣ GuestCartTotalRepository.php ┃ ┃ ┃ ┣ GuestCouponManagement.php ┃ ┃ ┃ ┣ GuestPaymentMethodManagement.php ┃ ┃ ┃ ┣ GuestShippingAddressManagement.php ┃ ┃ ┃ ┣ GuestShippingAddressManagementInterface.php ┃ ┃ ┃ ┣ GuestShippingMethodManagement.php ┃ ┃ ┃ ┗ GuestShippingMethodManagementInterface.php ┃ ┃ ┣ GuestCartManagement ┃ ┃ ┃ ┗ Plugin ┃ ┃ ┃ ┃ ┗ Authorization.php ┃ ┃ ┣ Product

rwols commented 3 years ago

You could also consider parsing /etc/php/X.Y/cli/php.ini for include_paths.