From 33b74576c253d8d3f08292e439af15e6e6acfc40 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 29 May 2020 11:31:38 -0400 Subject: [PATCH] Fixed error range for SemicolonRequiredInReference The error range now goes from the start of the ampersand to the end of the entity name. Fixes #664 Signed-off-by: David Thompson --- .../participants/XMLSyntaxErrorCode.java | 7 +++- .../XMLSyntaxDiagnosticsTest.java | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSyntaxErrorCode.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSyntaxErrorCode.java index 03c3d65e0..49cde4521 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSyntaxErrorCode.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSyntaxErrorCode.java @@ -31,6 +31,7 @@ import org.eclipse.lemminx.services.extensions.ICodeActionParticipant; import org.eclipse.lemminx.services.extensions.diagnostics.IXMLErrorCode; import org.eclipse.lemminx.utils.XMLPositionUtility; +import org.eclipse.lemminx.utils.XMLPositionUtility.EntityReferenceRange; import org.eclipse.lsp4j.Range; /** @@ -55,7 +56,7 @@ public enum XMLSyntaxErrorCode implements IXMLErrorCode { the_element_type_lmsg("the-element-type-lmsg"), EqRequiredInXMLDecl, IllegalQName, InvalidCommentStart, LessthanInAttValue, MarkupEntityMismatch, MarkupNotRecognizedInContent, NameRequiredInReference, OpenQuoteExpected, PITargetRequired, PseudoAttrNameExpected, QuoteRequiredInXMLDecl, RootElementTypeMustMatchDoctypedecl, - SDDeclInvalid, SpaceRequiredBeforeEncodingInXMLDecl, SpaceRequiredBeforeStandalone, SpaceRequiredInPI, + SDDeclInvalid, SemicolonRequiredInReference, SpaceRequiredBeforeEncodingInXMLDecl, SpaceRequiredBeforeStandalone, SpaceRequiredInPI, VersionInfoRequired, VersionNotSupported, XMLDeclUnterminated, CustomETag, PrematureEOF, DoctypeNotAllowed, NoMorePseudoAttributes; private final String code; @@ -167,6 +168,10 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj String tag = getString(arguments[0]); return XMLPositionUtility.selectChildEndTag(tag, offset, document); } + case SemicolonRequiredInReference: { + EntityReferenceRange range = XMLPositionUtility.selectEntityReference(offset + 1, document, false); + return range != null ? range.getRange() : null; + } case ContentIllegalInProlog: { int startOffset = offset + 1; int endOffset = 0; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSyntaxDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSyntaxDiagnosticsTest.java index 7b2ea7d15..f2932f912 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSyntaxDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSyntaxDiagnosticsTest.java @@ -492,4 +492,39 @@ public void testVersionNotSupported() throws Exception { String xml = ""; testDiagnosticsFor(xml, d(0, 14, 0, 22, XMLSyntaxErrorCode.VersionNotSupported)); } + + @Test + public void testEntitySemicolonRequiredInReference() throws Exception { + String xml = "\n" + // + " \n" + // + "]>\n" + // + "\n" + // + " &mdash \n" + // + ""; + testDiagnosticsFor(xml, d(5, 4, 5, 10, XMLSyntaxErrorCode.SemicolonRequiredInReference)); + } + + @Test + public void testEntitySemicolonRequiredInReferenceOddSpacing() throws Exception { + String xml = "\n" + // + " \n" + // + "]>\n" + // + "\n" + // + " &mdash"; + testDiagnosticsFor(xml, d(5, 4, 5, 10, XMLSyntaxErrorCode.SemicolonRequiredInReference)); + } + + @Test + public void testEntitySemicolonRequiredInReferenceShortName() throws Exception { + String xml = "\n" + // + " \n" + // + "]>\n" + // + "\n" + // + " &m \n" + // + ""; + testDiagnosticsFor(xml, d(5, 4, 5, 6, XMLSyntaxErrorCode.SemicolonRequiredInReference)); + } }