WEB-15620 Custom html attributes and elements are added lowercase only

GitOrigin-RevId: 9051538795501005b181af53e9e5db4061544c92
This commit is contained in:
Piotr Tomiak
2023-07-05 12:29:06 +02:00
committed by intellij-monorepo-bot
parent b0e5d3bec8
commit c9ef2330da
10 changed files with 35 additions and 38 deletions

View File

@@ -1 +1 @@
<div zzz="<caret>"
<div zZz="<caret>"

View File

@@ -1 +1 @@
<aaa zzz="<caret>"
<aaa zZz="<caret>"

View File

@@ -1,3 +1,3 @@
<div>
<zzz><caret></zzz>
<zZz><caret></zZz>
</div>

View File

@@ -1,2 +1,3 @@
<<symbolName descr="Custom tag name">custom-tag</symbolName>>hello</<symbolName descr="Custom tag name">custom-tag</symbolName>>
<<symbolName descr="Custom tag name">custom2-tag</symbolName>>hello</<symbolName descr="Custom tag name">custom2-tag</symbolName>>
<custom-utag>hello</custom-utag>

View File

@@ -338,12 +338,8 @@ public class HtmlCompletionTest extends BasePlatformTestCase {
public void testAdditionalHtmlTagsInsertedByCompletion() throws Exception {
final HtmlUnknownTagInspection inspection = new HtmlUnknownTagInspection();
String additionalEntries = inspection.getAdditionalEntries();
if (additionalEntries.length() > 0) {
additionalEntries += ",";
}
inspection.updateAdditionalEntries(additionalEntries + "zzz");
inspection.updateAdditionalEntries("zZz", getTestRootDisposable());
doTestWithHtmlInspectionEnabled("", inspection);
doTestWithHtmlInspectionEnabled("2", inspection);
@@ -351,12 +347,8 @@ public class HtmlCompletionTest extends BasePlatformTestCase {
public void testAdditionalHtmlAttributesInsertedByCompletion() throws Exception {
final HtmlUnknownAttributeInspection inspection = new HtmlUnknownAttributeInspection();
String additionalEntries = inspection.getAdditionalEntries();
if (additionalEntries.length() > 0) {
additionalEntries += ",";
}
inspection.updateAdditionalEntries(additionalEntries + "zzz");
inspection.updateAdditionalEntries("zZz", getTestRootDisposable());
doTestWithHtmlInspectionEnabled("2", inspection);
doTestWithHtmlInspectionEnabled("", inspection);

View File

@@ -855,18 +855,12 @@ public class HtmlHighlightingTest extends BasePlatformTestCase {
public void testCustomTagHighlighting() {
HtmlUnknownTagInspection inspection = new HtmlUnknownTagInspection();
String before = inspection.getAdditionalEntries();
inspection.updateAdditionalEntries("custom-tag,custom2-tag");
try {
myFixture.enableInspections(inspection);
inspection.updateAdditionalEntries("custom-tag,custom2-TAG", getTestRootDisposable());
myFixture.enableInspections(inspection);
HighlightTestInfo info = myFixture.testFile(getTestName(false) + ".html");
info.checkSymbolNames();
info.test();
}
finally {
inspection.updateAdditionalEntries(before);
}
HighlightTestInfo info = myFixture.testFile(getTestName(false) + ".html");
info.checkSymbolNames();
info.test();
}
private void doTestWebLinks(boolean startTestingLocalServer) throws Exception {

View File

@@ -55,7 +55,7 @@ public class HtmlEmmetAbbreviationTest extends EmmetAbbreviationTestSuite {
@Override
protected void setUp(@NotNull Project project) throws Exception {
super.setUp(project);
super.setUp(project);
final TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project);
TemplateContextType contextType = TemplateContextTypes.getByClass(HtmlTextContextType.class);
@@ -222,10 +222,8 @@ public class HtmlEmmetAbbreviationTest extends EmmetAbbreviationTestSuite {
addTestWithInit("input[title]", "<input type=\"text\" title=\"\">", null);
addTestWithInit("input[title]", "<input type=\"text\" title>", (fixture, testRootDisposable) -> {
final HtmlUnknownBooleanAttributeInspection inspection = new HtmlUnknownBooleanAttributeInspection();
final String oldValue = inspection.getAdditionalEntries();
inspection.updateAdditionalEntries("title");
inspection.updateAdditionalEntries("title", testRootDisposable);
fixture.enableInspections(inspection);
Disposer.register(testRootDisposable, () -> inspection.updateAdditionalEntries(oldValue));
});
}

View File

@@ -20,12 +20,15 @@ import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.util.InspectionMessage;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.JDOMExternalizableStringList;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlChildRole;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.StringTokenizer;
@@ -43,7 +46,7 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
final StringTokenizer tokenizer = new StringTokenizer(properties, ",");
while (tokenizer.hasMoreTokens()) {
result.add(StringUtil.toLowerCase(tokenizer.nextToken()).trim());
result.add(tokenizer.nextToken());
}
return result;
@@ -64,13 +67,13 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
}
}
protected boolean isCustomValue(@NotNull final String value) {
return myValues.contains(StringUtil.toLowerCase(value));
protected boolean isCustomValue(@NotNull String value) {
return ContainerUtil.exists(myValues, val -> StringUtil.equalsIgnoreCase(val, value));
}
@Override
public void addEntry(@NotNull final String text) {
final String s = StringUtil.toLowerCase(text.trim());
final String s = text.trim();
if (!isCustomValue(s)) {
myValues.add(s);
}
@@ -89,8 +92,14 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
return StringUtil.join(myValues, ",");
}
public void updateAdditionalEntries(@NotNull final String values) {
public void updateAdditionalEntries(@NotNull final String values, Disposable disposable) {
JDOMExternalizableStringList oldValue = myValues;
myValues = reparseProperties(values);
if (disposable != null) {
Disposer.register(disposable, () -> {
myValues = oldValue;
});
}
}
@NotNull

View File

@@ -63,9 +63,11 @@ class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : TextEdit
})
}
private fun getCustomNames() = (HtmlUtil.getEntitiesString(file, XmlEntitiesInspection.TAG_SHORT_NAME)
?.let { StringUtil.split(it, ",").toSet() }
?: emptySet())
private fun getCustomNames() =
HtmlUtil.getEntitiesString(file, XmlEntitiesInspection.TAG_SHORT_NAME)
?.splitToSequence(',')
?.mapTo(HashSet()) { StringUtil.toLowerCase(it) }
?: emptySet()
private fun applyHighlighting(node: ASTNode, elementType: IElementType) {
if (node !is LeafElement) return
@@ -119,7 +121,8 @@ fun isCustomTag(file: PsiFile, tag: XmlTag): Boolean {
return isHtmlLikeFile(file) && !isHtmlTagName(descriptor, tag)
}
private fun isHtmlLikeFile(file: PsiFile) = file.viewProvider.allFiles.any { it is HtmlCompatibleFile } || HtmlUtil.supportsXmlTypedHandlers(file)
private fun isHtmlLikeFile(file: PsiFile) = file.viewProvider.allFiles.any { it is HtmlCompatibleFile } || HtmlUtil.supportsXmlTypedHandlers(
file)
private fun isHtmlTagName(descriptor: XmlElementDescriptor, tag: XmlTag): Boolean {
if (descriptor is HtmlElementDescriptorImpl) return true