void (final XmlTag tag, final List<? super LookupElement> elements) { final FileBasedIndex fbi = FileBasedIndex.getInstance(); Collection<String> result = new ArrayList<>(); Processor<String> processor = Processors.cancelableCollectProcessor(result); fbi.processAllKeys(XmlNamespaceIndex.NAME, processor, tag.getProject()); final GlobalSearchScope scope = GlobalSearchScope.everythingScope(tag.getProject()); for (final String ns : result) { if (ns.isEmpty()) continue; fbi.processValues(XmlNamespaceIndex.NAME, ns, null, new FileBasedIndex.ValueProcessor<>() { @Override public boolean process(final @NotNull VirtualFile file, XsdNamespaceBuilder value) { List<String> tags = value.getRootTags(); for (String s : tags) { elements.add(LookupElementBuilder.create(s) .withIcon(AllIcons.Nodes.Tag) .withTypeText(ns).withInsertHandler(new XmlTagInsertHandler() { @Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { final Editor editor = context.getEditor(); final Document document = context.getDocument(); final int caretOffset = editor.getCaretModel().getOffset(); final RangeMarker caretMarker = document.createRangeMarker(caretOffset, caretOffset); caretMarker.setGreedyToRight(true); XmlFile psiFile = (XmlFile)context.getFile(); boolean incomplete = XmlUtil.getTokenOfType(tag, XmlTokenType.XML_TAG_END) == null && XmlUtil.getTokenOfType(tag, XmlTokenType.XML_EMPTY_ELEMENT_END) == null; XmlNamespaceHelper.getHelper(psiFile).insertNamespaceDeclaration(psiFile, editor, Collections.singleton(ns), null, null); editor.getCaretModel().moveToOffset(caretMarker.getEndOffset()); XmlTag rootTag = psiFile.getRootTag(); if (incomplete) { XmlToken token = XmlUtil.getTokenOfType(rootTag, XmlTokenType.XML_EMPTY_ELEMENT_END); if (token != null) token.delete(); // remove tag end added by smart attribute adder :( PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(document); super.handleInsert(context, item); } } })); } return true; } }, scope); } }