use of com.intellij.codeInsight.hint.ShowParameterInfoContext in project intellij-community by JetBrains.
the class JavaMethodCallElement method showParameterHints.
public static void showParameterHints(InsertionContext context, PsiMethod method, PsiCallExpression methodCall) {
PsiParameterList parameterList = method.getParameterList();
int parametersCount = parameterList.getParametersCount();
if (methodCall == null || parametersCount == 0 || context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR || Registry.is("java.completion.argument.live.template") || !Registry.is("java.completion.argument.hints")) {
return;
}
Editor editor = context.getEditor();
CaretModel caretModel = editor.getCaretModel();
int offset = caretModel.getOffset();
// avoid caret impact on hints location
caretModel.moveToOffset(offset - 1);
editor.getDocument().insertString(offset, StringUtil.repeat(", ", parametersCount - 1));
List<Inlay> addedHints = new ArrayList<>(parametersCount);
for (PsiParameter parameter : parameterList.getParameters()) {
String name = parameter.getName();
if (name != null) {
addedHints.add(ParameterHintsPresentationManager.getInstance().addHint(editor, offset, name + ":", false, true));
}
offset += 2;
}
int braceOffset = caretModel.getOffset();
caretModel.moveToLogicalPosition(editor.offsetToLogicalPosition(braceOffset + 1).leanForward(true));
Project project = context.getProject();
MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
ShowParameterInfoContext infoContext = new ShowParameterInfoContext(editor, project, context.getFile(), braceOffset, braceOffset);
handler.findElementForParameterInfo(infoContext);
Disposer.register(new ParameterInfoController(project, editor, braceOffset, infoContext.getItemsToShow(), null, methodCall.getArgumentList(), handler, false, false), () -> {
for (Inlay inlay : addedHints) {
if (inlay != null)
ParameterHintsPresentationManager.getInstance().unpin(inlay);
}
});
}
Aggregations