Search in sources :

Example 1 with UpdateParameterInfoContext

use of com.intellij.lang.parameterInfo.UpdateParameterInfoContext in project intellij-community by JetBrains.

the class ParameterInfoController method updateComponent.

public void updateComponent() {
    if (myKeepOnHintHidden) {
        boolean removeHints = true;
        PsiElement owner = myComponent.getParameterOwner();
        if (owner != null && owner.isValid()) {
            int caretOffset = myEditor.getCaretModel().getOffset();
            TextRange ownerTextRange = owner.getTextRange();
            if (ownerTextRange != null) {
                if (caretOffset > ownerTextRange.getStartOffset() && caretOffset < ownerTextRange.getEndOffset()) {
                    removeHints = false;
                } else {
                    for (PsiElement element : owner.getChildren()) {
                        if (element instanceof PsiErrorElement) {
                            removeHints = false;
                            break;
                        }
                    }
                }
            }
        }
        if (removeHints) {
            Disposer.dispose(this);
            return;
        }
    }
    if (!myHint.isVisible() && !myKeepOnHintHidden && !ApplicationManager.getApplication().isUnitTestMode()) {
        Disposer.dispose(this);
        return;
    }
    final PsiFile file = PsiUtilBase.getPsiFileInEditor(myEditor, myProject);
    CharSequence chars = myEditor.getDocument().getCharsSequence();
    boolean noDelimiter = myHandler instanceof ParameterInfoHandlerWithTabActionSupport && ((ParameterInfoHandlerWithTabActionSupport) myHandler).getActualParameterDelimiterType() == TokenType.WHITE_SPACE;
    int caretOffset = myEditor.getCaretModel().getOffset();
    final int offset = noDelimiter ? caretOffset : CharArrayUtil.shiftBackward(chars, caretOffset - 1, " \t") + 1;
    final UpdateParameterInfoContext context = new MyUpdateParameterInfoContext(offset, file);
    final Object elementForUpdating = myHandler.findElementForUpdatingParameterInfo(context);
    if (elementForUpdating != null) {
        myHandler.updateParameterInfo(elementForUpdating, context);
        if (!myDisposed && myHint.isVisible() && !myEditor.isDisposed() && myEditor.getComponent().getRootPane() != null) {
            myComponent.update();
            IdeTooltip tooltip = myHint.getCurrentIdeTooltip();
            short position = tooltip != null ? toShort(tooltip.getPreferredPosition()) : HintManager.UNDER;
            Pair<Point, Short> pos = myProvider.getBestPointPosition(myHint, elementForUpdating instanceof PsiElement ? (PsiElement) elementForUpdating : null, caretOffset, true, position);
            HintManagerImpl.adjustEditorHintPosition(myHint, myEditor, pos.getFirst(), pos.getSecond());
        }
    } else {
        context.removeHint();
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) UpdateParameterInfoContext(com.intellij.lang.parameterInfo.UpdateParameterInfoContext) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) IdeTooltip(com.intellij.ide.IdeTooltip)

Aggregations

IdeTooltip (com.intellij.ide.IdeTooltip)1 ParameterInfoHandlerWithTabActionSupport (com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport)1 UpdateParameterInfoContext (com.intellij.lang.parameterInfo.UpdateParameterInfoContext)1 TextRange (com.intellij.openapi.util.TextRange)1 HintHint (com.intellij.ui.HintHint)1 LightweightHint (com.intellij.ui.LightweightHint)1