public static void insertLookupString(final Project project,
                                        Editor editor, LookupElement item,
                                        PrefixMatcher matcher, String itemPattern, final int prefixLength) {
    final String lookupString = LookupUtil.getCaseCorrectedLookupString(item, matcher, itemPattern);

    final Editor hostEditor = editor;
    hostEditor.getCaretModel().runForEachCaret(__ -> {
      EditorModificationUtilEx.deleteSelectedText(hostEditor);
      final int caretOffset = hostEditor.getCaretModel().getOffset();

      int offset;
      try {
        offset = LookupUtil.insertLookupInDocumentWindowIfNeeded(project, editor, caretOffset, prefixLength, lookupString);
      }
      catch (AssertionError ae) {
        String classes = StreamEx.iterate(
            item, Objects::nonNull, i -> i instanceof LookupElementDecorator ? ((LookupElementDecorator<?>)i).getDelegate() : null)
          .map(le -> le.getClass().getName()).joining(" -> ");
        LOG.error("When completing " + item + " (" + classes + ")", ae);
        return;
      }
      hostEditor.getCaretModel().moveToOffset(offset);
      hostEditor.getSelectionModel().removeSelection();
    });

    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  }
public static void insertLookupString(final Project project,
                                        Editor editor, LookupElement item,
                                        PrefixMatcher matcher, String itemPattern, final int prefixLength)