Search in sources :

Example 1 with ParameterInfoHandlerWithTabActionSupport

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

the class ParameterInfoController method findArgumentList.

@Nullable
public static <E extends PsiElement> E findArgumentList(PsiFile file, int offset, int lbraceOffset) {
    if (file == null)
        return null;
    ParameterInfoHandler[] handlers = ShowParameterInfoHandler.getHandlers(file.getProject(), PsiUtilCore.getLanguageAtOffset(file, offset), file.getViewProvider().getBaseLanguage());
    if (handlers != null) {
        for (ParameterInfoHandler handler : handlers) {
            if (handler instanceof ParameterInfoHandlerWithTabActionSupport) {
                final ParameterInfoHandlerWithTabActionSupport parameterInfoHandler2 = (ParameterInfoHandlerWithTabActionSupport) handler;
                // please don't remove typecast in the following line; it's required to compile the code under old JDK 6 versions
                final E e = (E) ParameterInfoUtils.findArgumentList(file, offset, lbraceOffset, parameterInfoHandler2);
                if (e != null)
                    return e;
            }
        }
    }
    return null;
}
Also used : ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) ParameterInfoHandler(com.intellij.lang.parameterInfo.ParameterInfoHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ParameterInfoHandlerWithTabActionSupport

use of com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport 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)

Example 3 with ParameterInfoHandlerWithTabActionSupport

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

the class ParameterInfoController method getPrevOrNextParameterOffset.

private int getPrevOrNextParameterOffset(boolean isNext) {
    if (!(myHandler instanceof ParameterInfoHandlerWithTabActionSupport))
        return -1;
    ParameterInfoHandlerWithTabActionSupport handler = (ParameterInfoHandlerWithTabActionSupport) myHandler;
    boolean noDelimiter = handler.getActualParameterDelimiterType() == TokenType.WHITE_SPACE;
    int caretOffset = myEditor.getCaretModel().getOffset();
    int offset = noDelimiter ? caretOffset : CharArrayUtil.shiftBackward(myEditor.getDocument().getCharsSequence(), caretOffset - 1, " \t") + 1;
    int lbraceOffset = myLbraceMarker.getStartOffset();
    PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
    PsiElement argList = lbraceOffset < offset ? findArgumentList(file, offset, lbraceOffset) : null;
    if (argList == null)
        return -1;
    @SuppressWarnings("unchecked") PsiElement[] parameters = handler.getActualParameters(argList);
    int currentParameterIndex = noDelimiter ? JBIterable.of(parameters).indexOf((o) -> o.getTextRange().containsOffset(offset)) : ParameterInfoUtils.getCurrentParameterIndex(argList.getNode(), offset, handler.getActualParameterDelimiterType());
    int prevOrNextParameterIndex = isNext && currentParameterIndex < parameters.length - 1 ? currentParameterIndex + 1 : !isNext && currentParameterIndex > 0 ? currentParameterIndex - 1 : -1;
    return prevOrNextParameterIndex != -1 ? parameters[prevOrNextParameterIndex].getTextRange().getStartOffset() : -1;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) ParameterInfoHandler(com.intellij.lang.parameterInfo.ParameterInfoHandler) Lookup(com.intellij.codeInsight.lookup.Lookup) JBIterable(com.intellij.util.containers.JBIterable) PsiUtilBase(com.intellij.psi.util.PsiUtilBase) ModalityState(com.intellij.openapi.application.ModalityState) com.intellij.openapi.editor(com.intellij.openapi.editor) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) HintHint(com.intellij.ui.HintHint) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) PropertyChangeEvent(java.beans.PropertyChangeEvent) UpdateParameterInfoContext(com.intellij.lang.parameterInfo.UpdateParameterInfoContext) DumbService(com.intellij.openapi.project.DumbService) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) StringUtil(com.intellij.openapi.util.text.StringUtil) ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) LookupManager(com.intellij.codeInsight.lookup.LookupManager) Key(com.intellij.openapi.util.Key) TextRange(com.intellij.openapi.util.TextRange) IdeTooltip(com.intellij.ide.IdeTooltip) com.intellij.openapi.editor.event(com.intellij.openapi.editor.event) EditorWindow(com.intellij.injected.editor.EditorWindow) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) LockSupport(java.util.concurrent.locks.LockSupport) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ParameterInfoUtils(com.intellij.lang.parameterInfo.ParameterInfoUtils) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) PropertyChangeListener(java.beans.PropertyChangeListener) Position(com.intellij.openapi.ui.popup.Balloon.Position) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint) ParameterHintsPresentationManager(com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager) CharArrayUtil(com.intellij.util.text.CharArrayUtil) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint)

Aggregations

ParameterInfoHandlerWithTabActionSupport (com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport)3 IdeTooltip (com.intellij.ide.IdeTooltip)2 ParameterInfoHandler (com.intellij.lang.parameterInfo.ParameterInfoHandler)2 UpdateParameterInfoContext (com.intellij.lang.parameterInfo.UpdateParameterInfoContext)2 TextRange (com.intellij.openapi.util.TextRange)2 HintHint (com.intellij.ui.HintHint)2 LightweightHint (com.intellij.ui.LightweightHint)2 ParameterHintsPresentationManager (com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 ParameterInfoUtils (com.intellij.lang.parameterInfo.ParameterInfoUtils)1 Disposable (com.intellij.openapi.Disposable)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Logger (com.intellij.openapi.diagnostic.Logger)1 com.intellij.openapi.editor (com.intellij.openapi.editor)1 com.intellij.openapi.editor.event (com.intellij.openapi.editor.event)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 DumbService (com.intellij.openapi.project.DumbService)1