php 为什么 Eclipse 代码完成在某些项目中不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/177569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does Eclipse code completion not work on some projects?
提问by Edward Tanguay
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.
我有带有 PDT 的 Eclipse 3.3.2 进行 PHP 开发。我创建的所有项目,甚至 SVN 项目都有代码完成功能。现在我刚刚打开了另一个 SVN 项目,它没有代码完成或 PHP 模板(CTRL-space 在该项目中什么也不做)。但是,我可以打开其他项目并完成其中的所有工作。
Why would code completion and templates be "off" in just one project and how can I turn it back on?
为什么代码完成和模板仅在一个项目中“关闭”,我该如何重新打开它?
回答by Guido
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:
也许 Eclipse 不明白该项目具有“PHP 性质”。尝试比较两个项目上的 .project 文件以查找差异。它应该包含以下内容:
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
The .project file will be in your workspace under the project directories.
.project 文件将位于项目目录下的工作区中。
回答by Edward Tanguay
Look out for the file .buildpath in your project... put this line between the tag:
在您的项目中查找文件 .buildpath... 将这一行放在标记之间:
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
Save it and restart eclipse. Now everything should be OK... This worked for me. :)
保存并重新启动eclipse。现在一切都应该好了......这对我有用。:)
回答by lagopixel
It is just one line to add in the .project file and then restarting eclipse to get codecompletion: Where it says
只需在 .project 文件中添加一行,然后重新启动 eclipse 即可完成代码完成:它说的地方
---
<natures>
</natures>
---
after the change has to be
更改后必须是
---
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
---
That should do.
那应该做。
回答by lagopixel
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.
问题是,如果您创建一个 SVN 项目,则 .project 是一个没有代码完成参考的基本文件。您必须创建一个基本的 PHP 项目并比较两个文件并替换 SVN 项目中缺失的部分。
Now I have code completion for every file in the project, even for Zend Framework library
现在我对项目中的每个文件都有代码完成,即使是 Zend Framework 库
回答by umpirsky
@Guido PHPNature does not fix this.
@Guido PHPNature 没有解决这个问题。
@Edward Tanguay Yes, that's because when you create new PHP project, eclipse adds .buildpath file with
@Edward Tanguay 是的,那是因为当您创建新的 PHP 项目时,eclipse 添加了 .buildpath 文件
<?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).
当您导入现有项目时,eclipse 不会生成 .buildpath 文件,但您可以手动添加它或使用现有源创建新的 PHP 项目(您可以在向导中选择)。
回答by Joe Scylla
I have the same issue sometimes. For me it works to rebuild the PHP project with "Project" -> "Clean".
我有时也有同样的问题。对我来说,它可以使用“项目”->“清理”重建 PHP 项目。
回答by Ersin DO?AN
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.
- 在项目树中选择“PHP 包含路径”
- 右键单击它,然后单击“构建路径>配置构建路径”
- 在打开的窗口中,添加你要构建的文件夹,这样就可以做代码辅助了。
Thats all :) I hope it resolves your problem, I solved my one :)
就是这样:) 我希望它能解决你的问题,我解决了我的问题 :)
回答by Ersin DO?AN
Right click in the edit screen, goto Java -> Editor -> Content Assist -> Advanced ...select proposals accordingly
在编辑屏幕中右键单击,转到 Java -> Editor -> Content Assist -> Advanced ...相应地选择提案
回答by John
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.
转到“窗口”>“属性”,然后转到“PHP”>“编辑器”>“代码助手”(JAVA 有类似的选项)并设置“启用自动激活”,最好使用您认为合适的延迟(0 毫秒)。如果您被程序突然决定在没有提示的情况下为您做事(并且做错了)而感到困扰,请取消选择“自动插入单个建议”,您应该没问题。
回答by Sietse
Be sure the file opens with the "PHP editor". Right-click the file, and select open withto select the right editor.
确保文件使用“PHP 编辑器”打开。右键单击该文件,然后选择打开方式以选择正确的编辑器。
If it turns out you've been using the wrong editor, you can change the association under Preferences ? General ? Content Types
如果事实证明您使用了错误的编辑器,您可以在Preferences下更改关联?一般的 ?内容类型

