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 Jun 1, 2020
1 parent 3a5fe37 commit 33b7457
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;
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 33b7457

Please sign in to comment.