IntelliJ Code Completion not working for new Java

2019-01-18 20:20发布

IntelliJ IDEA 13 has started exhibiting a very weird behavior in my local setup.

Namely, in any new Java class added to an existing project, Code Completion does not work. So, after declaring an object variable of any type in the new class and then typing the name of that variable, followed by the dot (.), no suggestions come up for any of the methods of the corresponding object.

For example, after declaring

File f = new File("/home");

typing f. does not bring up a list of all the methods in the File class, to select one from. As a matter of fact, when typing the dot (.), no suggestions appear and at the bottom left (in the status bar) of the IDE window, the message "Identifier expected. Identifier expected." is displayed. Sometimes, a long list of totally irrelevant methods from irrelevant components or libraries are proposed.

Strangely, Code Completion works as expected if the above declaration happens in any of the existing classes.

This behavior persists after many combinations of machine restart, IDE restart, project re-importing, closing/reopening, or rebuilding.

Any ideas?

14条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-18 20:44

Make sure you mark all your Source directories as such in File -> Project Structure -> Modules.

查看更多
可以哭但决不认输i
3楼-- · 2019-01-18 20:44

Ensure that you are not in Power Save Mode while running IntelliJ (File [menu] -> Power Save Mode checked or not). If Power Save Mode is enabled, IntelliJ will not run background tasks, including code completion.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-18 20:48

There could be 2 reasons for your problem

  1. Either the the source folder is not properly configured in the your build java build path. If the source folder is not properly configured the autocomplete wont get the required class definitions and autocomplete would fail for your project.
  2. Restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'
查看更多
▲ chillily
5楼-- · 2019-01-18 20:49

The only thing that worked for me was killing IntelliJ (on Ubuntu) and starting it again.

查看更多
太酷不给撩
6楼-- · 2019-01-18 20:50

I was facing this issue while coding for eclipse-che client extension. Eclipse che modules are all of maven type. My client extension project was an independent module which can be compiled independent of the parent project. When I imported the same structure to Intellij my client-side extension project was not giving suggestions. After I include the client-extension project to the parent module (adding it to pom.xml) the suggestions started showing up.

查看更多
甜甜的少女心
7楼-- · 2019-01-18 20:52

Remove your package from the Settings>Editor>General>Auto Import>Java>Exclude from Import and Completion

I had run into this problem. None of the solutions from this post worked, but I was able to fix it because I accidentally put my project's package in the "Exclude from Import and Completion" settings.

change your intellij settings to include the package for completion

查看更多
登录 后发表回答