I'm switching from PhpStorm to VSCode for my PHP development and I have a problem: For my multi-root workspace, it only detects the classes from the current repository, not all the other repos and libraries from my project. For example, when trying to autocomplete a class, Go to Definition, etc.
I'm developing a TYPO3 project, using composer. Therefore, the structure of the nested projects is this one:
path-to-html/
path-to-html/public/typo3conf/ext/{extension1, extension2, etc.}
I've installed the VSCode PHP Intelephense extension and configured it according to its description. But, as I've said, I only get completion for symbols of the current repository, not of all the libraries of the TYPO3 project. How should I configure this?
I've read all the Intelephense options and I've tried setting these ones:
"settings": {
...
"intelephense.environment.documentRoot": "/path-to-html",
"intelephense.environment.includePaths": [
"/path-to-html/public/typo3conf/ext/extension_1",
...
]
}
But it still doesn't work.
Disclaimer: I also have "PHP Intellisense" installed. The context menu items such as "Go to Defintion" or "Go to declaration" etc only work correctly, when I use enable both extension. Maybe it has to do with the fact that "PHP Intellisense" also uses the Language Server Protocol, but the implementation of the LSP is provided by "PHP Intelephense". Admittedly I don't understand it fully, .
In any case, these "PHP Intelephense settings" work for me.
I am using these settings right now for a local TYPO3 CMS 10 version, ddev-based.
I'll provide it here as a screenshot because these are VSCode Workspace Settings, and I cannot fgure out where VSCode stores these. (They are not stored in the $HOME/.config/Code/Usersettings.json file).
I think I could have used $HOME/ddev/typo3-10/public/typo3/sysext/ instead of $HOME/ddev/typo3-10/public/typo3/. Havent't tries
Key is,
Intelephense needed a few minutes to pick up the settings after changing them. It does not happen instantly that the red wiggly lines disappear
Needless to say, "Go to Definition" (opens a Doc-preview Window), "Go to Declaration" (Opens the PHP Class File), etc, are only enabled for Intelephense Premium.
No need to install, while it is supposed to be there and the html is useless.
The config needs to include the sources; eg.:
"intelephense.environment.includePaths": [
"../../typo3_src/typo3_src-8.7.44"
]
Also see: https://github.com/bmewburn/vscode-intelephense/issues
I just quit VS Code and re-open it. VS Code will open in the exact state it was in on quit. And Intelephense will have scanned the vendor folder. No need for any config changes.
Related
I need to debug a drush command in a ddev project, but I don't know how to do it. In ddev v0.18.0, the PhpStorm debugger breaks at the beginning, but it can't find the associated code.
Updated 2020-12-28: This answer is obsolete since ddev already sets the PHP_IDE_CONFIG environment for you in recent versions. In general, if you've done any debugging already (which creates the .ddev.site "server"/mapping) then things should just work. Some people also prefer to use vendor/bin/drush as that skips the use of /usr/local/bin/drush, which is Drush launcher.
------- Original Answer -------
PHPStorm provides a very nice way to do this, and ddev makes it super easy with the automatic debugging setup.
This technique works best for a Drupal 8 site with drush vendored in, like you get with drupal-composer setups. It assumes that drush is vendored into vendor/drush/drush.
This PHPStorm blog post explains the technique.
Create a server in PHPStorm (Project settings->Servers). My "server" name is d8composer. It doesn't matter what you call it, you just need to use it later.
In the PHPStorm server configuration, map your host project directory to /var/www/html:
Click the "Listen for Debug Connections" button.
Click a breakpoint at a place you know should be hit by your drush command.
Inside the container (ddev ssh), export PHP_IDE_CONFIG="serverName=d8composer" - Yours will be named something other than d8composer of course.
Inside the container /var/www/html/vendor/drush/drush/drush uli (or whatever command you want). PHPStorm will break at your breakpoint. (Of course you could execute that command many ways, but the point is you need to execute the version of drush that's vendored into the repo.
On earlier versions of drupal you can actually just put a copy of drush into your repo temporarily to solve the mapping problem in the same way.
Note that Matt Glaman also wrote a blog post on Xdebug Over the Command Line with DDEV
Also check PHPStorm and uncheck “Ignore external connections through unregistered server configurations."
After many comes and goes I managed to install the MongoDB Driver for PHP 5.6 and made it work on OSX El Capitan. (The way it worked was using Homebrew)
To start working on a project I created the folder for the project and using Composer installed the required packages I needed. Between theese packages I required mongodb/mongodb which is the recomended mongo php library to use by the php Manual on line and in the driver github page.
The problem I found is that Eclipse is resolving the classes in the \MongoDB\ namespace but not in the \MongoDB\BSON\ namespace. If I check what Composer installed in the vendor folder I am able to see that the \MongoDB\BSON\ classes in fact are missing. On the other hand if I run the program in the PHP included webserver, it executes as expected.
So my question is how can do or what am I missing for Eclipse to find the missing classes. Are they defined somewhere else?
If this is not possible because they are compiled into a binary library and I have no way to resolve them, Is there any way to have Eclipse not showing these particular classes as mistakes?
Example of class that runs ok in the webserver, but is highlighted as an error in Eclipse:
$fecha_creacion = new MongoDB\BSON\UTCDateTime();
Reading this post and not finding anything newer on the subject I arrived to the conclusion that developers of the driver don't provide the php sources and leave it to the IDE developers to provide STUBs for the different fuctions of the driver in a way the IDE can recognize the functions and provide syntax checking and documentations popups.
Following this question, I finally ended up finding a JetBrains GitHub where there are many different stubs for PHPStrom, this one among them.
So I copied the file and added it to my project as part of the sources. And that solved my problem.
I've followed these steps to get PHPUnit working in NetBeans in windows:
Download PHPUnit.phar and save to c:\phpbin
Follow instructions under the Windows heading here
Set up PATH variables and NetBeans global/project settings
Everything's working, except I don't have code completion working for PHPUnit. For example, if I type:
$this->asser
I would expect it to show a list of the various assert statements. But it doesn't.
I tried following this guide to get it working, but I don't know where the PHPUnit source files are, so I cannot add it to NetBean's PHP Global Include Path as per the instructions.
Where are the source files? Or is there another way for autocompletion to be correctly configured?
Thanks
You should have the PHP Windows installation. When I last did this using PEAR (which is deprecated) PHPUnit was installed under the root of the PHP web server. I would bet that PHAR puts it in the same place.
Once that is done, you typically have to set up a bootstrap that tells Netbeans where to look for executables, directories and such. Oddly enough the Netbeans tutorial doesn't mention that you have to extend the PHPUnit class for your test. That should give you the autocomplete you seek.
class ClassTest extends PHPUnit_Framework_TestCase {
}
I've just imported a largish php project into NetBeans. Under the top directory I have "app1", "app2", "app3", etc. (each of which are mapped to a domain name), then a "shared" directory for (you guessed it) files used by all the apps.
In app1/route/Search.inc it has:
include_once "../shared/lib/search.inc";
But ctrl-B on this line does nothing. Makes sense, from NetBeans point of view of this as one large application, it should be "../../shared/lib/search.inc". But, for the way the apps are configured, the above is correct, and NetBeans is wrong.
How do I tell NetBeans it needs to go one extra directory up?
Under Include Path, I tried adding "/full/path/to/app1" (so then "../shared/lib/" would be found) (I tried Private tab, then Shared tab, with same results.) But it rejects that, telling me the app1 directory is already part of the application. There is no "Do what I say, and don't think about it, slap!" button.
Adding symbolic links in the file system, just for NetBeans, feels a bit ugly.
I'm wondering if I should make one NetBeans project per app? (I actually tried that first, but as all apps are in the same git repository it gave a lot of noise, so I assumed that was the wrong way.)
ADDITIONAL: I'm most interested in the answer to my last question - is it standard practice to keep each app as a separate NetBeans project, even if they are all in the same git repository?
Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Updates: NetBeans IDE is updated to version NetBeans 8.0.2 Patch 1
Java: 1.7.0_79; OpenJDK 64-Bit Server VM 24.79-b02
Runtime: OpenJDK Runtime Environment 1.7.0_79-b14
(on linux Mint 17)
Make shure that all files of your project are in the project's include path (righ click project -> properties -> include path). Usually there is only the "global include path", which you configure in the NetBeans settings (e.g. to point to your PEAR directory). Add all directories which contain source code you want auto completion for to this include path. Hint: This include path has nothing to do with the include_path used in PHP itself.
I'm wondering if I should make one NetBeans project per app? (I actually tried that first, but as all apps are in the same git repository it gave a lot of noise, so I assumed that was the wrong way.)
Yes you should have different NetBeans projects if your apps are separate, and since they are on different domains, it sounds like they are pretty distinct.
One way you can reduce the noise level of this approach is to right click the other app directories and find the option to Mark directory as > excluded and it should disappear (and the files won't be indexed for autocomplete / search / etc).
I have no problems with such a scenario, if I only select the filename. Then NetBeans search for a file with this name in the whole project directory.
If I select the filename and the path, it does not work. Maybe that is your problem?
I have changed nothing else and it works like a charm.
there is a alternative way to set path i.e. via php.ini
add the following line in php.ini set path of
include_path = ".:c:\xampp\htdocs\project_name\your_include_folder_name"
restart the apache server
I wanted to start a new Zend project, and currently I'm facing some issues regarding Eclipse PDT... My problem is, that the code completion in Eclipse for PHP does not work at all.
I tried a lot of different tutorials etc, for example making a new project and import the files; making a new workspace and import projects there; almost every possible combination of buildpath settings and library imports; deleting several files in .metadata (you will find lots of tutorials like this if you google for it), but nothing worked.
[Edit] Also the PHPNature is set (thanks to tranisstor):
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
(It also does not work if there is only the PHPNature set, and no other in addition)
[/Edit]
The problem in detail: I made a new Zend project, and tried to start coding in the IndexController.indexAction(). First thing I did: I typed in $this->, but no code completion came... I thought maybe I would need to add the Zend library, which I did. When I click into the Zend_Controller_Action in class IndexController extends Zend_Controller_Action I can see the documentation of Zend_Controller_Action, I also can press F3 and the corrosponding file will appear... Which means, Zend is successfully added as library.
I also tried Ctrl + Space, but just nothing happens. By the way, the standard PHP functions like isset() also won't show up in code completion
Does anybody have a idea how to fix this? I am using Eclipse Juno, with Eclipse PDT 3, and Zend Framework 1.x (don't know exactly, but it's not ZF2 and it works well if I open http://localhost.
I'm grateful for any help
I had the same problem when upgrading eclipse to Kepler. The following worked for me:
Remove files under workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2
The reason was that the workspace old DLTK index is not compliant with the new version and needs to be rebuilt. Start eclipse and the DLTK index will be regenerated.
Code completion worked for me again after that.
i feel you, i had to deal with this quite often too, and the mentioned .project file modifications didn't do the trick.
What helped me was this:
edit the .buildpath file and add
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
My complete build file might then look sth. like this:
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>
i also added my folder which contains the php files to the build and include path (RMB over the project), but i don't think that it was necessary, the most important part was the modification of the .buildpath file for me.
Hope that helps...
The standard solution (at Eclipse forum) didn't work for me. What fixed this problem was the following:
going to Properties for my project (right click on it in PHP Explorer, then Properties),
select PHP Build Path/"Add Folder"
in there I ticked/selected my project's main folder.
It took a while while the DLTK database was refreshed (it could block your machine for a couple of minutes, be patient) but then it started working great.
Remove workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/*. It should works.
Hope it helps!
I think this is the best way:
Right click on you project in the project Explorer » Configure » Add PHP support...
Maybe you need to edit your .project-File and add a "PHP nature" tag. See this thread for more information. I once had this issue after putting a project under svn version control and it seems to be a common problem.
I've found a sollution on eclipse forum. Downgrading to PDT 3.1.2 solved the problem.
Regards,
Marek
I had a similar issue, but involving just one PHP file. Then I found that I was using the following syntax for the initialization of a variable inside a method:
$rule = ($fullValidation)?(new StartTimeRule()):(new NullRule());
The problem seems to be the use of the inline condition. The code was working but apparently broke some Eclipse features, like the F3 command, autocompletion, the outline view, etc. I could be wrong, but I think this is a bug of the DTLK indexer.
I changed that line with a standard if statement, not an inline condition, and all the features now work again.
Hope this can help!
After trying the other possible solutions on this page, I managed to get code completion to work in PDT 3.2 with the latest Dynamic Languages Toolkit in Eclipse Juno.
Juno usually installs DLTK version 4.0 by default so I downloaded DLTK 5.0 from here: http://download.eclipse.org/technology/dltk/downloads/drops/R5.0/R-5.0-201306060709/. Use the Core Frameworks > EMF > Runtime Version link, which downloads a zip file so you will need to do a local install:
In Eclipse select Help > Install New Software > Add > Archive > navigate to the zip file > type DLTK in the Name box and confirm.
Use Eclipse's Install new software to get PDT 3.2 from the PDT repository, if it is not already installed: http://download.eclipse.org/tools/pdt/updates/3.2/release
Option 2: Before I tried the previous method I installed PDT 3.1, which I got from the Juno update site (instead of the PDT repository):
Install New Software > http://download.eclipse.org/releases/juno. Code completion worked in 3.1, so it's another possibility.
Download ZF2 and put it to your perefered Location (~Frameworks/ZF2)
Eclipse: Window > Preferences > PHP > Libraries = Push "New"-Button, add a Name
choose added Item and click "Add External Folder"-Button. Choose you ZF2 destination
Be sure, your Project is "PHP Project" (see: Mark Project-Base-Folder, click Project in Menu > Project Natures and choose PHP Project.
This will rebuild your Project, if not also choose Project > build Project.
Now all should work like a charm (on Kepler Service Release 2)