Why does Eclipse code completion not work on some projects?
Asked Answered
C

17

24

I have Eclipse 3.3.2 with PDT doing PHP development. All projects that I create, even SVN projects have code completion. Now I just opened another SVN project and it has no code completion or PHP templates (CTRL-space does nothing in that project). However, I can open the other projects and code completion all work in them.

Why would code completion and templates be "off" in just one project and how can I turn it back on?

Contrabandist answered 7/10, 2008 at 8:18 Comment(0)
N
43

Maybe Eclipse doesn't understand the project has a "PHP nature". Try comparing the .project file on both projects to look for differences. It should contain something like:

 <natures>
  <nature>org.eclipse.php.core.PHPNature</nature>
 </natures>

The .project file will be in your workspace under the project directories.

Natiha answered 7/10, 2008 at 8:29 Comment(2)
Because the repository had a .project file in it, it did not give me the chance to open it with the PHP project wizard, we deleted the .project file, rechecked it out and all is fine now, thanks!Contrabandist
This still does not show the autocomplete for PHP built-in functions.Paean
J
6

Look out for the file .buildpath in your project... put this line between the tag:

<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>

Save it and restart eclipse. Now everything should be OK... This worked for me. :)

Judaize answered 22/5, 2009 at 11:5 Comment(1)
This, with the .project change, is the missing part to make Eclipse properly display the autocomplete functionality of both built-in functions and project's stuff.Paean
T
5

Thank you! I spent all day long to figure out why I did not have code completion...

The problem is that if you create a SVN project the .project is a basic file without codecompletion reference. You have to create a basic PHP project and compare the two files and replacing the missing part in the SVN project one.

Now I have code completion for every file in the project, even for Zend Framework library

Tishatishri answered 16/10, 2008 at 16:0 Comment(0)
A
5

It is just one line to add in the .project file and then restarting eclipse to get codecompletion: Where it says

---
 <natures>
 </natures>
---

after the change has to be

---
 <natures>
  <nature>org.eclipse.php.core.PHPNature</nature>
 </natures>
---

That should do.

Asexual answered 20/1, 2010 at 9:15 Comment(1)
Yes, it works. Natures can be changed from context menu -> Properties -> Project Propperties -> select PHP and click OKRossuck
T
4

@Guido PHPNature does not fix this.

@Edward Tanguay Yes, that's because when you create new PHP project, eclipse adds .buildpath file with

<?xml version="1.0" encoding="UTF-8"?><buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/></buildpath>

when you import existing project you eclipse does not generates .buildpath file, but you can add it by hand or create new PHP project with existin source (you can choose in wizard).

Thunderhead answered 18/3, 2011 at 9:17 Comment(2)
I've been just dealing with this problem (code completion for my classes but not PHP core) for almost a year now, and I finally broke down and fixed it, thanks to your tip about .buildpath - thanks!Cabalist
Just a note since I'm using a newer version of Eclipse: Going under project properties and checking the PHP nature box fixed it for me. It was set to Web (primary) and js natures by default. I'm using Aptana Studio plugin and Eclipse Version: 4.0.0.201206120848Azelea
L
3

I have the same issue sometimes. For me it works to rebuild the PHP project with "Project" -> "Clean".

Levania answered 7/10, 2008 at 11:12 Comment(0)
C
2

If you have this problem, follow these steps :

  • Select "PHP Include Path" in your project tree
  • Right click on it then click "Build Path>Configure Build Path"
  • On the opening window,add folder that you want to build, so it can do code assist.

Thats all :) I hope it resolves your problem, I solved my one :)

Cloudcapped answered 7/11, 2010 at 17:27 Comment(1)
it works for the eclipse project ,but when i open individual php files of using eclipse ,code completion does not work ,how to make itForras
S
1

Be sure the file opens with the "PHP editor". Right-click the file, and select open with to select the right editor.

If it turns out you've been using the wrong editor, you can change the association under Preferences » General » Content Types

Slaw answered 7/10, 2008 at 8:54 Comment(0)
M
1

Right click in the edit screen, goto Java -> Editor -> Content Assist -> Advanced ...select proposals accordingly

Merthiolate answered 11/3, 2009 at 19:35 Comment(0)
S
1

ATTENTION

Besides the already mentioned solutions to get the whole autocomplete help to work, there is another quirk: it might not be enabled.

Go to Window > Properties and then to PHP > Editor > Code Assist (JAVA has a similar option) and set "Enable auto activation", preferably with a delay that you see comfortable (0ms). If you are bothered by the program suddenly deciding to do things for you without prompt (and doing it wrong), deselect "Insert single proposals automatically" and you should be fine.

Serology answered 16/8, 2010 at 13:21 Comment(0)
B
0

I've noticed sometimes when you checkout a project from svn in eclipse (subversive or subsclipe "checkout a project as") and even though you check it out as a php project it will either delete the .project file or it would be a generic project. I've found to just go in that directory and delete the .project .settings/ and .cach/

Then create a new php project and point the directory where you checked out the files. And you should have code completion and svn should be link to your repo.

Burdensome answered 7/10, 2008 at 14:36 Comment(0)
D
0

I had a problem that build path was empty, so no code completion for any of the files i tried to edit. Make sure you setup properly your build path, especially if you're linking the source from some other location than the workspace.

Like the apache htdocs folder for example.

Daffi answered 28/11, 2008 at 22:13 Comment(0)
C
0

I have solved this by enabling the Full C/C++ indexer (Windows-> properties -> C/C++ -> Indexer), and also hit the radio button "Use active button configuration". After that Clean, and Build all.

That worked on Eclipse CDT 3.4

Composed answered 11/12, 2009 at 18:7 Comment(0)
P
0

If you came here looking for code completion in php eclipse not working, make sure your project is being supported as a php project. Right click on the project and then go to configure -> Add php support. If you have the right settings for code assist it should work instantaneously. Sometimes newbies as me tweak around with the projects or start projects as clean and not as php so eclipse doesn't know how to treat the project.

Prohibitionist answered 3/3, 2010 at 19:21 Comment(0)
B
0

I had to right click the project in the PHP Explorer, go to "PHP Build Path". This was empty. I clicked "Add Folder", selected the checkbox next to the root folder of my project and clicked "OK", then "OK" again.

After that code completion seemed to work. Should just work out of the box if you ask me, but whatever.

Boldt answered 22/2, 2011 at 10:33 Comment(0)
R
0

Check the lib of your project. It may be that you have include two such jar files in which same class is available or say one class in code can be refrenced in two jar files. In such case also eclipse stops assisting code as it is totally confused.

Better way to check this is go to the file where assist is not working and comment all imports there, than add imports one by one and check at each import if code-assist is working or not.You can easily find the class with duplicate refrences.

Reenareenforce answered 27/4, 2011 at 11:52 Comment(0)
M
-1

One solution could be to include a dummy php file wich requires all your PHP classes. So that the PHP parser recognizes these classes too. Example dummy file:

if(false) {
     require_once 'class/one.php';
     require_once 'class/two.php';
     require_once 'class/three.php';
}
Mouseear answered 7/10, 2008 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.