private static void showParameterHint( final PsiElement element, final Editor editor, final Object[] descriptors, final Project project, @Nullable PsiElement highlighted, final int elementStart, final ParameterInfoHandler handler, final boolean requestFocus) { if (ParameterInfoController.isAlreadyShown(editor, elementStart)) return; if (editor.isDisposed() || !editor.getComponent().isVisible()) return; final ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus); component.setParameterOwner(element); component.setRequestFocus(requestFocus); if (highlighted != null) { component.setHighlightedParameter(highlighted); } component.update(); // to have correct preferred size final LightweightHint hint = new LightweightHint(component); hint.setSelectingHint(true); final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); final ShowParameterInfoHandler.BestLocationPointProvider provider = new MyBestLocationPointProvider(editor); final Pair<Point, Short> pos = provider.getBestPointPosition(hint, element, elementStart, true, HintManager.UNDER); PsiDocumentManager.getInstance(project) .performLaterWhenAllCommitted( () -> { if (editor.isDisposed() || DumbService.isDumb(project)) return; final Document document = editor.getDocument(); if (document.getTextLength() < elementStart) return; HintHint hintHint = HintManagerImpl.createHintHint(editor, pos.getFirst(), hint, pos.getSecond()); hintHint.setExplicitClose(true); hintHint.setRequestFocus(requestFocus); Editor editorToShow = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor; // is case of injection we need to calculate position for EditorWindow // also we need to show the hint in the main editor because of intention bulb hintManager.showEditorHint( hint, editorToShow, pos.getFirst(), HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, hintHint); new ParameterInfoController(project, editor, elementStart, hint, handler, provider); }); }
@TestOnly public static ParameterInfoUIContextEx createContext( Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler, int currentParameterIndex, @Nullable PsiElement parameterOwner) { final ParameterInfoComponent infoComponent = new ParameterInfoComponent(objects, editor, handler); infoComponent.setCurrentParameterIndex(currentParameterIndex); infoComponent.setParameterOwner(parameterOwner); return infoComponent.new MyParameterContext(); }