简体   繁体   English

如何修复IntelliJ IDEA方法参数自动完成?

[英]How to fix IntelliJ IDEA method parameter auto-completion?

I am using IntelliJ IDEA 15, and I noticed that (by default) Eclipse offers a much more convenient auto-completion, when it comes to writing method calls, which require multiple parameters. 我正在使用IntelliJ IDEA 15,我注意到(默认情况下)Eclipse提供了更方便的自动完成功能,当涉及到编写需要多个参数的方法调用时。

Eclipse automatically fills in default parameters and allows you to quickly navigate through them by pressing Tab : Eclipse会自动填充默认参数,并允许您通过按Tab键快速浏览它们

在此输入图像描述

However, IntelliJ IDEA does not handle it as conveniently and makes you write them manually: 但是,IntelliJ IDEA不能方便地处理它并让您手动编写它们:

在此输入图像描述

Is there a way to make IntelliJ IDEA, handle method call auto-completion in a similar way to Eclipse's, and pre-write all the parameters for you, having you just press Tab (or another key) to navigate through them? 有没有办法制作IntelliJ IDEA,以类似于Eclipse的方式处理方法调用自动完成,并为您预先写好所有参数,只需按Tab (或其他键)来浏览它们? If it is not possible in original IntelliJ, is there an add-on/plugin/external tool that will improve the intelligent code completion in such cases? 如果在原始的IntelliJ中不可能,是否有一个附加/插件/外部工具可以在这种情况下改善智能代码的完成?


Note: I am not being lazy, it just gets quite annoying, having to manually complete each parameter and put a comma after each one, when code completion should do it for you. 注意:我不是很懒,它只是非常烦人,必须手动完成每个参数并在每个参数后面加一个逗号,代码完成时应该为你完成。

IntelliJ doesn't do it and AFAIK there isn't a plugin for it. IntelliJ没有这样做,而AFAIK没有它的插件。
There is no solution for you (unless you built a plugin yourself, but then you'd just have another job to maintain that plugin) 你没有解决方案(除非你自己构建了一个插件,但是你只需要另一个工作来维护该插件)

The alternative is to break the habit/need for it and use IntelliJ's Code Completion shortcuts: 另一种方法是打破习惯/需求并使用IntelliJ的代码完成快捷方式:

  • Ctrl + P to view possible parameters for function. 按Ctrl + P查看功能的可能参数。
  • Ctrl + Shift + Space to list the possible variables that could be entered as a parameter in the respective parameter position (based on type). Ctrl + Shift + Space列出可在相应参数位置(基于类型)作为参数输入的可能变量。
    This also enters a comma if another parameter is required for the function. 如果函数需要另一个参数,这也会输入逗号。

Hardcoding numbers/strings as parameters to a custom function wouldn't be advisable as that negates the point of the parameters. 硬编码数字/字符串作为自定义函数的参数是不可取的,因为这会否定参数的要点。 It's better practice and more common to pass in a pre-defined variable; 传递预定义变量是更好的做法,也更常见; At which point Ctrl + Shift + Space is the easiest way for Code Completion. 此时Ctrl + Shift + Space是代码完成的最简单方法。
This would also prevent you from closing quotations and adding commas. 这也会阻止您关闭引号并添加逗号。

Also note: IntelliSense is Microsoft's Intelligent Code Completion implementation which neither IntelliJ nor Eclipse uses. 另请注意:IntelliSense是Microsoft的智能代码完成实现,IntelliJ和Eclipse都不使用它。


As frant.hartm states in their answer: 正如frant.hartm在答案中所述:

Unfortunately the view of Intellij developers is that this feature would be too error prone. 不幸的是,Intellij开发人员认为这个功能太容易出错。 See this issue on youtrack . 在youtrack上查看此问题

They even state that people are welcome to make a plugin that does this. 他们甚至表示欢迎人们制作插件来做到这一点。

The closest thing to this AFAIK is "method parameter completion", which allows you to auto complete parameters of current method as parameters of the inner method call at once (works for methods and constructors when calling super()). 与此AFAIK最接近的是“方法参数完成”,它允许您立即自动完成当前方法的参数作为内部方法调用的参数(在调用super()时适用于方法和构造函数)。

方法参数完成

Unfortunately the view of Intellij developers is that this feature would be too error prone. 不幸的是,Intellij开发人员认为这个功能太容易出错。 See this issue on youtrack . 在youtrack上查看此问题

IDEA doesn't fill the arguments automatically. IDEA不会自动填充参数。 You can use Ctrl+Shift+Space for auto-completion (completion is based on type, not name) or Ctrl+Alt+Space for suggestion. 您可以使用Ctrl+Shift+Space进行自动完成(完成基于类型,而不是名称)或Ctrl+Alt+Space进行建议。 Or Ctrl+P to see what arguments are accepted. 或者Ctrl+P查看接受的参数。

Try 尝试

Ctrl + Space

for 对于

Basic Code Completion 基本代码完成

And like previously was written 和以前一样写的

Ctrl + Shift + Space

for 对于

Type Code Completion 输入代码完成

or try the second variant TWICE. 或尝试第二个变体TWICE。 More about Auto-Completing Code is in here 有关自动完成代码的更多信息,请访问此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM