com.intellij.lang.parameterInfo.ParameterInfoHandler Java Examples

The following examples show how to use com.intellij.lang.parameterInfo.ParameterInfoHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShowParameterInfoContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showParameterHint(final PsiElement element,
                                      final Editor editor,
                                      final Object[] descriptors,
                                      final Project project,
                                      @Nullable Object highlighted,
                                      final int elementStart,
                                      final ParameterInfoHandler handler,
                                      final boolean requestFocus,
                                      boolean singleParameterInfo) {
  if (editor.isDisposed() || !editor.getComponent().isVisible()) return;

  PsiDocumentManager.getInstance(project).performLaterWhenAllCommitted(() -> {
    if (editor.isDisposed() || DumbService.isDumb(project) || !element.isValid() || (!ApplicationManager.getApplication().isUnitTestMode() && !EditorActivityManager.getInstance().isVisible(editor)))
      return;

    final Document document = editor.getDocument();
    if (document.getTextLength() < elementStart) return;

    ParameterInfoController controller = ParameterInfoController.findControllerAtOffset(editor, elementStart);
    if (controller == null) {
      new ParameterInfoController(project, editor, elementStart, descriptors, highlighted, element, handler, true, requestFocus);
    }
    else {
      controller.setDescriptors(descriptors);
      controller.showHint(requestFocus, singleParameterInfo);
    }
  });
}
 
Example #2
Source File: ShowParameterInfoHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, ParameterInfoHandler handler, boolean requestFocus) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus, false);
  component.update(false);

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ParameterInfoController.chooseBestHintPosition(editor, null, hint, HintManager.DEFAULT, true);
  ApplicationManager.getApplication().invokeLater(() -> {
    if (!EditorActivityManager.getInstance().isVisible(editor)) return;
    hintManager.showEditorHint(hint, editor, pos.getFirst(), HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_LOOKUP_ITEM_CHANGE | HintManager.UPDATE_BY_SCROLLING, 0, false, pos.getSecond());
  });
}
 
Example #3
Source File: ShowParameterInfoHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ParameterInfoHandler[] getHandlers(Project project, final Language... languages) {
  Set<ParameterInfoHandler> handlers = new LinkedHashSet<>();
  DumbService dumbService = DumbService.getInstance(project);
  for (final Language language : languages) {
    handlers.addAll(dumbService.filterByDumbAwareness(LanguageParameterInfo.INSTANCE.allForLanguage(language)));
  }
  if (handlers.isEmpty()) return null;
  return handlers.toArray(new ParameterInfoHandler[0]);
}
 
Example #4
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull 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(false);
}
 
Example #5
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, boolean requestFocus, boolean allowSwitchLabel) {
  super(new BorderLayout());
  myRequestFocus = requestFocus;

  if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    myWidthLimit = layeredPane.getWidth();
  }

  NORMAL_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.PLAIN) : UIUtil.getLabelFont();
  BOLD_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.BOLD) : NORMAL_FONT.deriveFont(Font.BOLD);

  myObjects = objects;

  setBackground(BACKGROUND);

  myHandler = handler;
  myMainPanel = new JPanel(new GridBagLayout());
  setPanels();

  if (myRequestFocus) {
    AccessibleContextUtil.setName(this, "Parameter Info. Press TAB to navigate through each element. Press ESC to close.");
  }

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myMainPanel, true);
  add(pane, BorderLayout.CENTER);

  myAllowSwitchLabel = allowSwitchLabel && !(editor instanceof EditorWindow);
  setShortcutLabel();
  myCurrentParameterIndex = -1;
}
 
Example #6
Source File: FakeCreateParameterInfoContext.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {
}
 
Example #7
Source File: MockCreateParameterInfoContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {}
 
Example #8
Source File: ShowParameterInfoContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {
  final Object[] itemsToShow = getItemsToShow();
  if (itemsToShow == null || itemsToShow.length == 0) return;
  showParameterHint(element, getEditor(), itemsToShow, getProject(), itemsToShow.length > 1 ? getHighlightedElement() : null, offset, handler, myRequestFocus, mySingleParameterInfo);
}
 
Example #9
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
@TestOnly
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, int currentParameterIndex) {
  return createContext(objects, editor, handler, currentParameterIndex, null);
}
 
Example #10
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler) {
  this(objects, editor, handler, false, false);
}