Auto-complete and Code Assist in Eclipse
May 25, 2009
Auto-complete and Code Assist in Eclipse
One of the most annoying issues I have encountered in all my years of using Eclipse as an IDE was with Code Assist and Auto completion , one of greatest features supported by all of Eclipse's flavours allows the automatic completion of code (mainly functions , classes , constants , variables) including valuable information including arguments order and description retrieved from JavaDoc or any other Doc prototype.
For the past two years I have been working on PHP projects using the Eclipse IDE (after a great transition from Notepad :)) , for those of you who don't know its power I recommend either PDT , Zend Studio for Eclipse (mainly for Zend related projects) or the latest version (still in development but the best choice in my opinion) of PDT named Galileo which is available by going to the PDT download page specified above , clicking 'Development Builds' and choosing the PHP flavour.
One of the problems I encountered with working on PHP related projects (mainly) with Eclipse is when I was pulling a project from an SVN repository I had set-up or was set-up for me. Eclipse has a known problem with the Auto complete and Code Assist features with that process. These great features are available only by special specifications in the project settings , these project settings are stored in the '.project' file (generated by Eclipse) present on the project's root folder. When creating a new project on PDT , Eclipse has no problem generating those files with the required settings to allow Auto completion and Code Assist, when pulling from SVN Eclipse fails to create those files properly thus disabling these features on such projects.
Before I propose the fix I would like to explain and allow you to understand what's actually missing in the .project file:
Another great feature Eclipse has is Building and specifically Auto-building.
Most languages having Eclipse flavours (such as Java / C++) have a specific compilation process for generating runnable (or otherwise useable) objects from plain-text sourcecode , these compilation processes can become very specific. Eclipse has a very sophisticated compilation process mechanism enhanced by the Ant builder, this building process can also be automated , allowing Eclipse to Auto-Build your projects allowing it to identify any errors(allowed by a validator in the build process) and by giving you code feedback in the form of Code Assist and Auto Completion. Since many flavours and builders are available for Eclipse it is necessary to specify exactly which builders are required by this specific project.
PHP is different in a way since no actual compilation is taking place but more of a parsing process but this is still dealt with on the building process.
But think about this for a second , is it really efficient for Eclipse to build your entire project everytime you ask it to or an automated request was generated?
Aside from Full project building Eclipse can call on Incremental Builders which build only the parts that were changed since the last build.
*There are more types and more info to be shared on this topic but i'll spare you and direct you to a better source at the end*
Other than specifying builders you can tell Eclipse the 'Nature' of your project. What does Nature mean? It tells Eclipse to associate your project with a specific plugin or feature set, so Eclipse knows what to reference.
Well obviously we need Eclipse to refernce a PHP nature and a PHP Incremental builder.
Now since we now what is missing from our .project file i'll tell you how to fix the problem(I am currently refering only to PHP projects used by PDT)
The easiest solution would be to create a New Project , do not choose the SVN repository or any other source , just a blank project , go to the project workspace folder and notice the .project file , open it with notepad and you'll see how it's built , copy the file to the project you created via SVN(overwrite and files present) , notice you'll have to change the line
where XXXXX is the example's project name , to the name you gave your project retrieved from SVN
you'll say more lines below that , in most cases they should be something like:
* I did not include all lines , just the lines that needs explaning so don't panic some lines are missing*
'PhpIncrementalProjectBuilder', 'validationbuilder' and a 'PHPNature' reference.
Different Eclipse setups generate different results , I have included an example .project file from my set-up which includes a JavaScript Nature reference and validator.
.project Example File
I have found that on some configuration this still fails to help , after checking in your Eclipse options that you have enabled Auto Completion (look for Code Assist in the Preferences Menu and check your settings) you might still not be able to use these features. What might be missing still is a reference to the Build Path. The Build Path simply tells all defined Builders where the files to be built reside, this is pretty obvious for Eclipse in mose cases , in case your'e missing this you can download the following file: .buildpath Example File and put it on the same folder as the .project file(this is a different file named the '.buildpath' file)
That's all for now , I spared a lot of information since this is a huge topic which is covered greatly elsewhere:
One of the most annoying issues I have encountered in all my years of using Eclipse as an IDE was with Code Assist and Auto completion , one of greatest features supported by all of Eclipse's flavours allows the automatic completion of code (mainly functions , classes , constants , variables) including valuable information including arguments order and description retrieved from JavaDoc or any other Doc prototype.
For the past two years I have been working on PHP projects using the Eclipse IDE (after a great transition from Notepad :)) , for those of you who don't know its power I recommend either PDT , Zend Studio for Eclipse (mainly for Zend related projects) or the latest version (still in development but the best choice in my opinion) of PDT named Galileo which is available by going to the PDT download page specified above , clicking 'Development Builds' and choosing the PHP flavour.
One of the problems I encountered with working on PHP related projects (mainly) with Eclipse is when I was pulling a project from an SVN repository I had set-up or was set-up for me. Eclipse has a known problem with the Auto complete and Code Assist features with that process. These great features are available only by special specifications in the project settings , these project settings are stored in the '.project' file (generated by Eclipse) present on the project's root folder. When creating a new project on PDT , Eclipse has no problem generating those files with the required settings to allow Auto completion and Code Assist, when pulling from SVN Eclipse fails to create those files properly thus disabling these features on such projects.
Before I propose the fix I would like to explain and allow you to understand what's actually missing in the .project file:
Another great feature Eclipse has is Building and specifically Auto-building.
Most languages having Eclipse flavours (such as Java / C++) have a specific compilation process for generating runnable (or otherwise useable) objects from plain-text sourcecode , these compilation processes can become very specific. Eclipse has a very sophisticated compilation process mechanism enhanced by the Ant builder, this building process can also be automated , allowing Eclipse to Auto-Build your projects allowing it to identify any errors(allowed by a validator in the build process) and by giving you code feedback in the form of Code Assist and Auto Completion. Since many flavours and builders are available for Eclipse it is necessary to specify exactly which builders are required by this specific project.
PHP is different in a way since no actual compilation is taking place but more of a parsing process but this is still dealt with on the building process.
But think about this for a second , is it really efficient for Eclipse to build your entire project everytime you ask it to or an automated request was generated?
Aside from Full project building Eclipse can call on Incremental Builders which build only the parts that were changed since the last build.
*There are more types and more info to be shared on this topic but i'll spare you and direct you to a better source at the end*
Other than specifying builders you can tell Eclipse the 'Nature' of your project. What does Nature mean? It tells Eclipse to associate your project with a specific plugin or feature set, so Eclipse knows what to reference.
Well obviously we need Eclipse to refernce a PHP nature and a PHP Incremental builder.
Now since we now what is missing from our .project file i'll tell you how to fix the problem(I am currently refering only to PHP projects used by PDT)
The easiest solution would be to create a New Project , do not choose the SVN repository or any other source , just a blank project , go to the project workspace folder and notice the .project file , open it with notepad and you'll see how it's built , copy the file to the project you created via SVN(overwrite and files present) , notice you'll have to change the line
<name>XXXXX</name>just under
<projectDescription>*Do not confuse with <buildCommand>*
where XXXXX is the example's project name , to the name you gave your project retrieved from SVN
you'll say more lines below that , in most cases they should be something like:
* I did not include all lines , just the lines that needs explaning so don't panic some lines are missing*
<buildSpec>If you read my explanation you'll notice a reference to
<buildCommand> <name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name>
<arguments></arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments></arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
'PhpIncrementalProjectBuilder', 'validationbuilder' and a 'PHPNature' reference.
Different Eclipse setups generate different results , I have included an example .project file from my set-up which includes a JavaScript Nature reference and validator.
.project Example File
I have found that on some configuration this still fails to help , after checking in your Eclipse options that you have enabled Auto Completion (look for Code Assist in the Preferences Menu and check your settings) you might still not be able to use these features. What might be missing still is a reference to the Build Path. The Build Path simply tells all defined Builders where the files to be built reside, this is pretty obvious for Eclipse in mose cases , in case your'e missing this you can download the following file: .buildpath Example File and put it on the same folder as the .project file(this is a different file named the '.buildpath' file)
That's all for now , I spared a lot of information since this is a huge topic which is covered greatly elsewhere:
Comments