From 1a5c7c5fc08327c37eb00a49ad8f84d67864dc7d Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Tue, 31 Oct 2023 11:39:44 +0100 Subject: [PATCH] WEB-63653 Angular 17: no completion for html tags inside block GitOrigin-RevId: bf68891c14e77332e9149a37fd0fbe2a2e25a88e --- .../psi/impl/source/html/HtmlDocumentImpl.java | 5 ++--- .../source/xml/TagNameVariantCollector.java | 11 +++++------ .../psi/impl/source/xml/XmlTagDelegate.java | 17 +++++++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java index 97fa57c009d4..c42270048f68 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/HtmlDocumentImpl.java @@ -17,10 +17,9 @@ package com.intellij.psi.impl.source.html; import com.intellij.psi.impl.source.xml.XmlDocumentImpl; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.xml.IXmlTagElementType; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlElementType; import com.intellij.psi.xml.XmlTag; -import com.intellij.xml.util.XmlPsiUtil; /** * @author Maxim.Mossienko @@ -36,6 +35,6 @@ public class HtmlDocumentImpl extends XmlDocumentImpl { @Override public XmlTag getRootTag() { - return (XmlTag)XmlPsiUtil.findElement(this, IXmlTagElementType.class::isInstance); + return PsiTreeUtil.findChildOfType(this, XmlTag.class); } } diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/TagNameVariantCollector.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/TagNameVariantCollector.java index 0dc9187cef3e..306762111b30 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/TagNameVariantCollector.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/TagNameVariantCollector.java @@ -3,7 +3,6 @@ package com.intellij.psi.impl.source.xml; import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiElement; import com.intellij.psi.html.HtmlTag; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlDocument; @@ -32,10 +31,10 @@ public final class TagNameVariantCollector { String elementNamespace = element.getNamespacePrefix().isEmpty() ? null : element.getNamespace(); final Map descriptorsMap = new HashMap<>(); - PsiElement context = element.getParent(); - PsiElement curElement = element.getParent(); + XmlTag context = element.getParentTag(); + XmlTag declarationTag = context; - while(curElement instanceof XmlTag declarationTag){ + while(declarationTag != null){ final String namespace = declarationTag.getNamespace(); if(!descriptorsMap.containsKey(namespace)) { @@ -51,7 +50,7 @@ public final class TagNameVariantCollector { } } } - curElement = curElement.getContext(); + declarationTag = declarationTag.getParentTag(); } final Set visited = new HashSet<>(); @@ -60,7 +59,7 @@ public final class TagNameVariantCollector { for (final String namespace: namespaces) { final int initialSize = variants.size(); processVariantsInNamespace(namespace, element, variants, elementDescriptor, elementNamespace, descriptorsMap, visited, - context instanceof XmlTag ? (XmlTag)context : element, extension); + context != null ? context : element, extension); if (nsInfo != null) { for (int i = initialSize; i < variants.size(); i++) { XmlElementDescriptor descriptor = variants.get(i); diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagDelegate.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagDelegate.java index 45581f7c22c5..93e098c4d446 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagDelegate.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagDelegate.java @@ -15,6 +15,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; +import com.intellij.psi.html.HtmlTag; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; import com.intellij.psi.impl.source.tree.Factory; import com.intellij.psi.impl.source.tree.*; @@ -417,7 +418,9 @@ public abstract class XmlTagDelegate { return XmlNamespaceIndex.guessSchema(namespace, nsDecl ? null : tag.getLocalName(), version, fileLocation, file); } - private static @Nullable PsiMetaOwner retrieveOwner(final @Nullable XmlTag tag, final @Nullable XmlFile file, final @Nullable String namespace) { + private static @Nullable PsiMetaOwner retrieveOwner(final @Nullable XmlTag tag, + final @Nullable XmlFile file, + final @Nullable String namespace) { if (file == null) { return namespace != null && namespace.equals(XmlUtil.getTargetSchemaNsFromTag(tag)) ? tag : null; } @@ -715,15 +718,15 @@ public abstract class XmlTagDelegate { } String @NotNull [] knownNamespaces() { - final PsiElement parentElement = myTag.getParent(); + final XmlTag parentTag = myTag.getParentTag(); BidirectionalMap map = getNamespaceMap(myTag); Set known = Collections.emptySet(); if (map != null) { known = new HashSet<>(map.values()); } - if (parentElement instanceof XmlTag) { - if (known.isEmpty()) return ((XmlTag)parentElement).knownNamespaces(); - ContainerUtil.addAll(known, ((XmlTag)parentElement).knownNamespaces()); + if (parentTag != null) { + if (known.isEmpty()) return parentTag.knownNamespaces(); + ContainerUtil.addAll(known, parentTag.knownNamespaces()); } else { XmlExtension xmlExtension = XmlExtension.getExtensionByElement(myTag); @@ -748,7 +751,6 @@ public abstract class XmlTagDelegate { private static @Nullable BidirectionalMap computeNamespaceMap(@NotNull XmlTag tag) { BidirectionalMap map = null; - PsiElement parent = tag.getParent(); boolean hasNamespaceDeclarations = tag.hasNamespaceDeclarations(); if (hasNamespaceDeclarations) { map = new BidirectionalMap<>(); @@ -772,6 +774,9 @@ public abstract class XmlTagDelegate { } } + PsiElement parent = (tag instanceof HtmlTag) + ? PsiTreeUtil.getParentOfType(tag, XmlTag.class, XmlDocument.class) + : tag.getParent(); if (parent instanceof XmlDocument) { final XmlExtension extension = XmlExtension.getExtensionByElement(parent); if (extension != null) {