Skip to content

Commit

Permalink
Fixed error range for SemicolonRequiredInReference
Browse files Browse the repository at this point in the history
The error range now goes from the start of the ampersand to
the end of the entity name.

Fixes eclipse-lemminx#664

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed May 29, 2020
1 parent 291c6fa commit 6ceb9c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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;
Expand Down Expand Up @@ -167,6 +167,10 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj
String tag = getString(arguments[0]);
return XMLPositionUtility.selectChildEndTag(tag, offset, document);
}
case SemicolonRequiredInReference: {
int startOffset = XMLPositionUtility.getEntityReferenceStartOffset(document.getText(), offset);
return XMLPositionUtility.createRange(startOffset, offset + 1, document);
}
case ContentIllegalInProlog: {
int startOffset = offset + 1;
int endOffset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,39 @@ public void testVersionNotSupported() throws Exception {
String xml = "<?xml version=\"5000.0\"encoding=\"UTF-8\"?>";
testDiagnosticsFor(xml, d(0, 14, 0, 22, XMLSyntaxErrorCode.VersionNotSupported));
}

@Test
public void testEntitySemicolonRequiredInReference() throws Exception {
String xml = "<!DOCTYPE root [\n" + //
" <!ELEMENT root (#PCDATA)>\n" + //
" <!ENTITY mdash \"&#x2014;\">\n" + //
"]>\n" + //
"<root>\n" + //
" &mdash \n" + //
"</root>";
testDiagnosticsFor(xml, d(5, 4, 5, 10, XMLSyntaxErrorCode.SemicolonRequiredInReference));
}

@Test
public void testEntitySemicolonRequiredInReferenceOddSpacing() throws Exception {
String xml = "<!DOCTYPE root [\n" + //
" <!ELEMENT root (#PCDATA)>\n" + //
" <!ENTITY mdash \"&#x2014;\">\n" + //
"]>\n" + //
"<root>\n" + //
" &mdash</root>";
testDiagnosticsFor(xml, d(5, 4, 5, 10, XMLSyntaxErrorCode.SemicolonRequiredInReference));
}

@Test
public void testEntitySemicolonRequiredInReferenceShortName() throws Exception {
String xml = "<!DOCTYPE root [\n" + //
" <!ELEMENT root (#PCDATA)>\n" + //
" <!ENTITY m \"&#x2014;\">\n" + //
"]>\n" + //
"<root>\n" + //
" &m \n" + //
"</root>";
testDiagnosticsFor(xml, d(5, 4, 5, 6, XMLSyntaxErrorCode.SemicolonRequiredInReference));
}
}

0 comments on commit 6ceb9c6

Please sign in to comment.