Skip to content

Commit

Permalink
Fixed EOF Error
Browse files Browse the repository at this point in the history
Fixes #157

The most common ocurrences of this error are
when the document is empty or there is just the
xml prolog (<?xml ... ?>). Errors that give negative values
will be ignored for now.

Signed-off-by: Nikolas <[email protected]>
  • Loading branch information
NikolasKomonen committed Mar 18, 2019
1 parent 3988871 commit 143d2d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ EqRequiredInAttribute, the_element_type_lmsg("the-element-type-lmsg"), EqRequire
InvalidCommentStart, LessthanInAttValue, MarkupEntityMismatch, MarkupNotRecognizedInContent,
NameRequiredInReference, OpenQuoteExpected, PITargetRequired, PseudoAttrNameExpected, QuoteRequiredInXMLDecl,
SDDeclInvalid, SpaceRequiredBeforeEncodingInXMLDecl, SpaceRequiredBeforeStandalone, SpaceRequiredInPI,
VersionInfoRequired, VersionNotSupported, XMLDeclUnterminated, CustomETag; // https://wiki.xmldation.com/Support/Validator/EqRequiredInAttribute
VersionInfoRequired, VersionNotSupported, XMLDeclUnterminated, CustomETag, PrematureEOF; // https://wiki.xmldation.com/Support/Validator/EqRequiredInAttribute

private final String code;

Expand Down Expand Up @@ -173,6 +173,7 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj
int start = selectCurrentTagOffset(offset, document) + 1;
int end = offset + 1;
return XMLPositionUtility.createRange(start, end, document);
case PrematureEOF:
case XMLDeclUnterminated:
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ public String reportError(XMLLocator location, String domain, String key, Object
message = str.toString();
}

Range adjustedRange = internalToLSPRange(location, key, arguments, xmlDocument);

if(adjustedRange == null) {
return null;
}
// Fill diagnostic
diagnostics.add(new Diagnostic(internalToLSPRange(location, key, arguments, xmlDocument), message,
diagnostics.add(new Diagnostic(adjustedRange, message,
toLSPSeverity(severity), source, key));

if (severity == SEVERITY_FATAL_ERROR && !fContinueAfterFatalError) {
Expand Down Expand Up @@ -127,6 +132,10 @@ private Range internalToLSPRange(XMLLocator location, String key, Object[] argum
int startOffset = location.getCharacterOffset() - 1;
int endOffset = location.getCharacterOffset() - 1;

if(startOffset < 0 || endOffset < 0) {
return null;
}

// Create LSP range
Position start = toLSPPosition(startOffset, location, document.getTextDocument());
Position end = toLSPPosition(endOffset, location, document.getTextDocument());
Expand Down

0 comments on commit 143d2d8

Please sign in to comment.