为什么 Eclipse 代码补全在某些项目上不起​​作用?

发布于 2024-07-07 00:52:42 字数 197 浏览 12 评论 0原文

我有 Eclipse 3.3.2 和 PDT 进行 PHP 开发。 我创建的所有项目,甚至 SVN 项目都有代码补全。 现在我刚刚打开另一个 SVN 项目,它没有代码完成或 PHP 模板(CTRL-空格在该项目中不执行任何操作)。 但是,我可以打开其他项目并完成其中的所有工作。

为什么代码补全和模板会在一个项目中“关闭”?如何将其重新打开?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

预谋 2024-07-14 00:52:42

谢谢你!
我花了一整天的时间来弄清楚为什么我没有代码完成...

问题是,如果你创建一个 SVN 项目,.project 是一个没有代码完成参考的基本文件。 您必须创建一个基本的 PHP 项目并比较这两个文件并替换 SVN 项目中缺少的部分。

现在我对项目中的每个文件都有代码补全,甚至是 Zend Framework 库

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

薯片软お妹 2024-07-14 00:52:42

留意项目中的文件 .buildpath...将此行放在标记之间:

保存并重新启动 Eclipse。 现在一切都应该没问题......这对我有用。 :)

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. :)

So要识趣 2024-07-14 00:52:42

也许 Eclipse 不理解该项目具有“PHP 性质”。
尝试比较两个项目的 .project 文件以查找差异。 它应该包含类似以下内容:

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

.project 文件将位于您的工作区中的项目目录下。

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.

微暖i 2024-07-14 00:52:42

只需在 .project 文件中添加一行,然后重新启动 Eclipse 即可完成代码:
的地方

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

更改后所说

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

必须是应该这样做。

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.

记忆で 2024-07-14 00:52:42

@Guido PHPNature 没有解决这个问题。

@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>

当您导入现有项目时,Eclipse不会生成.buildpath文件,但您可以手动添加它或使用现有源创建新的PHP项目(您可以在向导中选择)。

@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).

蓝色星空 2024-07-14 00:52:42

注意

除了已经提到的使整个自动完成帮助工作的解决方案之外,还有另一个怪癖:它可能无法启用。

转到窗口> 属性然后到PHP> 编辑> 代码辅助(JAVA 有类似的选项)并设置“启用自动激活”,最好设置您认为舒适的延迟(0 毫秒)。 如果您对程序突然决定在没有提示的情况下为您做事(并且做错了)感到困扰,请取消选择“自动插入单个提案”,您应该没问题。

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.

分开我的手 2024-07-14 00:52:42

确保使用“PHP 编辑器”打开文件。 右键单击该文件,然后选择打开方式以选择正确的编辑器。

如果发现您使用了错误的编辑器,您可以在首选项 » 常规 » 内容类型下更改关联

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

潦草背影 2024-07-14 00:52:42

在编辑屏幕中右键单击,转到 Java -> 编辑-> 内容辅助 -> 高级...相应地选择建议

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

愚人国度 2024-07-14 00:52:42

我有时也有同样的问题。 对我来说,它可以使用“Project”重建 PHP 项目 -> “干净的”。

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

仙气飘飘 2024-07-14 00:52:42

如果您遇到此问题,请按照下列步骤操作:

  • 在项目树中选择“PHP Include Path”,
  • 右键单击它,然后单击“Build Path>Configure Build Path”
  • 在打开的窗口中,添加您要构建的文件夹,这样就可以了做代码协助。

这就是全部:)我希望它能解决你的问题,我解决了我的问题:)

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 :)

好听的两个字的网名 2024-07-14 00:52:42

我通过启用完整的 C/C++ 索引器(Windows-> 属性 -> C/C++ -> 索引器)解决了这个问题,并且还点击了单选按钮“使用活动按钮配置”。 之后清理并构建全部。

这适用于 Eclipse CDT 3.4

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

臻嫒无言 2024-07-14 00:52:42

我遇到的问题是构建路径为空,因此我尝试编辑的任何文件都没有代码完成。 确保正确设置构建路径,特别是当您从工作区以外的其他位置链接源时。

例如 apache htdocs 文件夹。

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.

红墙和绿瓦 2024-07-14 00:52:42

我注意到有时当你在 Eclipse 中从 svn 签出一个项目时(颠覆性或 subsclipe“签出项目为”),即使你将其签出为 php 项目,它也会删除 .project 文件,或者它将是一个通用的项目。 我发现只需进入该目录并删除 .project .settings/ 和 .cach/

然后创建一个新的 php 项目并指向您签出文件的目录。 你应该有代码完成并且 svn 应该链接到你的存储库。

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.

_蜘蛛 2024-07-14 00:52:42

一种解决方案可能是包含一个需要所有 PHP 类的虚拟 php 文件。 这样 PHP 解析器也能识别这些类。
虚拟文件示例:

if(false) {
     require_once 'class/one.php';
     require_once 'class/two.php';
     require_once 'class/three.php';
}

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';
}
伴随着你 2024-07-14 00:52:42

检查您的项目的库。 您可能包含两个这样的 jar 文件,其中相同的类可用,或者说代码中的一个类可以在两个 jar 文件中引用。 在这种情况下,Eclipse 也会停止协助代码,因为它完全混乱了。

检查这一点的更好方法是转到辅助不起作用的文件并注释那里的所有导入,而不是逐一添加导入并检查每个导入是否代码辅助是否正常工作。您可以轻松找到具有重复引用的类。

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.

幼儿园老大 2024-07-14 00:52:42

我必须在 PHP 资源管理器中右键单击该项目,转到“PHP 构建路径”。 这是空的。 我单击“添加文件夹”,选中项目根文件夹旁边的复选框,然后单击“确定”,然后再次单击“确定”。

之后代码完成似乎可以工作。 如果你问我的话,应该开箱即用,但无论如何。

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.

噩梦成真你也成魔 2024-07-14 00:52:42

如果您来这里寻找 php eclipse 中的代码补全不起作用,请确保您的项目作为 php 项目得到支持。 右键单击项目,然后进入配置-> 添加 php 支持。 如果您的代码辅助设置正确,它应该会立即起作用。 有时,像我这样的新手会调整项目,或者以干净的方式启动项目,而不是像 php 那样启动项目,因此 Eclipse 不知道如何处理该项目。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文