private static void doInsertItemForSingleCaret(LookupElement item,
                                                 char completionChar,
                                                 StatisticsUpdate update,
                                                 List<LookupElement> items,
                                                 int idEndOffsetDelta,
                                                 Ref<WatchingInsertionContext> lastContext,
                                                 Editor hostEditor,
                                                 OffsetsInFile targetOffsets) {
    PsiFile targetFile = targetOffsets.getFile();
    Editor targetEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, targetFile);
    int targetCaretOffset = targetEditor.getCaretModel().getOffset();
    int idEnd = targetCaretOffset + idEndOffsetDelta;
    if (idEnd > targetEditor.getDocument().getTextLength()) {
      idEnd = targetCaretOffset; // no replacement by Tab when offsets gone wrong for some reason
    }

    WatchingInsertionContext currentContext = insertItem(items, item, completionChar, update,
                                                         targetEditor, targetFile,
                                                         targetCaretOffset, idEnd,
                                                         targetOffsets.getOffsets());
    lastContext.set(currentContext);
  }
private static void doInsertItemForSingleCaret(LookupElement item,
                                                 char completionChar,
                                                 StatisticsUpdate update,
                                                 List<LookupElement> items,
                                                 int idEndOffsetDelta,
                                                 Ref<WatchingInsertionContext> lastContext,
                                                 Editor hostEditor,
                                                 OffsetsInFile targetOffsets)