void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { PsiElement position = parameters.getOriginalPosition(); PyClass containingClass = PsiTreeUtil.getParentOfType(position, PyClass.class); PsiElement nextElement = position != null ? position.getNextSibling() : null; if (containingClass == null && position instanceof PsiWhiteSpace) { position = PsiTreeUtil.prevLeaf(position); containingClass = PsiTreeUtil.getParentOfType(position, PyClass.class); } if (containingClass == null) { return; } Set<String> seenNames = new HashSet<>(); for (PyFunction function : containingClass.getMethods()) { seenNames.add(function.getName()); } LanguageLevel languageLevel = LanguageLevel.forElement(parameters.getOriginalFile()); seenNames.addAll(PyNames.getBuiltinMethods(languageLevel).keySet()); TypeEvalContext typeEvalContext = TypeEvalContext.codeCompletion(containingClass.getProject(), containingClass.getContainingFile()); for (PyFunction superMethod : PyPsiRefactoringUtil.getAllSuperMethods(containingClass, typeEvalContext)) { if (!seenNames.add(superMethod.getName())) { continue; } StringBuilder builder = new StringBuilder(); builder.append(superMethod.getName()); if (!(nextElement instanceof PyParameterList)) { PyParameterList parameterList; boolean copyAnnotations = PyPsiRefactoringUtil.shouldCopyAnnotations(superMethod, parameters.getOriginalFile()); if (copyAnnotations) { parameterList = superMethod.getParameterList(); } else { parameterList = stripAnnotations(superMethod.getParameterList()); } builder.append(parameterList.getText()); if (superMethod.getAnnotation() != null && copyAnnotations) { builder.append(" ") .append(superMethod.getAnnotation().getText()) .append(":"); } else if (superMethod.getTypeComment() != null) { builder.append(": ") .append(superMethod.getTypeComment().getText()); } else { builder.append(":"); } } LookupElementBuilder element = LookupElementBuilder.create(builder.toString()) .withInsertHandler((insertionContext, item) -> { PsiElement methodName = insertionContext.getFile().findElementAt(insertionContext.getStartOffset()); if (methodName == null || !(methodName.getParent() instanceof PyFunction insertedMethod)) return; WriteCommandAction.writeCommandAction(insertionContext.getFile()).run(() -> { PyClassRefactoringUtil.transplantImportsFromSignature(superMethod, insertedMethod); }); }); result.addElement(TailTypeDecorator.withTail(element, TailTypes.noneType())); } }