forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synxtax error ranges, resources updated Signed-off-by: Nikolas Komonen <nikolaskomonen@gmail.com>
- Loading branch information
1 parent
efef96d
commit 0087fbe
Showing
26 changed files
with
300 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...in/java/org/eclipse/lsp4xml/contentmodel/participants/diagnostics/XMLSchemaErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.contentmodel.participants.diagnostics; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.xerces.xni.XMLLocator; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4xml.dom.XMLDocument; | ||
import org.eclipse.lsp4xml.utils.XMLPositionUtility; | ||
|
||
/** | ||
* XML Schema error code. | ||
* | ||
* @see https://wiki.xmldation.com/Support/Validator | ||
* | ||
*/ | ||
public enum XMLSchemaErrorCode implements IXMLErrorCode{ | ||
|
||
cvc_complex_type_2_4_a("cvc-complex-type.2.4.a"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-2-4-a | ||
cvc_complex_type_2_4_d("cvc-complex-type.2.4.d"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-2-4-d | ||
cvc_complex_type_3_2_2("cvc-complex-type.3.2.2"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-3-2-2 | ||
cvc_complex_type_4("cvc-complex-type.4"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-4 | ||
cvc_type_3_1_1("cvc-type.3.1.1"); // https://wiki.xmldation.com/Support/Validator/cvc-type-3-1-1 | ||
|
||
private final String code; | ||
|
||
private XMLSchemaErrorCode() { | ||
this(null); | ||
} | ||
|
||
private XMLSchemaErrorCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
if (code == null) { | ||
return name(); | ||
} | ||
return code; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getCode(); | ||
} | ||
|
||
private final static Map<String, XMLSchemaErrorCode> codes; | ||
|
||
static { | ||
codes = new HashMap<>(); | ||
for (XMLSchemaErrorCode errorCode : values()) { | ||
codes.put(errorCode.getCode(), errorCode); | ||
} | ||
} | ||
|
||
public static XMLSchemaErrorCode get(String name) { | ||
return codes.get(name); | ||
} | ||
|
||
/** | ||
* Create the LSP range from the SAX error. | ||
* | ||
* @param location | ||
* @param key | ||
* @param arguments | ||
* @param document.ge | ||
* @return the LSP range from the SAX error. | ||
*/ | ||
public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Object[] arguments, | ||
XMLDocument document) { | ||
int offset = location.getCharacterOffset() - 1; | ||
|
||
// adjust positions | ||
switch (code) { | ||
case cvc_complex_type_2_4_a: | ||
case cvc_complex_type_2_4_d: | ||
return XMLPositionUtility.selectStartTag(offset, document); | ||
case cvc_complex_type_3_2_2: { | ||
String attrName = (String) arguments[0]; | ||
return XMLPositionUtility.selectAttributeName(attrName, offset, document); | ||
} | ||
case cvc_complex_type_4: { | ||
// String tag = (String) arguments[0]; | ||
// String attrName = (String) arguments[1]; | ||
// startOffset = findOffsetOfStartTag(document.ge.getText(), offset, tag); | ||
// endOffset = startOffset + tag.length(); | ||
break; | ||
} | ||
case cvc_type_3_1_1: | ||
return XMLPositionUtility.selectAllAttributes(offset, document); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.