Skip to content

Commit

Permalink
cvc pattern error range fix
Browse files Browse the repository at this point in the history
Fixes #554

This PR falls back to the range of the text content if it matches

Signed-off-by: Nikolas Komonen <[email protected]>
  • Loading branch information
NikolasKomonen authored and angelozerr committed Oct 23, 2019
1 parent 0e09b21 commit 68d9292
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj
return XMLPositionUtility.selectAttributeFromGivenNameAt(attrName, offset, document);
}
case cvc_pattern_valid: {
String attrValue = getString(arguments[0]);
return XMLPositionUtility.selectAttributeValueByGivenValueAt(attrValue, offset, document);
String value = getString(arguments[0]);
Range result = XMLPositionUtility.selectAttributeValueByGivenValueAt(value, offset, document);
if(result != null) {
return result;
}
return XMLPositionUtility.selectTrimmedText(offset, document);
}
case SchemaLocation:
case schema_reference_4: {
Expand Down Expand Up @@ -209,7 +213,7 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj
DOMElement element = (DOMElement) document.findNodeAt(offset);

if (DOMUtils.containsTextOnly(element)) {
return XMLPositionUtility.selectTextTrimmed(offset, document);
return XMLPositionUtility.selectTrimmedText(offset, document);
} else {
return XMLPositionUtility.selectFirstChild(offset, document);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public static Range selectContent(int offset, DOMDocument document) {
* @return range covering the trimmed text belonging to the node
* located at offset
*/
public static Range selectTextTrimmed(int offset, DOMDocument document) {
public static Range selectTrimmedText(int offset, DOMDocument document) {
DOMNode node = document.findNodeAt(offset);
if (node == null || !node.isElement()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void cvc_pattern_valid_With_Buffer() throws Exception {
" <STOKENN>FIX_ERROR_RANGE_HERE</STOKENN>\r\n" + // <-- Error should follow pattern [0-9]{8}
" </cprev>\r\n" +
"</cpr>";
Diagnostic patternValid = d(6, 47, 6, 47, XMLSchemaErrorCode.cvc_pattern_valid);
Diagnostic patternValid = d(6, 17, 6, 37, XMLSchemaErrorCode.cvc_pattern_valid);
Diagnostic cvcType313 = d(6, 17, 6, 37, XMLSchemaErrorCode.cvc_type_3_1_3);
Diagnostic cvcType24b = d(3, 5, 3, 10, XMLSchemaErrorCode.cvc_complex_type_2_4_b);
testDiagnosticsFor(xml, patternValid, cvcType313, cvcType24b);
Expand Down

0 comments on commit 68d9292

Please sign in to comment.