WatchingInsertionContext (CompletionProgressIndicator indicator, LookupElement item, char completionChar) { final Editor editor = indicator.getEditor(); final int caretOffset = indicator.getCaret().getOffset(); final int idEndOffset = CompletionUtil.calcIdEndOffset(indicator.getOffsetMap(), editor, indicator.getCaret().getOffset()); PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, indicator.getProject()); WatchingInsertionContext context = CompletionUtil.createInsertionContext(indicator.getLookup().getItems(), item, completionChar, editor, psiFile, caretOffset, idEndOffset, indicator.getOffsetMap()); try { item.handleInsert(context); } finally { context.stopWatching(); } return context; }