Eclipse PDT + Code completion not working at all

2019-03-31 07:49发布

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

10条回答
Root(大扎)
2楼-- · 2019-03-31 08:34

The standard solution (at Eclipse forum) didn't work for me. What fixed this problem was the following:

  1. going to Properties for my project (right click on it in PHP Explorer, then Properties),
  2. select PHP Build Path/"Add Folder"
  3. 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.

查看更多
smile是对你的礼貌
3楼-- · 2019-03-31 08:36

I think this is the best way:

Right click on you project in the project Explorer » Configure » Add PHP support...

enter image description here

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-03-31 08:44
  1. Download ZF2 and put it to your perefered Location (~Frameworks/ZF2)
  2. Eclipse: Window > Preferences > PHP > Libraries = Push "New"-Button, add a Name
  3. choose added Item and click "Add External Folder"-Button. Choose you ZF2 destination
  4. Be sure, your Project is "PHP Project" (see: Mark Project-Base-Folder, click Project in Menu > Project Natures and choose PHP Project.
  5. This will rebuild your Project, if not also choose Project > build Project.

Now all should work like a charm (on Kepler Service Release 2)

查看更多
成全新的幸福
5楼-- · 2019-03-31 08:45

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!

查看更多
登录 后发表回答